]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Library/AuthVariableLib/AuthServiceInternal.h
SecurityPkg: AuthVariableLib: Customized SecureBoot Mode transition.
[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
15Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
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
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 set.\r
91///\r
92/// GUID: gEfiCertDbGuid\r
93///\r
94/// We need maintain atomicity.\r
95///\r
96/// Format:\r
97/// +----------------------------+\r
98/// | UINT32 | <-- CertDbListSize, including this UINT32\r
99/// +----------------------------+\r
100/// | AUTH_CERT_DB_DATA | <-- First CERT\r
101/// +----------------------------+\r
102/// | ........ |\r
103/// +----------------------------+\r
104/// | AUTH_CERT_DB_DATA | <-- Last CERT\r
105/// +----------------------------+\r
106///\r
107#define EFI_CERT_DB_NAME L"certdb"\r
108\r
109#pragma pack(1)\r
110typedef struct {\r
111 EFI_GUID VendorGuid;\r
112 UINT32 CertNodeSize;\r
113 UINT32 NameSize;\r
114 UINT32 CertDataSize;\r
115 /// CHAR16 VariableName[NameSize];\r
116 /// UINT8 CertData[CertDataSize];\r
117} AUTH_CERT_DB_DATA;\r
118#pragma pack()\r
119\r
4fc08e8d
CZ
120///\r
121/// "SecureBootMode" variable stores current secure boot mode.\r
122/// The value type is SECURE_BOOT_MODE_TYPE.\r
123///\r
124#define EDKII_SECURE_BOOT_MODE_NAME L"SecureBootMode"\r
125\r
126typedef enum { \r
127 SecureBootModeTypeUserMode,\r
128 SecureBootModeTypeSetupMode,\r
129 SecureBootModeTypeAuditMode,\r
130 SecureBootModeTypeDeployedMode,\r
131 SecureBootModeTypeMax\r
132} SECURE_BOOT_MODE_TYPE;\r
133\r
134//\r
135// Record status info of Customized Secure Boot Mode.\r
136//\r
137typedef struct {\r
138 ///\r
139 /// AuditMode variable value\r
140 ///\r
141 UINT8 AuditMode;\r
142 ///\r
143 /// AuditMode variable RW\r
144 ///\r
145 BOOLEAN IsAuditModeRO;\r
146 ///\r
147 /// DeployedMode variable value\r
148 ///\r
149 UINT8 DeployedMode;\r
150 ///\r
151 /// AuditMode variable RW\r
152 ///\r
153 BOOLEAN IsDeployedModeRO;\r
154 ///\r
155 /// SetupMode variable value\r
156 ///\r
157 UINT8 SetupMode;\r
158 /// \r
159 /// SetupMode is always RO. Skip IsSetupModeRO; \r
160 ///\r
161\r
162 ///\r
163 /// SecureBoot variable value\r
164 ///\r
165 UINT8 SecureBoot;\r
166} SECURE_BOOT_MODE;\r
167\r
a6811666
SZ
168extern UINT8 *mPubKeyStore;\r
169extern UINT32 mPubKeyNumber;\r
170extern UINT32 mMaxKeyNumber;\r
171extern UINT32 mMaxKeyDbSize;\r
172extern UINT8 *mCertDbStore;\r
173extern UINT32 mMaxCertDbSize;\r
174extern UINT32 mPlatformMode;\r
175extern UINT8 mVendorKeyState;\r
176\r
177extern VOID *mHashCtx;\r
178\r
179extern AUTH_VAR_LIB_CONTEXT_IN *mAuthVarLibContextIn;\r
180\r
4fc08e8d
CZ
181/**\r
182 Initialize Secure Boot variables.\r
183\r
184 @retval EFI_SUCCESS The initialization operation is successful.\r
185 @retval EFI_OUT_OF_RESOURCES There is not enough resource.\r
186\r
187**/\r
188EFI_STATUS \r
189InitSecureBootVariables (\r
190 VOID\r
191 );\r
192\r
a6811666
SZ
193/**\r
194 Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set\r
195\r
196 Caution: This function may receive untrusted input.\r
197 This function may be invoked in SMM mode, and datasize and data are external input.\r
198 This function will do basic validation, before parse the data.\r
199 This function will parse the authentication carefully to avoid security issues, like\r
200 buffer overflow, integer overflow.\r
201\r
202 @param[in] VariableName Name of Variable to be found.\r
203 @param[in] VendorGuid Variable vendor GUID.\r
204 @param[in] Data Data pointer.\r
205 @param[in] DataSize Size of Data found. If size is less than the\r
206 data, this value contains the required size.\r
207 @param[in] Attributes Attribute value of the variable.\r
208 @param[in] AuthVarType Verify against PK, KEK database, private database or certificate in data payload.\r
209 @param[out] VarDel Delete the variable or not.\r
210\r
211 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
212 @retval EFI_SECURITY_VIOLATION The variable does NOT pass the validation\r
213 check carried out by the firmware.\r
214 @retval EFI_OUT_OF_RESOURCES Failed to process variable due to lack\r
215 of resources.\r
216 @retval EFI_SUCCESS Variable pass validation successfully.\r
217\r
218**/\r
219EFI_STATUS\r
220VerifyTimeBasedPayloadAndUpdate (\r
221 IN CHAR16 *VariableName,\r
222 IN EFI_GUID *VendorGuid,\r
223 IN VOID *Data,\r
224 IN UINTN DataSize,\r
225 IN UINT32 Attributes,\r
226 IN AUTHVAR_TYPE AuthVarType,\r
227 OUT BOOLEAN *VarDel\r
228 );\r
229\r
230/**\r
231 Delete matching signer's certificates when deleting common authenticated\r
232 variable by corresponding VariableName and VendorGuid from "certdb".\r
233\r
234 @param[in] VariableName Name of authenticated Variable.\r
235 @param[in] VendorGuid Vendor GUID of authenticated Variable.\r
236\r
237 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.\r
238 @retval EFI_NOT_FOUND Fail to find "certdb" or matching certs.\r
239 @retval EFI_OUT_OF_RESOURCES The operation is failed due to lack of resources.\r
240 @retval EFI_SUCCESS The operation is completed successfully.\r
241\r
242**/\r
243EFI_STATUS\r
244DeleteCertsFromDb (\r
245 IN CHAR16 *VariableName,\r
246 IN EFI_GUID *VendorGuid\r
247 );\r
248\r
64b6a3ff
CZ
249/**\r
250 Clean up signer's certificates for common authenticated variable\r
251 by corresponding VariableName and VendorGuid from "certdb".\r
252 Sytem may break down during Timebased Variable update & certdb update,\r
253 make them inconsistent, this function is called in AuthVariable Init to ensure \r
254 consistency\r
255 \r
256 @retval EFI_NOT_FOUND Fail to find matching certs.\r
257 @retval EFI_SUCCESS Find matching certs and output parameters.\r
258\r
259**/\r
260EFI_STATUS\r
261CleanCertsFromDb (\r
262 VOID\r
263 );\r
264\r
a6811666
SZ
265/**\r
266 Filter out the duplicated EFI_SIGNATURE_DATA from the new data by comparing to the original data.\r
267\r
268 @param[in] Data Pointer to original EFI_SIGNATURE_LIST.\r
269 @param[in] DataSize Size of Data buffer.\r
270 @param[in, out] NewData Pointer to new EFI_SIGNATURE_LIST.\r
271 @param[in, out] NewDataSize Size of NewData buffer.\r
272\r
273**/\r
274EFI_STATUS\r
275FilterSignatureList (\r
276 IN VOID *Data,\r
277 IN UINTN DataSize,\r
278 IN OUT VOID *NewData,\r
279 IN OUT UINTN *NewDataSize\r
280 );\r
281\r
4fc08e8d
CZ
282/**\r
283 Process Secure Boot Mode variable.\r
284\r
285 Caution: This function may receive untrusted input.\r
286 This function may be invoked in SMM mode, and datasize and data are external input.\r
287 This function will do basic validation, before parse the data.\r
288 This function will parse the authentication carefully to avoid security issues, like\r
289 buffer overflow, integer overflow.\r
290 This function will check attribute carefully to avoid authentication bypass.\r
291\r
292 @param[in] VariableName Name of Variable to be found.\r
293 @param[in] VendorGuid Variable vendor GUID.\r
294 @param[in] Data Data pointer.\r
295 @param[in] DataSize Size of Data found. If size is less than the\r
296 data, this value contains the required size.\r
297 @param[in] Attributes Attribute value of the variable\r
298\r
299 @return EFI_INVALID_PARAMETER Invalid parameter\r
300 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation\r
301 check carried out by the firmware.\r
302 @return EFI_WRITE_PROTECTED Variable is Read-Only.\r
303 @return EFI_SUCCESS Variable passed validation successfully.\r
304\r
305**/\r
306EFI_STATUS\r
307ProcessSecureBootModeVar (\r
308 IN CHAR16 *VariableName,\r
309 IN EFI_GUID *VendorGuid,\r
310 IN VOID *Data,\r
311 IN UINTN DataSize,\r
312 IN UINT32 Attributes OPTIONAL\r
313 );\r
314\r
a6811666
SZ
315/**\r
316 Process variable with platform key for verification.\r
317\r
318 Caution: This function may receive untrusted input.\r
319 This function may be invoked in SMM mode, and datasize and data are external input.\r
320 This function will do basic validation, before parse the data.\r
321 This function will parse the authentication carefully to avoid security issues, like\r
322 buffer overflow, integer overflow.\r
323 This function will check attribute carefully to avoid authentication bypass.\r
324\r
325 @param[in] VariableName Name of Variable to be found.\r
326 @param[in] VendorGuid Variable vendor GUID.\r
327 @param[in] Data Data pointer.\r
328 @param[in] DataSize Size of Data found. If size is less than the\r
329 data, this value contains the required size.\r
330 @param[in] Attributes Attribute value of the variable\r
331 @param[in] IsPk Indicate whether it is to process pk.\r
332\r
333 @return EFI_INVALID_PARAMETER Invalid parameter.\r
334 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation.\r
335 check carried out by the firmware.\r
336 @return EFI_SUCCESS Variable passed validation successfully.\r
337\r
338**/\r
339EFI_STATUS\r
340ProcessVarWithPk (\r
341 IN CHAR16 *VariableName,\r
342 IN EFI_GUID *VendorGuid,\r
343 IN VOID *Data,\r
344 IN UINTN DataSize,\r
345 IN UINT32 Attributes OPTIONAL,\r
346 IN BOOLEAN IsPk\r
347 );\r
348\r
349/**\r
350 Process variable with key exchange key for verification.\r
351\r
352 Caution: This function may receive untrusted input.\r
353 This function may be invoked in SMM mode, and datasize and data are external input.\r
354 This function will do basic validation, before parse the data.\r
355 This function will parse the authentication carefully to avoid security issues, like\r
356 buffer overflow, integer overflow.\r
357 This function will check attribute carefully to avoid authentication bypass.\r
358\r
359 @param[in] VariableName Name of Variable to be found.\r
360 @param[in] VendorGuid Variable vendor GUID.\r
361 @param[in] Data Data pointer.\r
362 @param[in] DataSize Size of Data found. If size is less than the\r
363 data, this value contains the required size.\r
364 @param[in] Attributes Attribute value of the variable.\r
365\r
366 @return EFI_INVALID_PARAMETER Invalid parameter.\r
367 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation\r
368 check carried out by the firmware.\r
369 @return EFI_SUCCESS Variable pass validation successfully.\r
370\r
371**/\r
372EFI_STATUS\r
373ProcessVarWithKek (\r
374 IN CHAR16 *VariableName,\r
375 IN EFI_GUID *VendorGuid,\r
376 IN VOID *Data,\r
377 IN UINTN DataSize,\r
378 IN UINT32 Attributes OPTIONAL\r
379 );\r
380\r
381/**\r
382 Process variable with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS/EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set\r
383\r
384 Caution: This function may receive untrusted input.\r
385 This function may be invoked in SMM mode, and datasize and data are external input.\r
386 This function will do basic validation, before parse the data.\r
387 This function will parse the authentication carefully to avoid security issues, like\r
388 buffer overflow, integer overflow.\r
389 This function will check attribute carefully to avoid authentication bypass.\r
390\r
391 @param[in] VariableName Name of the variable.\r
392 @param[in] VendorGuid Variable vendor GUID.\r
393 @param[in] Data Data pointer.\r
394 @param[in] DataSize Size of Data.\r
395 @param[in] Attributes Attribute value of the variable.\r
396\r
397 @return EFI_INVALID_PARAMETER Invalid parameter.\r
398 @return EFI_WRITE_PROTECTED Variable is write-protected and needs authentication with\r
399 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS set.\r
400 @return EFI_OUT_OF_RESOURCES The Database to save the public key is full.\r
401 @return EFI_SECURITY_VIOLATION The variable is with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS\r
402 set, but the AuthInfo does NOT pass the validation\r
403 check carried out by the firmware.\r
404 @return EFI_SUCCESS Variable is not write-protected or pass validation successfully.\r
405\r
406**/\r
407EFI_STATUS\r
408ProcessVariable (\r
409 IN CHAR16 *VariableName,\r
410 IN EFI_GUID *VendorGuid,\r
411 IN VOID *Data,\r
412 IN UINTN DataSize,\r
413 IN UINT32 Attributes OPTIONAL\r
414 );\r
415\r
416/**\r
417 Finds variable in storage blocks of volatile and non-volatile storage areas.\r
418\r
419 This code finds variable in storage blocks of volatile and non-volatile storage areas.\r
420 If VariableName is an empty string, then we just return the first\r
421 qualified variable without comparing VariableName and VendorGuid.\r
422\r
423 @param[in] VariableName Name of the variable to be found.\r
424 @param[in] VendorGuid Variable vendor GUID to be found.\r
425 @param[out] Data Pointer to data address.\r
426 @param[out] DataSize Pointer to data size.\r
427\r
428 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,\r
429 while VendorGuid is NULL.\r
430 @retval EFI_SUCCESS Variable successfully found.\r
431 @retval EFI_NOT_FOUND Variable not found\r
432\r
433**/\r
434EFI_STATUS\r
435AuthServiceInternalFindVariable (\r
436 IN CHAR16 *VariableName,\r
437 IN EFI_GUID *VendorGuid,\r
438 OUT VOID **Data,\r
439 OUT UINTN *DataSize\r
440 );\r
441\r
442/**\r
443 Update the variable region with Variable information.\r
444\r
445 @param[in] VariableName Name of variable.\r
446 @param[in] VendorGuid Guid of variable.\r
447 @param[in] Data Data pointer.\r
448 @param[in] DataSize Size of Data.\r
449 @param[in] Attributes Attribute value of the variable.\r
450\r
451 @retval EFI_SUCCESS The update operation is success.\r
452 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
453 @retval EFI_WRITE_PROTECTED Variable is write-protected.\r
454 @retval EFI_OUT_OF_RESOURCES There is not enough resource.\r
455\r
456**/\r
457EFI_STATUS\r
458AuthServiceInternalUpdateVariable (\r
459 IN CHAR16 *VariableName,\r
460 IN EFI_GUID *VendorGuid,\r
461 IN VOID *Data,\r
462 IN UINTN DataSize,\r
463 IN UINT32 Attributes\r
464 );\r
465\r
466/**\r
467 Update the variable region with Variable information.\r
468\r
469 @param[in] VariableName Name of variable.\r
470 @param[in] VendorGuid Guid of variable.\r
471 @param[in] Data Data pointer.\r
472 @param[in] DataSize Size of Data.\r
473 @param[in] Attributes Attribute value of the variable.\r
474 @param[in] KeyIndex Index of associated public key.\r
475 @param[in] MonotonicCount Value of associated monotonic count.\r
476\r
477 @retval EFI_SUCCESS The update operation is success.\r
478 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
479 @retval EFI_WRITE_PROTECTED Variable is write-protected.\r
480 @retval EFI_OUT_OF_RESOURCES There is not enough resource.\r
481\r
482**/\r
483EFI_STATUS\r
484AuthServiceInternalUpdateVariableWithMonotonicCount (\r
485 IN CHAR16 *VariableName,\r
486 IN EFI_GUID *VendorGuid,\r
487 IN VOID *Data,\r
488 IN UINTN DataSize,\r
489 IN UINT32 Attributes,\r
490 IN UINT32 KeyIndex,\r
491 IN UINT64 MonotonicCount\r
492 );\r
493\r
494/**\r
495 Update the variable region with Variable information.\r
496\r
497 @param[in] VariableName Name of variable.\r
498 @param[in] VendorGuid Guid of variable.\r
499 @param[in] Data Data pointer.\r
500 @param[in] DataSize Size of Data.\r
501 @param[in] Attributes Attribute value of the variable.\r
502 @param[in] TimeStamp Value of associated TimeStamp.\r
503\r
504 @retval EFI_SUCCESS The update operation is success.\r
505 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
506 @retval EFI_WRITE_PROTECTED Variable is write-protected.\r
507 @retval EFI_OUT_OF_RESOURCES There is not enough resource.\r
508\r
509**/\r
510EFI_STATUS\r
511AuthServiceInternalUpdateVariableWithTimeStamp (\r
512 IN CHAR16 *VariableName,\r
513 IN EFI_GUID *VendorGuid,\r
514 IN VOID *Data,\r
515 IN UINTN DataSize,\r
516 IN UINT32 Attributes,\r
517 IN EFI_TIME *TimeStamp\r
518 );\r
519\r
520#endif\r