]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Library/AuthVariableLib/AuthServiceInternal.h
OvmfPkg: introduce gRootBridgesConnectedEventGroupGuid
[mirror_edk2.git] / SecurityPkg / Library / AuthVariableLib / AuthServiceInternal.h
CommitLineData
a6811666
SZ
1/** @file\r
2 The internal header file includes the common header files, defines\r
3 internal structure and functions used by AuthService module.\r
4\r
5 Caution: This module requires additional review when modified.\r
6 This driver will have external input - variable data. It may be input in SMM mode.\r
7 This external input must be validated carefully to avoid security issue like\r
8 buffer overflow, integer overflow.\r
9 Variable attribute should also be checked to avoid authentication bypass.\r
10 The whole SMM authentication variable design relies on the integrity of flash part and SMM.\r
11 which is assumed to be protected by platform. All variable code and metadata in flash/SMM Memory\r
12 may not be modified without authorization. If platform fails to protect these resources,\r
13 the authentication service provided in this driver will be broken, and the behavior is undefined.\r
14\r
98c2d961 15Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
a6811666
SZ
16This program and the accompanying materials\r
17are licensed and made available under the terms and conditions of the BSD License\r
18which accompanies this distribution. The full text of the license may be found at\r
19http://opensource.org/licenses/bsd-license.php\r
20\r
21THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
22WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
23\r
24**/\r
25\r
26#ifndef _AUTHSERVICE_INTERNAL_H_\r
27#define _AUTHSERVICE_INTERNAL_H_\r
28\r
29#include <Library/AuthVariableLib.h>\r
30#include <Library/BaseLib.h>\r
31#include <Library/BaseMemoryLib.h>\r
32#include <Library/DebugLib.h>\r
33#include <Library/MemoryAllocationLib.h>\r
34#include <Library/BaseCryptLib.h>\r
35#include <Library/PlatformSecureLib.h>\r
36\r
37#include <Guid/AuthenticatedVariableFormat.h>\r
38#include <Guid/ImageAuthentication.h>\r
39\r
40///\r
41/// Struct to record signature requirement defined by UEFI spec.\r
42/// For SigHeaderSize and SigDataSize, ((UINT32) ~0) means NO exact length requirement for this field.\r
43///\r
44typedef struct {\r
45 EFI_GUID SigType;\r
46 // Expected SignatureHeader size in Bytes.\r
47 UINT32 SigHeaderSize;\r
48 // Expected SignatureData size in Bytes.\r
49 UINT32 SigDataSize;\r
50} EFI_SIGNATURE_ITEM;\r
51\r
52typedef enum {\r
53 AuthVarTypePk,\r
54 AuthVarTypeKek,\r
55 AuthVarTypePriv,\r
56 AuthVarTypePayload\r
57} AUTHVAR_TYPE;\r
58\r
59///\r
60/// "AuthVarKeyDatabase" variable for the Public Key store\r
61/// of variables with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS set.\r
62///\r
63/// GUID: gEfiAuthenticatedVariableGuid\r
64///\r
65/// We need maintain atomicity.\r
66///\r
67/// Format:\r
68/// +----------------------------+\r
69/// | AUTHVAR_KEY_DB_DATA | <-- First AuthVarKey\r
70/// +----------------------------+\r
71/// | ...... |\r
72/// +----------------------------+\r
73/// | AUTHVAR_KEY_DB_DATA | <-- Last AuthKey\r
74/// +----------------------------+\r
75///\r
76#define AUTHVAR_KEYDB_NAME L"AuthVarKeyDatabase"\r
77\r
78#define EFI_CERT_TYPE_RSA2048_SHA256_SIZE 256\r
79#define EFI_CERT_TYPE_RSA2048_SIZE 256\r
80\r
81#pragma pack(1)\r
82typedef struct {\r
83 UINT32 KeyIndex;\r
84 UINT8 KeyData[EFI_CERT_TYPE_RSA2048_SIZE];\r
85} AUTHVAR_KEY_DB_DATA;\r
86#pragma pack()\r
87\r
88///\r
98c2d961
CZ
89/// "certdb" variable stores the signer's certificates for non PK/KEK/DB/DBX\r
90/// variables with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS|EFI_VARIABLE_NON_VOLATILE set.\r
91/// "certdbv" variable stores the signer's certificates for non PK/KEK/DB/DBX\r
92/// variables with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set\r
a6811666
SZ
93///\r
94/// GUID: gEfiCertDbGuid\r
95///\r
96/// We need maintain atomicity.\r
97///\r
98/// Format:\r
99/// +----------------------------+\r
100/// | UINT32 | <-- CertDbListSize, including this UINT32\r
101/// +----------------------------+\r
102/// | AUTH_CERT_DB_DATA | <-- First CERT\r
103/// +----------------------------+\r
104/// | ........ |\r
105/// +----------------------------+\r
106/// | AUTH_CERT_DB_DATA | <-- Last CERT\r
107/// +----------------------------+\r
108///\r
98c2d961
CZ
109#define EFI_CERT_DB_NAME L"certdb"\r
110#define EFI_CERT_DB_VOLATILE_NAME L"certdbv"\r
a6811666
SZ
111\r
112#pragma pack(1)\r
113typedef struct {\r
114 EFI_GUID VendorGuid;\r
115 UINT32 CertNodeSize;\r
116 UINT32 NameSize;\r
117 UINT32 CertDataSize;\r
118 /// CHAR16 VariableName[NameSize];\r
119 /// UINT8 CertData[CertDataSize];\r
120} AUTH_CERT_DB_DATA;\r
121#pragma pack()\r
122\r
4fc08e8d
CZ
123///\r
124/// "SecureBootMode" variable stores current secure boot mode.\r
125/// The value type is SECURE_BOOT_MODE_TYPE.\r
126///\r
127#define EDKII_SECURE_BOOT_MODE_NAME L"SecureBootMode"\r
128\r
129typedef enum { \r
130 SecureBootModeTypeUserMode,\r
131 SecureBootModeTypeSetupMode,\r
132 SecureBootModeTypeAuditMode,\r
133 SecureBootModeTypeDeployedMode,\r
134 SecureBootModeTypeMax\r
135} SECURE_BOOT_MODE_TYPE;\r
136\r
137//\r
138// Record status info of Customized Secure Boot Mode.\r
139//\r
140typedef struct {\r
141 ///\r
142 /// AuditMode variable value\r
143 ///\r
144 UINT8 AuditMode;\r
145 ///\r
146 /// AuditMode variable RW\r
147 ///\r
148 BOOLEAN IsAuditModeRO;\r
149 ///\r
150 /// DeployedMode variable value\r
151 ///\r
152 UINT8 DeployedMode;\r
153 ///\r
154 /// AuditMode variable RW\r
155 ///\r
156 BOOLEAN IsDeployedModeRO;\r
157 ///\r
158 /// SetupMode variable value\r
159 ///\r
160 UINT8 SetupMode;\r
161 /// \r
162 /// SetupMode is always RO. Skip IsSetupModeRO; \r
163 ///\r
164\r
165 ///\r
166 /// SecureBoot variable value\r
167 ///\r
168 UINT8 SecureBoot;\r
169} SECURE_BOOT_MODE;\r
170\r
a6811666
SZ
171extern UINT8 *mPubKeyStore;\r
172extern UINT32 mPubKeyNumber;\r
173extern UINT32 mMaxKeyNumber;\r
174extern UINT32 mMaxKeyDbSize;\r
175extern UINT8 *mCertDbStore;\r
176extern UINT32 mMaxCertDbSize;\r
177extern UINT32 mPlatformMode;\r
178extern UINT8 mVendorKeyState;\r
179\r
180extern VOID *mHashCtx;\r
181\r
182extern AUTH_VAR_LIB_CONTEXT_IN *mAuthVarLibContextIn;\r
183\r
4fc08e8d
CZ
184/**\r
185 Initialize Secure Boot variables.\r
186\r
187 @retval EFI_SUCCESS The initialization operation is successful.\r
188 @retval EFI_OUT_OF_RESOURCES There is not enough resource.\r
189\r
190**/\r
191EFI_STATUS \r
192InitSecureBootVariables (\r
193 VOID\r
194 );\r
195\r
a6811666
SZ
196/**\r
197 Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set\r
198\r
199 Caution: This function may receive untrusted input.\r
200 This function may be invoked in SMM mode, and datasize and data are external input.\r
201 This function will do basic validation, before parse the data.\r
202 This function will parse the authentication carefully to avoid security issues, like\r
203 buffer overflow, integer overflow.\r
204\r
205 @param[in] VariableName Name of Variable to be found.\r
206 @param[in] VendorGuid Variable vendor GUID.\r
207 @param[in] Data Data pointer.\r
208 @param[in] DataSize Size of Data found. If size is less than the\r
209 data, this value contains the required size.\r
210 @param[in] Attributes Attribute value of the variable.\r
211 @param[in] AuthVarType Verify against PK, KEK database, private database or certificate in data payload.\r
212 @param[out] VarDel Delete the variable or not.\r
213\r
214 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
215 @retval EFI_SECURITY_VIOLATION The variable does NOT pass the validation\r
216 check carried out by the firmware.\r
217 @retval EFI_OUT_OF_RESOURCES Failed to process variable due to lack\r
218 of resources.\r
219 @retval EFI_SUCCESS Variable pass validation successfully.\r
220\r
221**/\r
222EFI_STATUS\r
223VerifyTimeBasedPayloadAndUpdate (\r
224 IN CHAR16 *VariableName,\r
225 IN EFI_GUID *VendorGuid,\r
226 IN VOID *Data,\r
227 IN UINTN DataSize,\r
228 IN UINT32 Attributes,\r
229 IN AUTHVAR_TYPE AuthVarType,\r
230 OUT BOOLEAN *VarDel\r
231 );\r
232\r
233/**\r
234 Delete matching signer's certificates when deleting common authenticated\r
98c2d961
CZ
235 variable by corresponding VariableName and VendorGuid from "certdb" or \r
236 "certdbv" according to authenticated variable attributes.\r
a6811666
SZ
237\r
238 @param[in] VariableName Name of authenticated Variable.\r
239 @param[in] VendorGuid Vendor GUID of authenticated Variable.\r
98c2d961 240 @param[in] Attributes Attributes of authenticated variable.\r
a6811666
SZ
241\r
242 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.\r
98c2d961 243 @retval EFI_NOT_FOUND Fail to find "certdb"/"certdbv" or matching certs.\r
a6811666
SZ
244 @retval EFI_OUT_OF_RESOURCES The operation is failed due to lack of resources.\r
245 @retval EFI_SUCCESS The operation is completed successfully.\r
246\r
247**/\r
248EFI_STATUS\r
249DeleteCertsFromDb (\r
250 IN CHAR16 *VariableName,\r
98c2d961
CZ
251 IN EFI_GUID *VendorGuid,\r
252 IN UINT32 Attributes\r
a6811666
SZ
253 );\r
254\r
64b6a3ff
CZ
255/**\r
256 Clean up signer's certificates for common authenticated variable\r
257 by corresponding VariableName and VendorGuid from "certdb".\r
258 Sytem may break down during Timebased Variable update & certdb update,\r
259 make them inconsistent, this function is called in AuthVariable Init to ensure \r
260 consistency\r
261 \r
262 @retval EFI_NOT_FOUND Fail to find matching certs.\r
263 @retval EFI_SUCCESS Find matching certs and output parameters.\r
264\r
265**/\r
266EFI_STATUS\r
267CleanCertsFromDb (\r
268 VOID\r
269 );\r
270\r
a6811666
SZ
271/**\r
272 Filter out the duplicated EFI_SIGNATURE_DATA from the new data by comparing to the original data.\r
273\r
274 @param[in] Data Pointer to original EFI_SIGNATURE_LIST.\r
275 @param[in] DataSize Size of Data buffer.\r
276 @param[in, out] NewData Pointer to new EFI_SIGNATURE_LIST.\r
277 @param[in, out] NewDataSize Size of NewData buffer.\r
278\r
279**/\r
280EFI_STATUS\r
281FilterSignatureList (\r
282 IN VOID *Data,\r
283 IN UINTN DataSize,\r
284 IN OUT VOID *NewData,\r
285 IN OUT UINTN *NewDataSize\r
286 );\r
287\r
4fc08e8d
CZ
288/**\r
289 Process Secure Boot Mode variable.\r
290\r
291 Caution: This function may receive untrusted input.\r
292 This function may be invoked in SMM mode, and datasize and data are external input.\r
293 This function will do basic validation, before parse the data.\r
294 This function will parse the authentication carefully to avoid security issues, like\r
295 buffer overflow, integer overflow.\r
296 This function will check attribute carefully to avoid authentication bypass.\r
297\r
298 @param[in] VariableName Name of Variable to be found.\r
299 @param[in] VendorGuid Variable vendor GUID.\r
300 @param[in] Data Data pointer.\r
301 @param[in] DataSize Size of Data found. If size is less than the\r
302 data, this value contains the required size.\r
303 @param[in] Attributes Attribute value of the variable\r
304\r
305 @return EFI_INVALID_PARAMETER Invalid parameter\r
306 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation\r
307 check carried out by the firmware.\r
308 @return EFI_WRITE_PROTECTED Variable is Read-Only.\r
309 @return EFI_SUCCESS Variable passed validation successfully.\r
310\r
311**/\r
312EFI_STATUS\r
313ProcessSecureBootModeVar (\r
314 IN CHAR16 *VariableName,\r
315 IN EFI_GUID *VendorGuid,\r
316 IN VOID *Data,\r
317 IN UINTN DataSize,\r
318 IN UINT32 Attributes OPTIONAL\r
319 );\r
320\r
a6811666
SZ
321/**\r
322 Process variable with platform key for verification.\r
323\r
324 Caution: This function may receive untrusted input.\r
325 This function may be invoked in SMM mode, and datasize and data are external input.\r
326 This function will do basic validation, before parse the data.\r
327 This function will parse the authentication carefully to avoid security issues, like\r
328 buffer overflow, integer overflow.\r
329 This function will check attribute carefully to avoid authentication bypass.\r
330\r
331 @param[in] VariableName Name of Variable to be found.\r
332 @param[in] VendorGuid Variable vendor GUID.\r
333 @param[in] Data Data pointer.\r
334 @param[in] DataSize Size of Data found. If size is less than the\r
335 data, this value contains the required size.\r
336 @param[in] Attributes Attribute value of the variable\r
337 @param[in] IsPk Indicate whether it is to process pk.\r
338\r
339 @return EFI_INVALID_PARAMETER Invalid parameter.\r
340 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation.\r
341 check carried out by the firmware.\r
342 @return EFI_SUCCESS Variable passed validation successfully.\r
343\r
344**/\r
345EFI_STATUS\r
346ProcessVarWithPk (\r
347 IN CHAR16 *VariableName,\r
348 IN EFI_GUID *VendorGuid,\r
349 IN VOID *Data,\r
350 IN UINTN DataSize,\r
351 IN UINT32 Attributes OPTIONAL,\r
352 IN BOOLEAN IsPk\r
353 );\r
354\r
355/**\r
356 Process variable with key exchange key for verification.\r
357\r
358 Caution: This function may receive untrusted input.\r
359 This function may be invoked in SMM mode, and datasize and data are external input.\r
360 This function will do basic validation, before parse the data.\r
361 This function will parse the authentication carefully to avoid security issues, like\r
362 buffer overflow, integer overflow.\r
363 This function will check attribute carefully to avoid authentication bypass.\r
364\r
365 @param[in] VariableName Name of Variable to be found.\r
366 @param[in] VendorGuid Variable vendor GUID.\r
367 @param[in] Data Data pointer.\r
368 @param[in] DataSize Size of Data found. If size is less than the\r
369 data, this value contains the required size.\r
370 @param[in] Attributes Attribute value of the variable.\r
371\r
372 @return EFI_INVALID_PARAMETER Invalid parameter.\r
373 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation\r
374 check carried out by the firmware.\r
375 @return EFI_SUCCESS Variable pass validation successfully.\r
376\r
377**/\r
378EFI_STATUS\r
379ProcessVarWithKek (\r
380 IN CHAR16 *VariableName,\r
381 IN EFI_GUID *VendorGuid,\r
382 IN VOID *Data,\r
383 IN UINTN DataSize,\r
384 IN UINT32 Attributes OPTIONAL\r
385 );\r
386\r
387/**\r
388 Process variable with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS/EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set\r
389\r
390 Caution: This function may receive untrusted input.\r
391 This function may be invoked in SMM mode, and datasize and data are external input.\r
392 This function will do basic validation, before parse the data.\r
393 This function will parse the authentication carefully to avoid security issues, like\r
394 buffer overflow, integer overflow.\r
395 This function will check attribute carefully to avoid authentication bypass.\r
396\r
397 @param[in] VariableName Name of the variable.\r
398 @param[in] VendorGuid Variable vendor GUID.\r
399 @param[in] Data Data pointer.\r
400 @param[in] DataSize Size of Data.\r
401 @param[in] Attributes Attribute value of the variable.\r
402\r
403 @return EFI_INVALID_PARAMETER Invalid parameter.\r
404 @return EFI_WRITE_PROTECTED Variable is write-protected and needs authentication with\r
405 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS set.\r
406 @return EFI_OUT_OF_RESOURCES The Database to save the public key is full.\r
407 @return EFI_SECURITY_VIOLATION The variable is with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS\r
408 set, but the AuthInfo does NOT pass the validation\r
409 check carried out by the firmware.\r
410 @return EFI_SUCCESS Variable is not write-protected or pass validation successfully.\r
411\r
412**/\r
413EFI_STATUS\r
414ProcessVariable (\r
415 IN CHAR16 *VariableName,\r
416 IN EFI_GUID *VendorGuid,\r
417 IN VOID *Data,\r
418 IN UINTN DataSize,\r
98c2d961 419 IN UINT32 Attributes\r
a6811666
SZ
420 );\r
421\r
422/**\r
423 Finds variable in storage blocks of volatile and non-volatile storage areas.\r
424\r
425 This code finds variable in storage blocks of volatile and non-volatile storage areas.\r
426 If VariableName is an empty string, then we just return the first\r
427 qualified variable without comparing VariableName and VendorGuid.\r
428\r
429 @param[in] VariableName Name of the variable to be found.\r
430 @param[in] VendorGuid Variable vendor GUID to be found.\r
431 @param[out] Data Pointer to data address.\r
432 @param[out] DataSize Pointer to data size.\r
433\r
434 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,\r
435 while VendorGuid is NULL.\r
436 @retval EFI_SUCCESS Variable successfully found.\r
437 @retval EFI_NOT_FOUND Variable not found\r
438\r
439**/\r
440EFI_STATUS\r
441AuthServiceInternalFindVariable (\r
442 IN CHAR16 *VariableName,\r
443 IN EFI_GUID *VendorGuid,\r
444 OUT VOID **Data,\r
445 OUT UINTN *DataSize\r
446 );\r
447\r
448/**\r
449 Update the variable region with Variable information.\r
450\r
451 @param[in] VariableName Name of variable.\r
452 @param[in] VendorGuid Guid of variable.\r
453 @param[in] Data Data pointer.\r
454 @param[in] DataSize Size of Data.\r
455 @param[in] Attributes Attribute value of the variable.\r
456\r
457 @retval EFI_SUCCESS The update operation is success.\r
458 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
459 @retval EFI_WRITE_PROTECTED Variable is write-protected.\r
460 @retval EFI_OUT_OF_RESOURCES There is not enough resource.\r
461\r
462**/\r
463EFI_STATUS\r
464AuthServiceInternalUpdateVariable (\r
465 IN CHAR16 *VariableName,\r
466 IN EFI_GUID *VendorGuid,\r
467 IN VOID *Data,\r
468 IN UINTN DataSize,\r
469 IN UINT32 Attributes\r
470 );\r
471\r
472/**\r
473 Update the variable region with Variable information.\r
474\r
475 @param[in] VariableName Name of variable.\r
476 @param[in] VendorGuid Guid of variable.\r
477 @param[in] Data Data pointer.\r
478 @param[in] DataSize Size of Data.\r
479 @param[in] Attributes Attribute value of the variable.\r
480 @param[in] KeyIndex Index of associated public key.\r
481 @param[in] MonotonicCount Value of associated monotonic count.\r
482\r
483 @retval EFI_SUCCESS The update operation is success.\r
484 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
485 @retval EFI_WRITE_PROTECTED Variable is write-protected.\r
486 @retval EFI_OUT_OF_RESOURCES There is not enough resource.\r
487\r
488**/\r
489EFI_STATUS\r
490AuthServiceInternalUpdateVariableWithMonotonicCount (\r
491 IN CHAR16 *VariableName,\r
492 IN EFI_GUID *VendorGuid,\r
493 IN VOID *Data,\r
494 IN UINTN DataSize,\r
495 IN UINT32 Attributes,\r
496 IN UINT32 KeyIndex,\r
497 IN UINT64 MonotonicCount\r
498 );\r
499\r
500/**\r
501 Update the variable region with Variable information.\r
502\r
503 @param[in] VariableName Name of variable.\r
504 @param[in] VendorGuid Guid of variable.\r
505 @param[in] Data Data pointer.\r
506 @param[in] DataSize Size of Data.\r
507 @param[in] Attributes Attribute value of the variable.\r
508 @param[in] TimeStamp Value of associated TimeStamp.\r
509\r
510 @retval EFI_SUCCESS The update operation is success.\r
511 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
512 @retval EFI_WRITE_PROTECTED Variable is write-protected.\r
513 @retval EFI_OUT_OF_RESOURCES There is not enough resource.\r
514\r
515**/\r
516EFI_STATUS\r
517AuthServiceInternalUpdateVariableWithTimeStamp (\r
518 IN CHAR16 *VariableName,\r
519 IN EFI_GUID *VendorGuid,\r
520 IN VOID *Data,\r
521 IN UINTN DataSize,\r
522 IN UINT32 Attributes,\r
523 IN EFI_TIME *TimeStamp\r
524 );\r
525\r
526#endif\r