2 The internal header file includes the common header files, defines
3 internal structure and functions used by AuthService module.
5 Caution: This module requires additional review when modified.
6 This driver will have external input - variable data. It may be input in SMM mode.
7 This external input must be validated carefully to avoid security issue like
8 buffer overflow, integer overflow.
9 Variable attribute should also be checked to avoid authentication bypass.
10 The whole SMM authentication variable design relies on the integrity of flash part and SMM.
11 which is assumed to be protected by platform. All variable code and metadata in flash/SMM Memory
12 may not be modified without authorization. If platform fails to protect these resources,
13 the authentication service provided in this driver will be broken, and the behavior is undefined.
15 Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
16 This program and the accompanying materials
17 are licensed and made available under the terms and conditions of the BSD License
18 which accompanies this distribution. The full text of the license may be found at
19 http://opensource.org/licenses/bsd-license.php
21 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
22 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
26 #ifndef _AUTHSERVICE_INTERNAL_H_
27 #define _AUTHSERVICE_INTERNAL_H_
29 #include <Library/AuthVariableLib.h>
30 #include <Library/BaseLib.h>
31 #include <Library/BaseMemoryLib.h>
32 #include <Library/DebugLib.h>
33 #include <Library/MemoryAllocationLib.h>
34 #include <Library/BaseCryptLib.h>
35 #include <Library/PlatformSecureLib.h>
37 #include <Guid/AuthenticatedVariableFormat.h>
38 #include <Guid/ImageAuthentication.h>
41 /// Struct to record signature requirement defined by UEFI spec.
42 /// For SigHeaderSize and SigDataSize, ((UINT32) ~0) means NO exact length requirement for this field.
46 // Expected SignatureHeader size in Bytes.
48 // Expected SignatureData size in Bytes.
60 /// "AuthVarKeyDatabase" variable for the Public Key store
61 /// of variables with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS set.
63 /// GUID: gEfiAuthenticatedVariableGuid
65 /// We need maintain atomicity.
68 /// +----------------------------+
69 /// | AUTHVAR_KEY_DB_DATA | <-- First AuthVarKey
70 /// +----------------------------+
72 /// +----------------------------+
73 /// | AUTHVAR_KEY_DB_DATA | <-- Last AuthKey
74 /// +----------------------------+
76 #define AUTHVAR_KEYDB_NAME L"AuthVarKeyDatabase"
78 #define EFI_CERT_TYPE_RSA2048_SHA256_SIZE 256
79 #define EFI_CERT_TYPE_RSA2048_SIZE 256
84 UINT8 KeyData
[EFI_CERT_TYPE_RSA2048_SIZE
];
85 } AUTHVAR_KEY_DB_DATA
;
89 /// "certdb" variable stores the signer's certificates for non PK/KEK/DB/DBX
90 /// variables with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS|EFI_VARIABLE_NON_VOLATILE set.
91 /// "certdbv" variable stores the signer's certificates for non PK/KEK/DB/DBX
92 /// variables with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
94 /// GUID: gEfiCertDbGuid
96 /// We need maintain atomicity.
99 /// +----------------------------+
100 /// | UINT32 | <-- CertDbListSize, including this UINT32
101 /// +----------------------------+
102 /// | AUTH_CERT_DB_DATA | <-- First CERT
103 /// +----------------------------+
105 /// +----------------------------+
106 /// | AUTH_CERT_DB_DATA | <-- Last CERT
107 /// +----------------------------+
109 #define EFI_CERT_DB_NAME L"certdb"
110 #define EFI_CERT_DB_VOLATILE_NAME L"certdbv"
118 /// CHAR16 VariableName[NameSize];
119 /// UINT8 CertData[CertDataSize];
124 /// "SecureBootMode" variable stores current secure boot mode.
125 /// The value type is SECURE_BOOT_MODE_TYPE.
127 #define EDKII_SECURE_BOOT_MODE_NAME L"SecureBootMode"
130 SecureBootModeTypeUserMode
,
131 SecureBootModeTypeSetupMode
,
132 SecureBootModeTypeAuditMode
,
133 SecureBootModeTypeDeployedMode
,
134 SecureBootModeTypeMax
135 } SECURE_BOOT_MODE_TYPE
;
138 // Record status info of Customized Secure Boot Mode.
142 /// AuditMode variable value
146 /// AuditMode variable RW
148 BOOLEAN IsAuditModeRO
;
150 /// DeployedMode variable value
154 /// AuditMode variable RW
156 BOOLEAN IsDeployedModeRO
;
158 /// SetupMode variable value
162 /// SetupMode is always RO. Skip IsSetupModeRO;
166 /// SecureBoot variable value
171 extern UINT8
*mPubKeyStore
;
172 extern UINT32 mPubKeyNumber
;
173 extern UINT32 mMaxKeyNumber
;
174 extern UINT32 mMaxKeyDbSize
;
175 extern UINT8
*mCertDbStore
;
176 extern UINT32 mMaxCertDbSize
;
177 extern UINT32 mPlatformMode
;
178 extern UINT8 mVendorKeyState
;
180 extern VOID
*mHashCtx
;
182 extern AUTH_VAR_LIB_CONTEXT_IN
*mAuthVarLibContextIn
;
185 Initialize Secure Boot variables.
187 @retval EFI_SUCCESS The initialization operation is successful.
188 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
192 InitSecureBootVariables (
197 Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
199 Caution: This function may receive untrusted input.
200 This function may be invoked in SMM mode, and datasize and data are external input.
201 This function will do basic validation, before parse the data.
202 This function will parse the authentication carefully to avoid security issues, like
203 buffer overflow, integer overflow.
205 @param[in] VariableName Name of Variable to be found.
206 @param[in] VendorGuid Variable vendor GUID.
207 @param[in] Data Data pointer.
208 @param[in] DataSize Size of Data found. If size is less than the
209 data, this value contains the required size.
210 @param[in] Attributes Attribute value of the variable.
211 @param[in] AuthVarType Verify against PK, KEK database, private database or certificate in data payload.
212 @param[out] VarDel Delete the variable or not.
214 @retval EFI_INVALID_PARAMETER Invalid parameter.
215 @retval EFI_SECURITY_VIOLATION The variable does NOT pass the validation
216 check carried out by the firmware.
217 @retval EFI_OUT_OF_RESOURCES Failed to process variable due to lack
219 @retval EFI_SUCCESS Variable pass validation successfully.
223 VerifyTimeBasedPayloadAndUpdate (
224 IN CHAR16
*VariableName
,
225 IN EFI_GUID
*VendorGuid
,
228 IN UINT32 Attributes
,
229 IN AUTHVAR_TYPE AuthVarType
,
234 Delete matching signer's certificates when deleting common authenticated
235 variable by corresponding VariableName and VendorGuid from "certdb" or
236 "certdbv" according to authenticated variable attributes.
238 @param[in] VariableName Name of authenticated Variable.
239 @param[in] VendorGuid Vendor GUID of authenticated Variable.
240 @param[in] Attributes Attributes of authenticated variable.
242 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
243 @retval EFI_NOT_FOUND Fail to find "certdb"/"certdbv" or matching certs.
244 @retval EFI_OUT_OF_RESOURCES The operation is failed due to lack of resources.
245 @retval EFI_SUCCESS The operation is completed successfully.
250 IN CHAR16
*VariableName
,
251 IN EFI_GUID
*VendorGuid
,
256 Clean up signer's certificates for common authenticated variable
257 by corresponding VariableName and VendorGuid from "certdb".
258 Sytem may break down during Timebased Variable update & certdb update,
259 make them inconsistent, this function is called in AuthVariable Init to ensure
262 @retval EFI_NOT_FOUND Fail to find matching certs.
263 @retval EFI_SUCCESS Find matching certs and output parameters.
272 Filter out the duplicated EFI_SIGNATURE_DATA from the new data by comparing to the original data.
274 @param[in] Data Pointer to original EFI_SIGNATURE_LIST.
275 @param[in] DataSize Size of Data buffer.
276 @param[in, out] NewData Pointer to new EFI_SIGNATURE_LIST.
277 @param[in, out] NewDataSize Size of NewData buffer.
281 FilterSignatureList (
284 IN OUT VOID
*NewData
,
285 IN OUT UINTN
*NewDataSize
289 Process Secure Boot Mode variable.
291 Caution: This function may receive untrusted input.
292 This function may be invoked in SMM mode, and datasize and data are external input.
293 This function will do basic validation, before parse the data.
294 This function will parse the authentication carefully to avoid security issues, like
295 buffer overflow, integer overflow.
296 This function will check attribute carefully to avoid authentication bypass.
298 @param[in] VariableName Name of Variable to be found.
299 @param[in] VendorGuid Variable vendor GUID.
300 @param[in] Data Data pointer.
301 @param[in] DataSize Size of Data found. If size is less than the
302 data, this value contains the required size.
303 @param[in] Attributes Attribute value of the variable
305 @return EFI_INVALID_PARAMETER Invalid parameter
306 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation
307 check carried out by the firmware.
308 @return EFI_WRITE_PROTECTED Variable is Read-Only.
309 @return EFI_SUCCESS Variable passed validation successfully.
313 ProcessSecureBootModeVar (
314 IN CHAR16
*VariableName
,
315 IN EFI_GUID
*VendorGuid
,
318 IN UINT32 Attributes OPTIONAL
322 Process variable with platform key for verification.
324 Caution: This function may receive untrusted input.
325 This function may be invoked in SMM mode, and datasize and data are external input.
326 This function will do basic validation, before parse the data.
327 This function will parse the authentication carefully to avoid security issues, like
328 buffer overflow, integer overflow.
329 This function will check attribute carefully to avoid authentication bypass.
331 @param[in] VariableName Name of Variable to be found.
332 @param[in] VendorGuid Variable vendor GUID.
333 @param[in] Data Data pointer.
334 @param[in] DataSize Size of Data found. If size is less than the
335 data, this value contains the required size.
336 @param[in] Attributes Attribute value of the variable
337 @param[in] IsPk Indicate whether it is to process pk.
339 @return EFI_INVALID_PARAMETER Invalid parameter.
340 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation.
341 check carried out by the firmware.
342 @return EFI_SUCCESS Variable passed validation successfully.
347 IN CHAR16
*VariableName
,
348 IN EFI_GUID
*VendorGuid
,
351 IN UINT32 Attributes OPTIONAL
,
356 Process variable with key exchange key for verification.
358 Caution: This function may receive untrusted input.
359 This function may be invoked in SMM mode, and datasize and data are external input.
360 This function will do basic validation, before parse the data.
361 This function will parse the authentication carefully to avoid security issues, like
362 buffer overflow, integer overflow.
363 This function will check attribute carefully to avoid authentication bypass.
365 @param[in] VariableName Name of Variable to be found.
366 @param[in] VendorGuid Variable vendor GUID.
367 @param[in] Data Data pointer.
368 @param[in] DataSize Size of Data found. If size is less than the
369 data, this value contains the required size.
370 @param[in] Attributes Attribute value of the variable.
372 @return EFI_INVALID_PARAMETER Invalid parameter.
373 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation
374 check carried out by the firmware.
375 @return EFI_SUCCESS Variable pass validation successfully.
380 IN CHAR16
*VariableName
,
381 IN EFI_GUID
*VendorGuid
,
384 IN UINT32 Attributes OPTIONAL
388 Process variable with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS/EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
390 Caution: This function may receive untrusted input.
391 This function may be invoked in SMM mode, and datasize and data are external input.
392 This function will do basic validation, before parse the data.
393 This function will parse the authentication carefully to avoid security issues, like
394 buffer overflow, integer overflow.
395 This function will check attribute carefully to avoid authentication bypass.
397 @param[in] VariableName Name of the variable.
398 @param[in] VendorGuid Variable vendor GUID.
399 @param[in] Data Data pointer.
400 @param[in] DataSize Size of Data.
401 @param[in] Attributes Attribute value of the variable.
403 @return EFI_INVALID_PARAMETER Invalid parameter.
404 @return EFI_WRITE_PROTECTED Variable is write-protected and needs authentication with
405 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS set.
406 @return EFI_OUT_OF_RESOURCES The Database to save the public key is full.
407 @return EFI_SECURITY_VIOLATION The variable is with EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
408 set, but the AuthInfo does NOT pass the validation
409 check carried out by the firmware.
410 @return EFI_SUCCESS Variable is not write-protected or pass validation successfully.
415 IN CHAR16
*VariableName
,
416 IN EFI_GUID
*VendorGuid
,
423 Finds variable in storage blocks of volatile and non-volatile storage areas.
425 This code finds variable in storage blocks of volatile and non-volatile storage areas.
426 If VariableName is an empty string, then we just return the first
427 qualified variable without comparing VariableName and VendorGuid.
429 @param[in] VariableName Name of the variable to be found.
430 @param[in] VendorGuid Variable vendor GUID to be found.
431 @param[out] Data Pointer to data address.
432 @param[out] DataSize Pointer to data size.
434 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,
435 while VendorGuid is NULL.
436 @retval EFI_SUCCESS Variable successfully found.
437 @retval EFI_NOT_FOUND Variable not found
441 AuthServiceInternalFindVariable (
442 IN CHAR16
*VariableName
,
443 IN EFI_GUID
*VendorGuid
,
449 Update the variable region with Variable information.
451 @param[in] VariableName Name of variable.
452 @param[in] VendorGuid Guid of variable.
453 @param[in] Data Data pointer.
454 @param[in] DataSize Size of Data.
455 @param[in] Attributes Attribute value of the variable.
457 @retval EFI_SUCCESS The update operation is success.
458 @retval EFI_INVALID_PARAMETER Invalid parameter.
459 @retval EFI_WRITE_PROTECTED Variable is write-protected.
460 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
464 AuthServiceInternalUpdateVariable (
465 IN CHAR16
*VariableName
,
466 IN EFI_GUID
*VendorGuid
,
473 Update the variable region with Variable information.
475 @param[in] VariableName Name of variable.
476 @param[in] VendorGuid Guid of variable.
477 @param[in] Data Data pointer.
478 @param[in] DataSize Size of Data.
479 @param[in] Attributes Attribute value of the variable.
480 @param[in] KeyIndex Index of associated public key.
481 @param[in] MonotonicCount Value of associated monotonic count.
483 @retval EFI_SUCCESS The update operation is success.
484 @retval EFI_INVALID_PARAMETER Invalid parameter.
485 @retval EFI_WRITE_PROTECTED Variable is write-protected.
486 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
490 AuthServiceInternalUpdateVariableWithMonotonicCount (
491 IN CHAR16
*VariableName
,
492 IN EFI_GUID
*VendorGuid
,
495 IN UINT32 Attributes
,
497 IN UINT64 MonotonicCount
501 Update the variable region with Variable information.
503 @param[in] VariableName Name of variable.
504 @param[in] VendorGuid Guid of variable.
505 @param[in] Data Data pointer.
506 @param[in] DataSize Size of Data.
507 @param[in] Attributes Attribute value of the variable.
508 @param[in] TimeStamp Value of associated TimeStamp.
510 @retval EFI_SUCCESS The update operation is success.
511 @retval EFI_INVALID_PARAMETER Invalid parameter.
512 @retval EFI_WRITE_PROTECTED Variable is write-protected.
513 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
517 AuthServiceInternalUpdateVariableWithTimeStamp (
518 IN CHAR16
*VariableName
,
519 IN EFI_GUID
*VendorGuid
,
522 IN UINT32 Attributes
,
523 IN EFI_TIME
*TimeStamp