2 Implement authentication services for the authenticated variables.
4 Caution: This module requires additional review when modified.
5 This driver will have external input - variable data. It may be input in SMM mode.
6 This external input must be validated carefully to avoid security issue like
7 buffer overflow, integer overflow.
8 Variable attribute should also be checked to avoid authentication bypass.
9 The whole SMM authentication variable design relies on the integrity of flash part and SMM.
10 which is assumed to be protected by platform. All variable code and metadata in flash/SMM Memory
11 may not be modified without authorization. If platform fails to protect these resources,
12 the authentication service provided in this driver will be broken, and the behavior is undefined.
14 ProcessVarWithPk(), ProcessVarWithKek() and ProcessVariable() are the function to do
15 variable authentication.
17 VerifyTimeBasedPayloadAndUpdate() and VerifyCounterBasedPayload() are sub function to do verification.
18 They will do basic validation for authentication data structure, then call crypto library
19 to verify the signature.
21 Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.<BR>
22 SPDX-License-Identifier: BSD-2-Clause-Patent
26 #include "AuthServiceInternal.h"
29 // Public Exponent of RSA Key.
31 CONST UINT8 mRsaE
[] = { 0x01, 0x00, 0x01 };
33 CONST UINT8 mSha256OidValue
[] = { 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01 };
36 // Requirement for different signature type which have been defined in UEFI spec.
37 // These data are used to perform SignatureList format check while setting PK/KEK variable.
39 EFI_SIGNATURE_ITEM mSupportSigItem
[] = {
40 //{SigType, SigHeaderSize, SigDataSize }
41 {EFI_CERT_SHA256_GUID
, 0, 32 },
42 {EFI_CERT_RSA2048_GUID
, 0, 256 },
43 {EFI_CERT_RSA2048_SHA256_GUID
, 0, 256 },
44 {EFI_CERT_SHA1_GUID
, 0, 20 },
45 {EFI_CERT_RSA2048_SHA1_GUID
, 0, 256 },
46 {EFI_CERT_X509_GUID
, 0, ((UINT32
) ~0)},
47 {EFI_CERT_SHA224_GUID
, 0, 28 },
48 {EFI_CERT_SHA384_GUID
, 0, 48 },
49 {EFI_CERT_SHA512_GUID
, 0, 64 },
50 {EFI_CERT_X509_SHA256_GUID
, 0, 48 },
51 {EFI_CERT_X509_SHA384_GUID
, 0, 64 },
52 {EFI_CERT_X509_SHA512_GUID
, 0, 80 }
56 Finds variable in storage blocks of volatile and non-volatile storage areas.
58 This code finds variable in storage blocks of volatile and non-volatile storage areas.
59 If VariableName is an empty string, then we just return the first
60 qualified variable without comparing VariableName and VendorGuid.
62 @param[in] VariableName Name of the variable to be found.
63 @param[in] VendorGuid Variable vendor GUID to be found.
64 @param[out] Data Pointer to data address.
65 @param[out] DataSize Pointer to data size.
67 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string,
68 while VendorGuid is NULL.
69 @retval EFI_SUCCESS Variable successfully found.
70 @retval EFI_NOT_FOUND Variable not found
74 AuthServiceInternalFindVariable (
75 IN CHAR16
*VariableName
,
76 IN EFI_GUID
*VendorGuid
,
82 AUTH_VARIABLE_INFO AuthVariableInfo
;
84 ZeroMem (&AuthVariableInfo
, sizeof (AuthVariableInfo
));
85 Status
= mAuthVarLibContextIn
->FindVariable (
90 *Data
= AuthVariableInfo
.Data
;
91 *DataSize
= AuthVariableInfo
.DataSize
;
96 Update the variable region with Variable information.
98 @param[in] VariableName Name of variable.
99 @param[in] VendorGuid Guid of variable.
100 @param[in] Data Data pointer.
101 @param[in] DataSize Size of Data.
102 @param[in] Attributes Attribute value of the variable.
104 @retval EFI_SUCCESS The update operation is success.
105 @retval EFI_INVALID_PARAMETER Invalid parameter.
106 @retval EFI_WRITE_PROTECTED Variable is write-protected.
107 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
111 AuthServiceInternalUpdateVariable (
112 IN CHAR16
*VariableName
,
113 IN EFI_GUID
*VendorGuid
,
119 AUTH_VARIABLE_INFO AuthVariableInfo
;
121 ZeroMem (&AuthVariableInfo
, sizeof (AuthVariableInfo
));
122 AuthVariableInfo
.VariableName
= VariableName
;
123 AuthVariableInfo
.VendorGuid
= VendorGuid
;
124 AuthVariableInfo
.Data
= Data
;
125 AuthVariableInfo
.DataSize
= DataSize
;
126 AuthVariableInfo
.Attributes
= Attributes
;
128 return mAuthVarLibContextIn
->UpdateVariable (
134 Update the variable region with Variable information.
136 @param[in] VariableName Name of variable.
137 @param[in] VendorGuid Guid of variable.
138 @param[in] Data Data pointer.
139 @param[in] DataSize Size of Data.
140 @param[in] Attributes Attribute value of the variable.
141 @param[in] TimeStamp Value of associated TimeStamp.
143 @retval EFI_SUCCESS The update operation is success.
144 @retval EFI_INVALID_PARAMETER Invalid parameter.
145 @retval EFI_WRITE_PROTECTED Variable is write-protected.
146 @retval EFI_OUT_OF_RESOURCES There is not enough resource.
150 AuthServiceInternalUpdateVariableWithTimeStamp (
151 IN CHAR16
*VariableName
,
152 IN EFI_GUID
*VendorGuid
,
155 IN UINT32 Attributes
,
156 IN EFI_TIME
*TimeStamp
159 EFI_STATUS FindStatus
;
162 AUTH_VARIABLE_INFO AuthVariableInfo
;
164 FindStatus
= AuthServiceInternalFindVariable (
172 // EFI_VARIABLE_APPEND_WRITE attribute only effects for existing variable
174 if (!EFI_ERROR (FindStatus
) && ((Attributes
& EFI_VARIABLE_APPEND_WRITE
) != 0)) {
175 if ((CompareGuid (VendorGuid
, &gEfiImageSecurityDatabaseGuid
) &&
176 ((StrCmp (VariableName
, EFI_IMAGE_SECURITY_DATABASE
) == 0) || (StrCmp (VariableName
, EFI_IMAGE_SECURITY_DATABASE1
) == 0) ||
177 (StrCmp (VariableName
, EFI_IMAGE_SECURITY_DATABASE2
) == 0))) ||
178 (CompareGuid (VendorGuid
, &gEfiGlobalVariableGuid
) && (StrCmp (VariableName
, EFI_KEY_EXCHANGE_KEY_NAME
) == 0))) {
180 // For variables with formatted as EFI_SIGNATURE_LIST, the driver shall not perform an append of
181 // EFI_SIGNATURE_DATA values that are already part of the existing variable value.
183 FilterSignatureList (
192 ZeroMem (&AuthVariableInfo
, sizeof (AuthVariableInfo
));
193 AuthVariableInfo
.VariableName
= VariableName
;
194 AuthVariableInfo
.VendorGuid
= VendorGuid
;
195 AuthVariableInfo
.Data
= Data
;
196 AuthVariableInfo
.DataSize
= DataSize
;
197 AuthVariableInfo
.Attributes
= Attributes
;
198 AuthVariableInfo
.TimeStamp
= TimeStamp
;
199 return mAuthVarLibContextIn
->UpdateVariable (
205 Determine whether this operation needs a physical present user.
207 @param[in] VariableName Name of the Variable.
208 @param[in] VendorGuid GUID of the Variable.
210 @retval TRUE This variable is protected, only a physical present user could set this variable.
211 @retval FALSE This variable is not protected.
215 NeedPhysicallyPresent(
216 IN CHAR16
*VariableName
,
217 IN EFI_GUID
*VendorGuid
220 if ((CompareGuid (VendorGuid
, &gEfiSecureBootEnableDisableGuid
) && (StrCmp (VariableName
, EFI_SECURE_BOOT_ENABLE_NAME
) == 0))
221 || (CompareGuid (VendorGuid
, &gEfiCustomModeEnableGuid
) && (StrCmp (VariableName
, EFI_CUSTOM_MODE_NAME
) == 0))) {
229 Determine whether the platform is operating in Custom Secure Boot mode.
231 @retval TRUE The platform is operating in Custom mode.
232 @retval FALSE The platform is operating in Standard mode.
244 Status
= AuthServiceInternalFindVariable (EFI_CUSTOM_MODE_NAME
, &gEfiCustomModeEnableGuid
, &Data
, &DataSize
);
245 if (!EFI_ERROR (Status
) && (*(UINT8
*) Data
== CUSTOM_SECURE_BOOT_MODE
)) {
253 Update platform mode.
255 @param[in] Mode SETUP_MODE or USER_MODE.
257 @return EFI_INVALID_PARAMETER Invalid parameter.
258 @return EFI_SUCCESS Update platform mode successfully.
269 UINT8 SecureBootMode
;
270 UINT8 SecureBootEnable
;
271 UINTN VariableDataSize
;
273 Status
= AuthServiceInternalFindVariable (
275 &gEfiGlobalVariableGuid
,
279 if (EFI_ERROR (Status
)) {
284 // Update the value of SetupMode variable by a simple mem copy, this could avoid possible
285 // variable storage reclaim at runtime.
287 mPlatformMode
= (UINT8
) Mode
;
288 CopyMem (Data
, &mPlatformMode
, sizeof(UINT8
));
290 if (mAuthVarLibContextIn
->AtRuntime ()) {
292 // SecureBoot Variable indicates whether the platform firmware is operating
293 // in Secure boot mode (1) or not (0), so we should not change SecureBoot
294 // Variable in runtime.
300 // Check "SecureBoot" variable's existence.
301 // If it doesn't exist, firmware has no capability to perform driver signing verification,
302 // then set "SecureBoot" to 0.
304 Status
= AuthServiceInternalFindVariable (
305 EFI_SECURE_BOOT_MODE_NAME
,
306 &gEfiGlobalVariableGuid
,
311 // If "SecureBoot" variable exists, then check "SetupMode" variable update.
312 // If "SetupMode" variable is USER_MODE, "SecureBoot" variable is set to 1.
313 // If "SetupMode" variable is SETUP_MODE, "SecureBoot" variable is set to 0.
315 if (EFI_ERROR (Status
)) {
316 SecureBootMode
= SECURE_BOOT_MODE_DISABLE
;
318 if (mPlatformMode
== USER_MODE
) {
319 SecureBootMode
= SECURE_BOOT_MODE_ENABLE
;
320 } else if (mPlatformMode
== SETUP_MODE
) {
321 SecureBootMode
= SECURE_BOOT_MODE_DISABLE
;
323 return EFI_NOT_FOUND
;
327 Status
= AuthServiceInternalUpdateVariable (
328 EFI_SECURE_BOOT_MODE_NAME
,
329 &gEfiGlobalVariableGuid
,
332 EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
334 if (EFI_ERROR (Status
)) {
339 // Check "SecureBootEnable" variable's existence. It can enable/disable secure boot feature.
341 Status
= AuthServiceInternalFindVariable (
342 EFI_SECURE_BOOT_ENABLE_NAME
,
343 &gEfiSecureBootEnableDisableGuid
,
348 if (SecureBootMode
== SECURE_BOOT_MODE_ENABLE
) {
350 // Create the "SecureBootEnable" variable as secure boot is enabled.
352 SecureBootEnable
= SECURE_BOOT_ENABLE
;
353 VariableDataSize
= sizeof (SecureBootEnable
);
356 // Delete the "SecureBootEnable" variable if this variable exist as "SecureBoot"
357 // variable is not in secure boot state.
359 if (EFI_ERROR (Status
)) {
362 SecureBootEnable
= SECURE_BOOT_DISABLE
;
363 VariableDataSize
= 0;
366 Status
= AuthServiceInternalUpdateVariable (
367 EFI_SECURE_BOOT_ENABLE_NAME
,
368 &gEfiSecureBootEnableDisableGuid
,
371 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
377 Check input data form to make sure it is a valid EFI_SIGNATURE_LIST for PK/KEK/db/dbx/dbt variable.
379 @param[in] VariableName Name of Variable to be check.
380 @param[in] VendorGuid Variable vendor GUID.
381 @param[in] Data Point to the variable data to be checked.
382 @param[in] DataSize Size of Data.
384 @return EFI_INVALID_PARAMETER Invalid signature list format.
385 @return EFI_SUCCESS Passed signature list format check successfully.
389 CheckSignatureListFormat(
390 IN CHAR16
*VariableName
,
391 IN EFI_GUID
*VendorGuid
,
396 EFI_SIGNATURE_LIST
*SigList
;
402 EFI_SIGNATURE_DATA
*CertData
;
409 ASSERT (VariableName
!= NULL
&& VendorGuid
!= NULL
&& Data
!= NULL
);
411 if (CompareGuid (VendorGuid
, &gEfiGlobalVariableGuid
) && (StrCmp (VariableName
, EFI_PLATFORM_KEY_NAME
) == 0)){
413 } else if ((CompareGuid (VendorGuid
, &gEfiGlobalVariableGuid
) && (StrCmp (VariableName
, EFI_KEY_EXCHANGE_KEY_NAME
) == 0)) ||
414 (CompareGuid (VendorGuid
, &gEfiImageSecurityDatabaseGuid
) &&
415 ((StrCmp (VariableName
, EFI_IMAGE_SECURITY_DATABASE
) == 0) || (StrCmp (VariableName
, EFI_IMAGE_SECURITY_DATABASE1
) == 0) ||
416 (StrCmp (VariableName
, EFI_IMAGE_SECURITY_DATABASE2
) == 0)))) {
423 SigList
= (EFI_SIGNATURE_LIST
*) Data
;
424 SigDataSize
= DataSize
;
428 // Walk through the input signature list and check the data format.
429 // If any signature is incorrectly formed, the whole check will fail.
431 while ((SigDataSize
> 0) && (SigDataSize
>= SigList
->SignatureListSize
)) {
432 for (Index
= 0; Index
< (sizeof (mSupportSigItem
) / sizeof (EFI_SIGNATURE_ITEM
)); Index
++ ) {
433 if (CompareGuid (&SigList
->SignatureType
, &mSupportSigItem
[Index
].SigType
)) {
435 // The value of SignatureSize should always be 16 (size of SignatureOwner
436 // component) add the data length according to signature type.
438 if (mSupportSigItem
[Index
].SigDataSize
!= ((UINT32
) ~0) &&
439 (SigList
->SignatureSize
- sizeof (EFI_GUID
)) != mSupportSigItem
[Index
].SigDataSize
) {
440 return EFI_INVALID_PARAMETER
;
442 if (mSupportSigItem
[Index
].SigHeaderSize
!= ((UINT32
) ~0) &&
443 SigList
->SignatureHeaderSize
!= mSupportSigItem
[Index
].SigHeaderSize
) {
444 return EFI_INVALID_PARAMETER
;
450 if (Index
== (sizeof (mSupportSigItem
) / sizeof (EFI_SIGNATURE_ITEM
))) {
452 // Undefined signature type.
454 return EFI_INVALID_PARAMETER
;
457 if (CompareGuid (&SigList
->SignatureType
, &gEfiCertX509Guid
)) {
459 // Try to retrieve the RSA public key from the X.509 certificate.
460 // If this operation fails, it's not a valid certificate.
462 RsaContext
= RsaNew ();
463 if (RsaContext
== NULL
) {
464 return EFI_INVALID_PARAMETER
;
466 CertData
= (EFI_SIGNATURE_DATA
*) ((UINT8
*) SigList
+ sizeof (EFI_SIGNATURE_LIST
) + SigList
->SignatureHeaderSize
);
467 CertLen
= SigList
->SignatureSize
- sizeof (EFI_GUID
);
468 if (!RsaGetPublicKeyFromX509 (CertData
->SignatureData
, CertLen
, &RsaContext
)) {
469 RsaFree (RsaContext
);
470 return EFI_INVALID_PARAMETER
;
472 RsaFree (RsaContext
);
475 if ((SigList
->SignatureListSize
- sizeof (EFI_SIGNATURE_LIST
) - SigList
->SignatureHeaderSize
) % SigList
->SignatureSize
!= 0) {
476 return EFI_INVALID_PARAMETER
;
478 SigCount
+= (SigList
->SignatureListSize
- sizeof (EFI_SIGNATURE_LIST
) - SigList
->SignatureHeaderSize
) / SigList
->SignatureSize
;
480 SigDataSize
-= SigList
->SignatureListSize
;
481 SigList
= (EFI_SIGNATURE_LIST
*) ((UINT8
*) SigList
+ SigList
->SignatureListSize
);
484 if (((UINTN
) SigList
- (UINTN
) Data
) != DataSize
) {
485 return EFI_INVALID_PARAMETER
;
488 if (IsPk
&& SigCount
> 1) {
489 return EFI_INVALID_PARAMETER
;
496 Update "VendorKeys" variable to record the out of band secure boot key modification.
498 @return EFI_SUCCESS Variable is updated successfully.
499 @return Others Failed to update variable.
503 VendorKeyIsModified (
509 if (mVendorKeyState
== VENDOR_KEYS_MODIFIED
) {
512 mVendorKeyState
= VENDOR_KEYS_MODIFIED
;
514 Status
= AuthServiceInternalUpdateVariable (
515 EFI_VENDOR_KEYS_NV_VARIABLE_NAME
,
516 &gEfiVendorKeysNvGuid
,
519 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
521 if (EFI_ERROR (Status
)) {
525 return AuthServiceInternalUpdateVariable (
526 EFI_VENDOR_KEYS_VARIABLE_NAME
,
527 &gEfiGlobalVariableGuid
,
530 EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
535 Process variable with platform key for verification.
537 Caution: This function may receive untrusted input.
538 This function may be invoked in SMM mode, and datasize and data are external input.
539 This function will do basic validation, before parse the data.
540 This function will parse the authentication carefully to avoid security issues, like
541 buffer overflow, integer overflow.
542 This function will check attribute carefully to avoid authentication bypass.
544 @param[in] VariableName Name of Variable to be found.
545 @param[in] VendorGuid Variable vendor GUID.
546 @param[in] Data Data pointer.
547 @param[in] DataSize Size of Data found. If size is less than the
548 data, this value contains the required size.
549 @param[in] Attributes Attribute value of the variable
550 @param[in] IsPk Indicate whether it is to process pk.
552 @return EFI_INVALID_PARAMETER Invalid parameter.
553 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation.
554 check carried out by the firmware.
555 @return EFI_SUCCESS Variable passed validation successfully.
560 IN CHAR16
*VariableName
,
561 IN EFI_GUID
*VendorGuid
,
564 IN UINT32 Attributes OPTIONAL
,
573 if ((Attributes
& EFI_VARIABLE_NON_VOLATILE
) == 0 ||
574 (Attributes
& EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
) == 0) {
576 // PK, KEK and db/dbx/dbt should set EFI_VARIABLE_NON_VOLATILE attribute and should be a time-based
577 // authenticated variable.
579 return EFI_INVALID_PARAMETER
;
583 // Init state of Del. State may change due to secure check
586 if ((InCustomMode() && UserPhysicalPresent()) || (mPlatformMode
== SETUP_MODE
&& !IsPk
)) {
587 Payload
= (UINT8
*) Data
+ AUTHINFO2_SIZE (Data
);
588 PayloadSize
= DataSize
- AUTHINFO2_SIZE (Data
);
589 if (PayloadSize
== 0) {
593 Status
= CheckSignatureListFormat(VariableName
, VendorGuid
, Payload
, PayloadSize
);
594 if (EFI_ERROR (Status
)) {
598 Status
= AuthServiceInternalUpdateVariableWithTimeStamp (
604 &((EFI_VARIABLE_AUTHENTICATION_2
*) Data
)->TimeStamp
606 if (EFI_ERROR(Status
)) {
610 if ((mPlatformMode
!= SETUP_MODE
) || IsPk
) {
611 Status
= VendorKeyIsModified ();
613 } else if (mPlatformMode
== USER_MODE
) {
615 // Verify against X509 Cert in PK database.
617 Status
= VerifyTimeBasedPayloadAndUpdate (
628 // Verify against the certificate in data payload.
630 Status
= VerifyTimeBasedPayloadAndUpdate (
641 if (!EFI_ERROR(Status
) && IsPk
) {
642 if (mPlatformMode
== SETUP_MODE
&& !Del
) {
644 // If enroll PK in setup mode, need change to user mode.
646 Status
= UpdatePlatformMode (USER_MODE
);
647 } else if (mPlatformMode
== USER_MODE
&& Del
){
649 // If delete PK in user mode, need change to setup mode.
651 Status
= UpdatePlatformMode (SETUP_MODE
);
659 Process variable with key exchange key for verification.
661 Caution: This function may receive untrusted input.
662 This function may be invoked in SMM mode, and datasize and data are external input.
663 This function will do basic validation, before parse the data.
664 This function will parse the authentication carefully to avoid security issues, like
665 buffer overflow, integer overflow.
666 This function will check attribute carefully to avoid authentication bypass.
668 @param[in] VariableName Name of Variable to be found.
669 @param[in] VendorGuid Variable vendor GUID.
670 @param[in] Data Data pointer.
671 @param[in] DataSize Size of Data found. If size is less than the
672 data, this value contains the required size.
673 @param[in] Attributes Attribute value of the variable.
675 @return EFI_INVALID_PARAMETER Invalid parameter.
676 @return EFI_SECURITY_VIOLATION The variable does NOT pass the validation
677 check carried out by the firmware.
678 @return EFI_SUCCESS Variable pass validation successfully.
683 IN CHAR16
*VariableName
,
684 IN EFI_GUID
*VendorGuid
,
687 IN UINT32 Attributes OPTIONAL
694 if ((Attributes
& EFI_VARIABLE_NON_VOLATILE
) == 0 ||
695 (Attributes
& EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
) == 0) {
697 // DB, DBX and DBT should set EFI_VARIABLE_NON_VOLATILE attribute and should be a time-based
698 // authenticated variable.
700 return EFI_INVALID_PARAMETER
;
703 Status
= EFI_SUCCESS
;
704 if (mPlatformMode
== USER_MODE
&& !(InCustomMode() && UserPhysicalPresent())) {
706 // Time-based, verify against X509 Cert KEK.
708 return VerifyTimeBasedPayloadAndUpdate (
719 // If in setup mode or custom secure boot mode, no authentication needed.
721 Payload
= (UINT8
*) Data
+ AUTHINFO2_SIZE (Data
);
722 PayloadSize
= DataSize
- AUTHINFO2_SIZE (Data
);
724 Status
= CheckSignatureListFormat(VariableName
, VendorGuid
, Payload
, PayloadSize
);
725 if (EFI_ERROR (Status
)) {
729 Status
= AuthServiceInternalUpdateVariableWithTimeStamp (
735 &((EFI_VARIABLE_AUTHENTICATION_2
*) Data
)->TimeStamp
737 if (EFI_ERROR (Status
)) {
741 if (mPlatformMode
!= SETUP_MODE
) {
742 Status
= VendorKeyIsModified ();
750 Check if it is to delete auth variable.
752 @param[in] OrgAttributes Original attribute value of the variable.
753 @param[in] Data Data pointer.
754 @param[in] DataSize Size of Data.
755 @param[in] Attributes Attribute value of the variable.
757 @retval TRUE It is to delete auth variable.
758 @retval FALSE It is not to delete auth variable.
762 IsDeleteAuthVariable (
763 IN UINT32 OrgAttributes
,
775 // To delete a variable created with the EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
776 // or the EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute,
777 // SetVariable must be used with attributes matching the existing variable
778 // and the DataSize set to the size of the AuthInfo descriptor.
780 if ((Attributes
== OrgAttributes
) &&
781 ((Attributes
& (EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
| EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
)) != 0)) {
782 if ((Attributes
& EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
) != 0) {
783 PayloadSize
= DataSize
- AUTHINFO2_SIZE (Data
);
784 if (PayloadSize
== 0) {
788 PayloadSize
= DataSize
- AUTHINFO_SIZE
;
789 if (PayloadSize
== 0) {
799 Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
801 Caution: This function may receive untrusted input.
802 This function may be invoked in SMM mode, and datasize and data are external input.
803 This function will do basic validation, before parse the data.
804 This function will parse the authentication carefully to avoid security issues, like
805 buffer overflow, integer overflow.
806 This function will check attribute carefully to avoid authentication bypass.
808 @param[in] VariableName Name of the variable.
809 @param[in] VendorGuid Variable vendor GUID.
810 @param[in] Data Data pointer.
811 @param[in] DataSize Size of Data.
812 @param[in] Attributes Attribute value of the variable.
814 @return EFI_INVALID_PARAMETER Invalid parameter.
815 @return EFI_WRITE_PROTECTED Variable is write-protected and needs authentication with
816 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set.
817 @return EFI_OUT_OF_RESOURCES The Database to save the public key is full.
818 @return EFI_SECURITY_VIOLATION The variable is with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
819 set, but the AuthInfo does NOT pass the validation
820 check carried out by the firmware.
821 @return EFI_SUCCESS Variable is not write-protected or pass validation successfully.
826 IN CHAR16
*VariableName
,
827 IN EFI_GUID
*VendorGuid
,
834 AUTH_VARIABLE_INFO OrgVariableInfo
;
836 Status
= EFI_SUCCESS
;
838 ZeroMem (&OrgVariableInfo
, sizeof (OrgVariableInfo
));
839 Status
= mAuthVarLibContextIn
->FindVariable (
845 if ((!EFI_ERROR (Status
)) && IsDeleteAuthVariable (OrgVariableInfo
.Attributes
, Data
, DataSize
, Attributes
) && UserPhysicalPresent()) {
847 // Allow the delete operation of common authenticated variable(AT or AW) at user physical presence.
849 Status
= AuthServiceInternalUpdateVariable (
856 if (!EFI_ERROR (Status
) && ((Attributes
& EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
) != 0)) {
857 Status
= DeleteCertsFromDb (VariableName
, VendorGuid
, Attributes
);
863 if (NeedPhysicallyPresent (VariableName
, VendorGuid
) && !UserPhysicalPresent()) {
865 // This variable is protected, only physical present user could modify its value.
867 return EFI_SECURITY_VIOLATION
;
871 if ((Attributes
& EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
) != 0) {
873 // Reject Counter Based Auth Variable processing request.
875 return EFI_UNSUPPORTED
;
876 } else if ((Attributes
& EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
) != 0) {
878 // Process Time-based Authenticated variable.
880 return VerifyTimeBasedPayloadAndUpdate (
891 if ((OrgVariableInfo
.Data
!= NULL
) &&
892 ((OrgVariableInfo
.Attributes
& (EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
| EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
)) != 0)) {
894 // If the variable is already write-protected, it always needs authentication before update.
896 return EFI_WRITE_PROTECTED
;
900 // Not authenticated variable, just update variable as usual.
902 Status
= AuthServiceInternalUpdateVariable (VariableName
, VendorGuid
, Data
, DataSize
, Attributes
);
908 Filter out the duplicated EFI_SIGNATURE_DATA from the new data by comparing to the original data.
910 @param[in] Data Pointer to original EFI_SIGNATURE_LIST.
911 @param[in] DataSize Size of Data buffer.
912 @param[in, out] NewData Pointer to new EFI_SIGNATURE_LIST.
913 @param[in, out] NewDataSize Size of NewData buffer.
917 FilterSignatureList (
920 IN OUT VOID
*NewData
,
921 IN OUT UINTN
*NewDataSize
924 EFI_SIGNATURE_LIST
*CertList
;
925 EFI_SIGNATURE_DATA
*Cert
;
927 EFI_SIGNATURE_LIST
*NewCertList
;
928 EFI_SIGNATURE_DATA
*NewCert
;
935 UINTN SignatureListSize
;
941 if (*NewDataSize
== 0) {
945 TempDataSize
= *NewDataSize
;
946 Status
= mAuthVarLibContextIn
->GetScratchBuffer (&TempDataSize
, (VOID
**) &TempData
);
947 if (EFI_ERROR (Status
)) {
948 return EFI_OUT_OF_RESOURCES
;
953 NewCertList
= (EFI_SIGNATURE_LIST
*) NewData
;
954 while ((*NewDataSize
> 0) && (*NewDataSize
>= NewCertList
->SignatureListSize
)) {
955 NewCert
= (EFI_SIGNATURE_DATA
*) ((UINT8
*) NewCertList
+ sizeof (EFI_SIGNATURE_LIST
) + NewCertList
->SignatureHeaderSize
);
956 NewCertCount
= (NewCertList
->SignatureListSize
- sizeof (EFI_SIGNATURE_LIST
) - NewCertList
->SignatureHeaderSize
) / NewCertList
->SignatureSize
;
959 for (Index
= 0; Index
< NewCertCount
; Index
++) {
963 CertList
= (EFI_SIGNATURE_LIST
*) Data
;
964 while ((Size
> 0) && (Size
>= CertList
->SignatureListSize
)) {
965 if (CompareGuid (&CertList
->SignatureType
, &NewCertList
->SignatureType
) &&
966 (CertList
->SignatureSize
== NewCertList
->SignatureSize
)) {
967 Cert
= (EFI_SIGNATURE_DATA
*) ((UINT8
*) CertList
+ sizeof (EFI_SIGNATURE_LIST
) + CertList
->SignatureHeaderSize
);
968 CertCount
= (CertList
->SignatureListSize
- sizeof (EFI_SIGNATURE_LIST
) - CertList
->SignatureHeaderSize
) / CertList
->SignatureSize
;
969 for (Index2
= 0; Index2
< CertCount
; Index2
++) {
971 // Iterate each Signature Data in this Signature List.
973 if (CompareMem (NewCert
, Cert
, CertList
->SignatureSize
) == 0) {
977 Cert
= (EFI_SIGNATURE_DATA
*) ((UINT8
*) Cert
+ CertList
->SignatureSize
);
984 Size
-= CertList
->SignatureListSize
;
985 CertList
= (EFI_SIGNATURE_LIST
*) ((UINT8
*) CertList
+ CertList
->SignatureListSize
);
990 // New EFI_SIGNATURE_DATA, keep it.
992 if (CopiedCount
== 0) {
994 // Copy EFI_SIGNATURE_LIST header for only once.
996 CopyMem (Tail
, NewCertList
, sizeof (EFI_SIGNATURE_LIST
) + NewCertList
->SignatureHeaderSize
);
997 Tail
= Tail
+ sizeof (EFI_SIGNATURE_LIST
) + NewCertList
->SignatureHeaderSize
;
1000 CopyMem (Tail
, NewCert
, NewCertList
->SignatureSize
);
1001 Tail
+= NewCertList
->SignatureSize
;
1005 NewCert
= (EFI_SIGNATURE_DATA
*) ((UINT8
*) NewCert
+ NewCertList
->SignatureSize
);
1009 // Update SignatureListSize in the kept EFI_SIGNATURE_LIST.
1011 if (CopiedCount
!= 0) {
1012 SignatureListSize
= sizeof (EFI_SIGNATURE_LIST
) + NewCertList
->SignatureHeaderSize
+ (CopiedCount
* NewCertList
->SignatureSize
);
1013 CertList
= (EFI_SIGNATURE_LIST
*) (Tail
- SignatureListSize
);
1014 CertList
->SignatureListSize
= (UINT32
) SignatureListSize
;
1017 *NewDataSize
-= NewCertList
->SignatureListSize
;
1018 NewCertList
= (EFI_SIGNATURE_LIST
*) ((UINT8
*) NewCertList
+ NewCertList
->SignatureListSize
);
1021 TempDataSize
= (Tail
- (UINT8
*) TempData
);
1023 CopyMem (NewData
, TempData
, TempDataSize
);
1024 *NewDataSize
= TempDataSize
;
1030 Compare two EFI_TIME data.
1033 @param FirstTime A pointer to the first EFI_TIME data.
1034 @param SecondTime A pointer to the second EFI_TIME data.
1036 @retval TRUE The FirstTime is not later than the SecondTime.
1037 @retval FALSE The FirstTime is later than the SecondTime.
1041 AuthServiceInternalCompareTimeStamp (
1042 IN EFI_TIME
*FirstTime
,
1043 IN EFI_TIME
*SecondTime
1046 if (FirstTime
->Year
!= SecondTime
->Year
) {
1047 return (BOOLEAN
) (FirstTime
->Year
< SecondTime
->Year
);
1048 } else if (FirstTime
->Month
!= SecondTime
->Month
) {
1049 return (BOOLEAN
) (FirstTime
->Month
< SecondTime
->Month
);
1050 } else if (FirstTime
->Day
!= SecondTime
->Day
) {
1051 return (BOOLEAN
) (FirstTime
->Day
< SecondTime
->Day
);
1052 } else if (FirstTime
->Hour
!= SecondTime
->Hour
) {
1053 return (BOOLEAN
) (FirstTime
->Hour
< SecondTime
->Hour
);
1054 } else if (FirstTime
->Minute
!= SecondTime
->Minute
) {
1055 return (BOOLEAN
) (FirstTime
->Minute
< SecondTime
->Minute
);
1058 return (BOOLEAN
) (FirstTime
->Second
<= SecondTime
->Second
);
1062 Calculate SHA256 digest of SignerCert CommonName + ToplevelCert tbsCertificate
1063 SignerCert and ToplevelCert are inside the signer certificate chain.
1065 @param[in] SignerCert A pointer to SignerCert data.
1066 @param[in] SignerCertSize Length of SignerCert data.
1067 @param[in] TopLevelCert A pointer to TopLevelCert data.
1068 @param[in] TopLevelCertSize Length of TopLevelCert data.
1069 @param[out] Sha256Digest Sha256 digest calculated.
1071 @return EFI_ABORTED Digest process failed.
1072 @return EFI_SUCCESS SHA256 Digest is successfully calculated.
1076 CalculatePrivAuthVarSignChainSHA256Digest(
1077 IN UINT8
*SignerCert
,
1078 IN UINTN SignerCertSize
,
1079 IN UINT8
*TopLevelCert
,
1080 IN UINTN TopLevelCertSize
,
1081 OUT UINT8
*Sha256Digest
1086 CHAR8 CertCommonName
[128];
1087 UINTN CertCommonNameSize
;
1088 BOOLEAN CryptoStatus
;
1091 CertCommonNameSize
= sizeof(CertCommonName
);
1094 // Get SignerCert CommonName
1096 Status
= X509GetCommonName(SignerCert
, SignerCertSize
, CertCommonName
, &CertCommonNameSize
);
1097 if (EFI_ERROR(Status
)) {
1098 DEBUG((DEBUG_INFO
, "%a Get SignerCert CommonName failed with status %x\n", __FUNCTION__
, Status
));
1103 // Get TopLevelCert tbsCertificate
1105 if (!X509GetTBSCert(TopLevelCert
, TopLevelCertSize
, &TbsCert
, &TbsCertSize
)) {
1106 DEBUG((DEBUG_INFO
, "%a Get Top-level Cert tbsCertificate failed!\n", __FUNCTION__
));
1111 // Digest SignerCert CN + TopLevelCert tbsCertificate
1113 ZeroMem (Sha256Digest
, SHA256_DIGEST_SIZE
);
1114 CryptoStatus
= Sha256Init (mHashCtx
);
1115 if (!CryptoStatus
) {
1120 // '\0' is forced in CertCommonName. No overflow issue
1122 CryptoStatus
= Sha256Update (
1125 AsciiStrLen (CertCommonName
)
1127 if (!CryptoStatus
) {
1131 CryptoStatus
= Sha256Update (mHashCtx
, TbsCert
, TbsCertSize
);
1132 if (!CryptoStatus
) {
1136 CryptoStatus
= Sha256Final (mHashCtx
, Sha256Digest
);
1137 if (!CryptoStatus
) {
1145 Find matching signer's certificates for common authenticated variable
1146 by corresponding VariableName and VendorGuid from "certdb" or "certdbv".
1148 The data format of "certdb" or "certdbv":
1150 // UINT32 CertDbListSize;
1151 // /// AUTH_CERT_DB_DATA Certs1[];
1152 // /// AUTH_CERT_DB_DATA Certs2[];
1154 // /// AUTH_CERT_DB_DATA Certsn[];
1157 @param[in] VariableName Name of authenticated Variable.
1158 @param[in] VendorGuid Vendor GUID of authenticated Variable.
1159 @param[in] Data Pointer to variable "certdb" or "certdbv".
1160 @param[in] DataSize Size of variable "certdb" or "certdbv".
1161 @param[out] CertOffset Offset of matching CertData, from starting of Data.
1162 @param[out] CertDataSize Length of CertData in bytes.
1163 @param[out] CertNodeOffset Offset of matching AUTH_CERT_DB_DATA , from
1165 @param[out] CertNodeSize Length of AUTH_CERT_DB_DATA in bytes.
1167 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
1168 @retval EFI_NOT_FOUND Fail to find matching certs.
1169 @retval EFI_SUCCESS Find matching certs and output parameters.
1174 IN CHAR16
*VariableName
,
1175 IN EFI_GUID
*VendorGuid
,
1178 OUT UINT32
*CertOffset
, OPTIONAL
1179 OUT UINT32
*CertDataSize
, OPTIONAL
1180 OUT UINT32
*CertNodeOffset
,OPTIONAL
1181 OUT UINT32
*CertNodeSize OPTIONAL
1185 AUTH_CERT_DB_DATA
*Ptr
;
1189 UINT32 CertDbListSize
;
1191 if ((VariableName
== NULL
) || (VendorGuid
== NULL
) || (Data
== NULL
)) {
1192 return EFI_INVALID_PARAMETER
;
1196 // Check whether DataSize matches recorded CertDbListSize.
1198 if (DataSize
< sizeof (UINT32
)) {
1199 return EFI_INVALID_PARAMETER
;
1202 CertDbListSize
= ReadUnaligned32 ((UINT32
*) Data
);
1204 if (CertDbListSize
!= (UINT32
) DataSize
) {
1205 return EFI_INVALID_PARAMETER
;
1208 Offset
= sizeof (UINT32
);
1211 // Get corresponding certificates by VendorGuid and VariableName.
1213 while (Offset
< (UINT32
) DataSize
) {
1214 Ptr
= (AUTH_CERT_DB_DATA
*) (Data
+ Offset
);
1216 // Check whether VendorGuid matches.
1218 if (CompareGuid (&Ptr
->VendorGuid
, VendorGuid
)) {
1219 NodeSize
= ReadUnaligned32 (&Ptr
->CertNodeSize
);
1220 NameSize
= ReadUnaligned32 (&Ptr
->NameSize
);
1221 CertSize
= ReadUnaligned32 (&Ptr
->CertDataSize
);
1223 if (NodeSize
!= sizeof (EFI_GUID
) + sizeof (UINT32
) * 3 + CertSize
+
1224 sizeof (CHAR16
) * NameSize
) {
1225 return EFI_INVALID_PARAMETER
;
1228 Offset
= Offset
+ sizeof (EFI_GUID
) + sizeof (UINT32
) * 3;
1230 // Check whether VariableName matches.
1232 if ((NameSize
== StrLen (VariableName
)) &&
1233 (CompareMem (Data
+ Offset
, VariableName
, NameSize
* sizeof (CHAR16
)) == 0)) {
1234 Offset
= Offset
+ NameSize
* sizeof (CHAR16
);
1236 if (CertOffset
!= NULL
) {
1237 *CertOffset
= Offset
;
1240 if (CertDataSize
!= NULL
) {
1241 *CertDataSize
= CertSize
;
1244 if (CertNodeOffset
!= NULL
) {
1245 *CertNodeOffset
= (UINT32
) ((UINT8
*) Ptr
- Data
);
1248 if (CertNodeSize
!= NULL
) {
1249 *CertNodeSize
= NodeSize
;
1254 Offset
= Offset
+ NameSize
* sizeof (CHAR16
) + CertSize
;
1257 NodeSize
= ReadUnaligned32 (&Ptr
->CertNodeSize
);
1258 Offset
= Offset
+ NodeSize
;
1262 return EFI_NOT_FOUND
;
1266 Retrieve signer's certificates for common authenticated variable
1267 by corresponding VariableName and VendorGuid from "certdb"
1268 or "certdbv" according to authenticated variable attributes.
1270 @param[in] VariableName Name of authenticated Variable.
1271 @param[in] VendorGuid Vendor GUID of authenticated Variable.
1272 @param[in] Attributes Attributes of authenticated variable.
1273 @param[out] CertData Pointer to signer's certificates.
1274 @param[out] CertDataSize Length of CertData in bytes.
1276 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
1277 @retval EFI_NOT_FOUND Fail to find "certdb"/"certdbv" or matching certs.
1278 @retval EFI_SUCCESS Get signer's certificates successfully.
1283 IN CHAR16
*VariableName
,
1284 IN EFI_GUID
*VendorGuid
,
1285 IN UINT32 Attributes
,
1286 OUT UINT8
**CertData
,
1287 OUT UINT32
*CertDataSize
1296 if ((VariableName
== NULL
) || (VendorGuid
== NULL
) || (CertData
== NULL
) || (CertDataSize
== NULL
)) {
1297 return EFI_INVALID_PARAMETER
;
1301 if ((Attributes
& EFI_VARIABLE_NON_VOLATILE
) != 0) {
1303 // Get variable "certdb".
1305 DbName
= EFI_CERT_DB_NAME
;
1308 // Get variable "certdbv".
1310 DbName
= EFI_CERT_DB_VOLATILE_NAME
;
1314 // Get variable "certdb" or "certdbv".
1316 Status
= AuthServiceInternalFindVariable (
1322 if (EFI_ERROR (Status
)) {
1326 if ((DataSize
== 0) || (Data
== NULL
)) {
1328 return EFI_NOT_FOUND
;
1331 Status
= FindCertsFromDb (
1342 if (EFI_ERROR (Status
)) {
1346 *CertData
= Data
+ CertOffset
;
1351 Delete matching signer's certificates when deleting common authenticated
1352 variable by corresponding VariableName and VendorGuid from "certdb" or
1353 "certdbv" according to authenticated variable attributes.
1355 @param[in] VariableName Name of authenticated Variable.
1356 @param[in] VendorGuid Vendor GUID of authenticated Variable.
1357 @param[in] Attributes Attributes of authenticated variable.
1359 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
1360 @retval EFI_NOT_FOUND Fail to find "certdb"/"certdbv" or matching certs.
1361 @retval EFI_OUT_OF_RESOURCES The operation is failed due to lack of resources.
1362 @retval EFI_SUCCESS The operation is completed successfully.
1367 IN CHAR16
*VariableName
,
1368 IN EFI_GUID
*VendorGuid
,
1369 IN UINT32 Attributes
1376 UINT32 CertNodeOffset
;
1377 UINT32 CertNodeSize
;
1379 UINT32 NewCertDbSize
;
1382 if ((VariableName
== NULL
) || (VendorGuid
== NULL
)) {
1383 return EFI_INVALID_PARAMETER
;
1386 if ((Attributes
& EFI_VARIABLE_NON_VOLATILE
) != 0) {
1388 // Get variable "certdb".
1390 DbName
= EFI_CERT_DB_NAME
;
1391 VarAttr
= EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
;
1394 // Get variable "certdbv".
1396 DbName
= EFI_CERT_DB_VOLATILE_NAME
;
1397 VarAttr
= EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
;
1400 Status
= AuthServiceInternalFindVariable (
1407 if (EFI_ERROR (Status
)) {
1411 if ((DataSize
== 0) || (Data
== NULL
)) {
1413 return EFI_NOT_FOUND
;
1416 if (DataSize
== sizeof (UINT32
)) {
1418 // There is no certs in "certdb" or "certdbv".
1424 // Get corresponding cert node from "certdb" or "certdbv".
1426 Status
= FindCertsFromDb (
1437 if (EFI_ERROR (Status
)) {
1441 if (DataSize
< (CertNodeOffset
+ CertNodeSize
)) {
1442 return EFI_NOT_FOUND
;
1446 // Construct new data content of variable "certdb" or "certdbv".
1448 NewCertDbSize
= (UINT32
) DataSize
- CertNodeSize
;
1449 NewCertDb
= (UINT8
*) mCertDbStore
;
1452 // Copy the DB entries before deleting node.
1454 CopyMem (NewCertDb
, Data
, CertNodeOffset
);
1456 // Update CertDbListSize.
1458 CopyMem (NewCertDb
, &NewCertDbSize
, sizeof (UINT32
));
1460 // Copy the DB entries after deleting node.
1462 if (DataSize
> (CertNodeOffset
+ CertNodeSize
)) {
1464 NewCertDb
+ CertNodeOffset
,
1465 Data
+ CertNodeOffset
+ CertNodeSize
,
1466 DataSize
- CertNodeOffset
- CertNodeSize
1471 // Set "certdb" or "certdbv".
1473 Status
= AuthServiceInternalUpdateVariable (
1485 Insert signer's certificates for common authenticated variable with VariableName
1486 and VendorGuid in AUTH_CERT_DB_DATA to "certdb" or "certdbv" according to
1487 time based authenticated variable attributes. CertData is the SHA256 digest of
1488 SignerCert CommonName + TopLevelCert tbsCertificate.
1490 @param[in] VariableName Name of authenticated Variable.
1491 @param[in] VendorGuid Vendor GUID of authenticated Variable.
1492 @param[in] Attributes Attributes of authenticated variable.
1493 @param[in] SignerCert Signer certificate data.
1494 @param[in] SignerCertSize Length of signer certificate.
1495 @param[in] TopLevelCert Top-level certificate data.
1496 @param[in] TopLevelCertSize Length of top-level certificate.
1498 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
1499 @retval EFI_ACCESS_DENIED An AUTH_CERT_DB_DATA entry with same VariableName
1500 and VendorGuid already exists.
1501 @retval EFI_OUT_OF_RESOURCES The operation is failed due to lack of resources.
1502 @retval EFI_SUCCESS Insert an AUTH_CERT_DB_DATA entry to "certdb" or "certdbv"
1507 IN CHAR16
*VariableName
,
1508 IN EFI_GUID
*VendorGuid
,
1509 IN UINT32 Attributes
,
1510 IN UINT8
*SignerCert
,
1511 IN UINTN SignerCertSize
,
1512 IN UINT8
*TopLevelCert
,
1513 IN UINTN TopLevelCertSize
1521 UINT32 NewCertDbSize
;
1522 UINT32 CertNodeSize
;
1524 UINT32 CertDataSize
;
1525 AUTH_CERT_DB_DATA
*Ptr
;
1527 UINT8 Sha256Digest
[SHA256_DIGEST_SIZE
];
1529 if ((VariableName
== NULL
) || (VendorGuid
== NULL
) || (SignerCert
== NULL
) ||(TopLevelCert
== NULL
)) {
1530 return EFI_INVALID_PARAMETER
;
1533 if ((Attributes
& EFI_VARIABLE_NON_VOLATILE
) != 0) {
1535 // Get variable "certdb".
1537 DbName
= EFI_CERT_DB_NAME
;
1538 VarAttr
= EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
;
1541 // Get variable "certdbv".
1543 DbName
= EFI_CERT_DB_VOLATILE_NAME
;
1544 VarAttr
= EFI_VARIABLE_RUNTIME_ACCESS
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
;
1548 // Get variable "certdb" or "certdbv".
1550 Status
= AuthServiceInternalFindVariable (
1556 if (EFI_ERROR (Status
)) {
1560 if ((DataSize
== 0) || (Data
== NULL
)) {
1562 return EFI_NOT_FOUND
;
1566 // Find whether matching cert node already exists in "certdb" or "certdbv".
1567 // If yes return error.
1569 Status
= FindCertsFromDb (
1580 if (!EFI_ERROR (Status
)) {
1582 return EFI_ACCESS_DENIED
;
1586 // Construct new data content of variable "certdb" or "certdbv".
1588 NameSize
= (UINT32
) StrLen (VariableName
);
1589 CertDataSize
= sizeof(Sha256Digest
);
1590 CertNodeSize
= sizeof (AUTH_CERT_DB_DATA
) + (UINT32
) CertDataSize
+ NameSize
* sizeof (CHAR16
);
1591 NewCertDbSize
= (UINT32
) DataSize
+ CertNodeSize
;
1592 if (NewCertDbSize
> mMaxCertDbSize
) {
1593 return EFI_OUT_OF_RESOURCES
;
1596 Status
= CalculatePrivAuthVarSignChainSHA256Digest(
1603 if (EFI_ERROR (Status
)) {
1607 NewCertDb
= (UINT8
*) mCertDbStore
;
1610 // Copy the DB entries before inserting node.
1612 CopyMem (NewCertDb
, Data
, DataSize
);
1614 // Update CertDbListSize.
1616 CopyMem (NewCertDb
, &NewCertDbSize
, sizeof (UINT32
));
1618 // Construct new cert node.
1620 Ptr
= (AUTH_CERT_DB_DATA
*) (NewCertDb
+ DataSize
);
1621 CopyGuid (&Ptr
->VendorGuid
, VendorGuid
);
1622 CopyMem (&Ptr
->CertNodeSize
, &CertNodeSize
, sizeof (UINT32
));
1623 CopyMem (&Ptr
->NameSize
, &NameSize
, sizeof (UINT32
));
1624 CopyMem (&Ptr
->CertDataSize
, &CertDataSize
, sizeof (UINT32
));
1627 (UINT8
*) Ptr
+ sizeof (AUTH_CERT_DB_DATA
),
1629 NameSize
* sizeof (CHAR16
)
1633 (UINT8
*) Ptr
+ sizeof (AUTH_CERT_DB_DATA
) + NameSize
* sizeof (CHAR16
),
1639 // Set "certdb" or "certdbv".
1641 Status
= AuthServiceInternalUpdateVariable (
1653 Clean up signer's certificates for common authenticated variable
1654 by corresponding VariableName and VendorGuid from "certdb".
1655 System may break down during Timebased Variable update & certdb update,
1656 make them inconsistent, this function is called in AuthVariable Init
1657 to ensure consistency.
1659 @retval EFI_NOT_FOUND Fail to find variable "certdb".
1660 @retval EFI_OUT_OF_RESOURCES The operation is failed due to lack of resources.
1661 @retval EFI_SUCCESS The operation is completed successfully.
1670 AUTH_CERT_DB_DATA
*Ptr
;
1673 CHAR16
*VariableName
;
1675 BOOLEAN CertCleaned
;
1678 EFI_GUID AuthVarGuid
;
1679 AUTH_VARIABLE_INFO AuthVariableInfo
;
1681 Status
= EFI_SUCCESS
;
1684 // Get corresponding certificates by VendorGuid and VariableName.
1687 CertCleaned
= FALSE
;
1690 // Get latest variable "certdb"
1692 Status
= AuthServiceInternalFindVariable (
1698 if (EFI_ERROR (Status
)) {
1702 if ((DataSize
== 0) || (Data
== NULL
)) {
1704 return EFI_NOT_FOUND
;
1707 Offset
= sizeof (UINT32
);
1709 while (Offset
< (UINT32
) DataSize
) {
1710 Ptr
= (AUTH_CERT_DB_DATA
*) (Data
+ Offset
);
1711 NodeSize
= ReadUnaligned32 (&Ptr
->CertNodeSize
);
1712 NameSize
= ReadUnaligned32 (&Ptr
->NameSize
);
1715 // Get VarName tailed with '\0'
1717 VariableName
= AllocateZeroPool((NameSize
+ 1) * sizeof(CHAR16
));
1718 if (VariableName
== NULL
) {
1719 return EFI_OUT_OF_RESOURCES
;
1721 CopyMem (VariableName
, (UINT8
*) Ptr
+ sizeof (AUTH_CERT_DB_DATA
), NameSize
* sizeof(CHAR16
));
1723 // Keep VarGuid aligned
1725 CopyMem (&AuthVarGuid
, &Ptr
->VendorGuid
, sizeof(EFI_GUID
));
1728 // Find corresponding time auth variable
1730 ZeroMem (&AuthVariableInfo
, sizeof (AuthVariableInfo
));
1731 Status
= mAuthVarLibContextIn
->FindVariable (
1737 if (EFI_ERROR(Status
) || (AuthVariableInfo
.Attributes
& EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
) == 0) {
1739 // While cleaning certdb, always delete the variable in certdb regardless of it attributes.
1741 Status
= DeleteCertsFromDb(
1744 AuthVariableInfo
.Attributes
| EFI_VARIABLE_NON_VOLATILE
1747 DEBUG((EFI_D_INFO
, "Recovery!! Cert for Auth Variable %s Guid %g is removed for consistency\n", VariableName
, &AuthVarGuid
));
1748 FreePool(VariableName
);
1752 FreePool(VariableName
);
1753 Offset
= Offset
+ NodeSize
;
1755 } while (CertCleaned
);
1761 Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
1763 Caution: This function may receive untrusted input.
1764 This function may be invoked in SMM mode, and datasize and data are external input.
1765 This function will do basic validation, before parse the data.
1766 This function will parse the authentication carefully to avoid security issues, like
1767 buffer overflow, integer overflow.
1769 @param[in] VariableName Name of Variable to be found.
1770 @param[in] VendorGuid Variable vendor GUID.
1771 @param[in] Data Data pointer.
1772 @param[in] DataSize Size of Data found. If size is less than the
1773 data, this value contains the required size.
1774 @param[in] Attributes Attribute value of the variable.
1775 @param[in] AuthVarType Verify against PK, KEK database, private database or certificate in data payload.
1776 @param[in] OrgTimeStamp Pointer to original time stamp,
1777 original variable is not found if NULL.
1778 @param[out] VarPayloadPtr Pointer to variable payload address.
1779 @param[out] VarPayloadSize Pointer to variable payload size.
1781 @retval EFI_INVALID_PARAMETER Invalid parameter.
1782 @retval EFI_SECURITY_VIOLATION The variable does NOT pass the validation
1783 check carried out by the firmware.
1784 @retval EFI_OUT_OF_RESOURCES Failed to process variable due to lack
1786 @retval EFI_SUCCESS Variable pass validation successfully.
1790 VerifyTimeBasedPayload (
1791 IN CHAR16
*VariableName
,
1792 IN EFI_GUID
*VendorGuid
,
1795 IN UINT32 Attributes
,
1796 IN AUTHVAR_TYPE AuthVarType
,
1797 IN EFI_TIME
*OrgTimeStamp
,
1798 OUT UINT8
**VarPayloadPtr
,
1799 OUT UINTN
*VarPayloadSize
1802 EFI_VARIABLE_AUTHENTICATION_2
*CertData
;
1808 BOOLEAN VerifyStatus
;
1810 EFI_SIGNATURE_LIST
*CertList
;
1811 EFI_SIGNATURE_DATA
*Cert
;
1819 UINT8
*TopLevelCert
;
1820 UINTN TopLevelCertSize
;
1822 UINTN TrustedCertSize
;
1824 UINTN CertStackSize
;
1825 UINT8
*CertsInCertDb
;
1826 UINT32 CertsSizeinDb
;
1827 UINT8 Sha256Digest
[SHA256_DIGEST_SIZE
];
1828 EFI_CERT_DATA
*CertDataPtr
;
1831 // 1. TopLevelCert is the top-level issuer certificate in signature Signer Cert Chain
1832 // 2. TrustedCert is the certificate which firmware trusts. It could be saved in protected
1833 // storage or PK payload on PK init
1835 VerifyStatus
= FALSE
;
1840 TopLevelCert
= NULL
;
1841 CertsInCertDb
= NULL
;
1845 // When the attribute EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS is
1846 // set, then the Data buffer shall begin with an instance of a complete (and serialized)
1847 // EFI_VARIABLE_AUTHENTICATION_2 descriptor. The descriptor shall be followed by the new
1848 // variable value and DataSize shall reflect the combined size of the descriptor and the new
1849 // variable value. The authentication descriptor is not part of the variable data and is not
1850 // returned by subsequent calls to GetVariable().
1852 CertData
= (EFI_VARIABLE_AUTHENTICATION_2
*) Data
;
1855 // Verify that Pad1, Nanosecond, TimeZone, Daylight and Pad2 components of the
1856 // TimeStamp value are set to zero.
1858 if ((CertData
->TimeStamp
.Pad1
!= 0) ||
1859 (CertData
->TimeStamp
.Nanosecond
!= 0) ||
1860 (CertData
->TimeStamp
.TimeZone
!= 0) ||
1861 (CertData
->TimeStamp
.Daylight
!= 0) ||
1862 (CertData
->TimeStamp
.Pad2
!= 0)) {
1863 return EFI_SECURITY_VIOLATION
;
1866 if ((OrgTimeStamp
!= NULL
) && ((Attributes
& EFI_VARIABLE_APPEND_WRITE
) == 0)) {
1867 if (AuthServiceInternalCompareTimeStamp (&CertData
->TimeStamp
, OrgTimeStamp
)) {
1869 // TimeStamp check fail, suspicious replay attack, return EFI_SECURITY_VIOLATION.
1871 return EFI_SECURITY_VIOLATION
;
1876 // wCertificateType should be WIN_CERT_TYPE_EFI_GUID.
1877 // Cert type should be EFI_CERT_TYPE_PKCS7_GUID.
1879 if ((CertData
->AuthInfo
.Hdr
.wCertificateType
!= WIN_CERT_TYPE_EFI_GUID
) ||
1880 !CompareGuid (&CertData
->AuthInfo
.CertType
, &gEfiCertPkcs7Guid
)) {
1882 // Invalid AuthInfo type, return EFI_SECURITY_VIOLATION.
1884 return EFI_SECURITY_VIOLATION
;
1888 // Find out Pkcs7 SignedData which follows the EFI_VARIABLE_AUTHENTICATION_2 descriptor.
1889 // AuthInfo.Hdr.dwLength is the length of the entire certificate, including the length of the header.
1891 SigData
= CertData
->AuthInfo
.CertData
;
1892 SigDataSize
= CertData
->AuthInfo
.Hdr
.dwLength
- (UINT32
) (OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID
, CertData
));
1895 // SignedData.digestAlgorithms shall contain the digest algorithm used when preparing the
1896 // signature. Only a digest algorithm of SHA-256 is accepted.
1898 // According to PKCS#7 Definition:
1899 // SignedData ::= SEQUENCE {
1901 // digestAlgorithms DigestAlgorithmIdentifiers,
1902 // contentInfo ContentInfo,
1904 // The DigestAlgorithmIdentifiers can be used to determine the hash algorithm
1905 // in VARIABLE_AUTHENTICATION_2 descriptor.
1906 // This field has the fixed offset (+13) and be calculated based on two bytes of length encoding.
1908 if ((Attributes
& EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
) != 0) {
1909 if (SigDataSize
>= (13 + sizeof (mSha256OidValue
))) {
1910 if (((*(SigData
+ 1) & TWO_BYTE_ENCODE
) != TWO_BYTE_ENCODE
) ||
1911 (CompareMem (SigData
+ 13, &mSha256OidValue
, sizeof (mSha256OidValue
)) != 0)) {
1912 return EFI_SECURITY_VIOLATION
;
1918 // Find out the new data payload which follows Pkcs7 SignedData directly.
1920 PayloadPtr
= SigData
+ SigDataSize
;
1921 PayloadSize
= DataSize
- OFFSET_OF_AUTHINFO2_CERT_DATA
- (UINTN
) SigDataSize
;
1924 // Construct a serialization buffer of the values of the VariableName, VendorGuid and Attributes
1925 // parameters of the SetVariable() call and the TimeStamp component of the
1926 // EFI_VARIABLE_AUTHENTICATION_2 descriptor followed by the variable's new value
1927 // i.e. (VariableName, VendorGuid, Attributes, TimeStamp, Data)
1929 NewDataSize
= PayloadSize
+ sizeof (EFI_TIME
) + sizeof (UINT32
) +
1930 sizeof (EFI_GUID
) + StrSize (VariableName
) - sizeof (CHAR16
);
1933 // Here is to reuse scratch data area(at the end of volatile variable store)
1934 // to reduce SMRAM consumption for SMM variable driver.
1935 // The scratch buffer is enough to hold the serialized data and safe to use,
1936 // because it is only used at here to do verification temporarily first
1937 // and then used in UpdateVariable() for a time based auth variable set.
1939 Status
= mAuthVarLibContextIn
->GetScratchBuffer (&NewDataSize
, (VOID
**) &NewData
);
1940 if (EFI_ERROR (Status
)) {
1941 return EFI_OUT_OF_RESOURCES
;
1945 Length
= StrLen (VariableName
) * sizeof (CHAR16
);
1946 CopyMem (Buffer
, VariableName
, Length
);
1949 Length
= sizeof (EFI_GUID
);
1950 CopyMem (Buffer
, VendorGuid
, Length
);
1953 Length
= sizeof (UINT32
);
1954 CopyMem (Buffer
, &Attr
, Length
);
1957 Length
= sizeof (EFI_TIME
);
1958 CopyMem (Buffer
, &CertData
->TimeStamp
, Length
);
1961 CopyMem (Buffer
, PayloadPtr
, PayloadSize
);
1963 if (AuthVarType
== AuthVarTypePk
) {
1965 // Verify that the signature has been made with the current Platform Key (no chaining for PK).
1966 // First, get signer's certificates from SignedData.
1968 VerifyStatus
= Pkcs7GetSigners (
1976 if (!VerifyStatus
) {
1981 // Second, get the current platform key from variable. Check whether it's identical with signer's certificates
1982 // in SignedData. If not, return error immediately.
1984 Status
= AuthServiceInternalFindVariable (
1985 EFI_PLATFORM_KEY_NAME
,
1986 &gEfiGlobalVariableGuid
,
1990 if (EFI_ERROR (Status
)) {
1991 VerifyStatus
= FALSE
;
1994 CertList
= (EFI_SIGNATURE_LIST
*) Data
;
1995 Cert
= (EFI_SIGNATURE_DATA
*) ((UINT8
*) CertList
+ sizeof (EFI_SIGNATURE_LIST
) + CertList
->SignatureHeaderSize
);
1996 if ((TopLevelCertSize
!= (CertList
->SignatureSize
- (sizeof (EFI_SIGNATURE_DATA
) - 1))) ||
1997 (CompareMem (Cert
->SignatureData
, TopLevelCert
, TopLevelCertSize
) != 0)) {
1998 VerifyStatus
= FALSE
;
2003 // Verify Pkcs7 SignedData via Pkcs7Verify library.
2005 VerifyStatus
= Pkcs7Verify (
2014 } else if (AuthVarType
== AuthVarTypeKek
) {
2017 // Get KEK database from variable.
2019 Status
= AuthServiceInternalFindVariable (
2020 EFI_KEY_EXCHANGE_KEY_NAME
,
2021 &gEfiGlobalVariableGuid
,
2025 if (EFI_ERROR (Status
)) {
2030 // Ready to verify Pkcs7 SignedData. Go through KEK Signature Database to find out X.509 CertList.
2032 KekDataSize
= (UINT32
) DataSize
;
2033 CertList
= (EFI_SIGNATURE_LIST
*) Data
;
2034 while ((KekDataSize
> 0) && (KekDataSize
>= CertList
->SignatureListSize
)) {
2035 if (CompareGuid (&CertList
->SignatureType
, &gEfiCertX509Guid
)) {
2036 Cert
= (EFI_SIGNATURE_DATA
*) ((UINT8
*) CertList
+ sizeof (EFI_SIGNATURE_LIST
) + CertList
->SignatureHeaderSize
);
2037 CertCount
= (CertList
->SignatureListSize
- sizeof (EFI_SIGNATURE_LIST
) - CertList
->SignatureHeaderSize
) / CertList
->SignatureSize
;
2038 for (Index
= 0; Index
< CertCount
; Index
++) {
2040 // Iterate each Signature Data Node within this CertList for a verify
2042 TrustedCert
= Cert
->SignatureData
;
2043 TrustedCertSize
= CertList
->SignatureSize
- (sizeof (EFI_SIGNATURE_DATA
) - 1);
2046 // Verify Pkcs7 SignedData via Pkcs7Verify library.
2048 VerifyStatus
= Pkcs7Verify (
2059 Cert
= (EFI_SIGNATURE_DATA
*) ((UINT8
*) Cert
+ CertList
->SignatureSize
);
2062 KekDataSize
-= CertList
->SignatureListSize
;
2063 CertList
= (EFI_SIGNATURE_LIST
*) ((UINT8
*) CertList
+ CertList
->SignatureListSize
);
2065 } else if (AuthVarType
== AuthVarTypePriv
) {
2068 // Process common authenticated variable except PK/KEK/DB/DBX/DBT.
2069 // Get signer's certificates from SignedData.
2071 VerifyStatus
= Pkcs7GetSigners (
2079 if (!VerifyStatus
) {
2084 // Get previously stored signer's certificates from certdb or certdbv for existing
2085 // variable. Check whether they are identical with signer's certificates
2086 // in SignedData. If not, return error immediately.
2088 if (OrgTimeStamp
!= NULL
) {
2089 VerifyStatus
= FALSE
;
2091 Status
= GetCertsFromDb (VariableName
, VendorGuid
, Attributes
, &CertsInCertDb
, &CertsSizeinDb
);
2092 if (EFI_ERROR (Status
)) {
2096 if (CertsSizeinDb
== SHA256_DIGEST_SIZE
) {
2098 // Check hash of signer cert CommonName + Top-level issuer tbsCertificate against data in CertDb
2100 CertDataPtr
= (EFI_CERT_DATA
*)(SignerCerts
+ 1);
2101 Status
= CalculatePrivAuthVarSignChainSHA256Digest(
2102 CertDataPtr
->CertDataBuffer
,
2103 ReadUnaligned32 ((UINT32
*)&(CertDataPtr
->CertDataLength
)),
2108 if (EFI_ERROR(Status
) || CompareMem (Sha256Digest
, CertsInCertDb
, CertsSizeinDb
) != 0){
2113 // Keep backward compatible with previous solution which saves whole signer certs stack in CertDb
2115 if ((CertStackSize
!= CertsSizeinDb
) ||
2116 (CompareMem (SignerCerts
, CertsInCertDb
, CertsSizeinDb
) != 0)) {
2122 VerifyStatus
= Pkcs7Verify (
2130 if (!VerifyStatus
) {
2134 if ((OrgTimeStamp
== NULL
) && (PayloadSize
!= 0)) {
2136 // When adding a new common authenticated variable, always save Hash of cn of signer cert + tbsCertificate of Top-level issuer
2138 CertDataPtr
= (EFI_CERT_DATA
*)(SignerCerts
+ 1);
2139 Status
= InsertCertsToDb (
2143 CertDataPtr
->CertDataBuffer
,
2144 ReadUnaligned32 ((UINT32
*)&(CertDataPtr
->CertDataLength
)),
2148 if (EFI_ERROR (Status
)) {
2149 VerifyStatus
= FALSE
;
2153 } else if (AuthVarType
== AuthVarTypePayload
) {
2154 CertList
= (EFI_SIGNATURE_LIST
*) PayloadPtr
;
2155 Cert
= (EFI_SIGNATURE_DATA
*) ((UINT8
*) CertList
+ sizeof (EFI_SIGNATURE_LIST
) + CertList
->SignatureHeaderSize
);
2156 TrustedCert
= Cert
->SignatureData
;
2157 TrustedCertSize
= CertList
->SignatureSize
- (sizeof (EFI_SIGNATURE_DATA
) - 1);
2159 // Verify Pkcs7 SignedData via Pkcs7Verify library.
2161 VerifyStatus
= Pkcs7Verify (
2170 return EFI_SECURITY_VIOLATION
;
2175 if (AuthVarType
== AuthVarTypePk
|| AuthVarType
== AuthVarTypePriv
) {
2176 Pkcs7FreeSigners (TopLevelCert
);
2177 Pkcs7FreeSigners (SignerCerts
);
2180 if (!VerifyStatus
) {
2181 return EFI_SECURITY_VIOLATION
;
2184 Status
= CheckSignatureListFormat(VariableName
, VendorGuid
, PayloadPtr
, PayloadSize
);
2185 if (EFI_ERROR (Status
)) {
2189 *VarPayloadPtr
= PayloadPtr
;
2190 *VarPayloadSize
= PayloadSize
;
2196 Process variable with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS set
2198 Caution: This function may receive untrusted input.
2199 This function may be invoked in SMM mode, and datasize and data are external input.
2200 This function will do basic validation, before parse the data.
2201 This function will parse the authentication carefully to avoid security issues, like
2202 buffer overflow, integer overflow.
2204 @param[in] VariableName Name of Variable to be found.
2205 @param[in] VendorGuid Variable vendor GUID.
2206 @param[in] Data Data pointer.
2207 @param[in] DataSize Size of Data found. If size is less than the
2208 data, this value contains the required size.
2209 @param[in] Attributes Attribute value of the variable.
2210 @param[in] AuthVarType Verify against PK, KEK database, private database or certificate in data payload.
2211 @param[out] VarDel Delete the variable or not.
2213 @retval EFI_INVALID_PARAMETER Invalid parameter.
2214 @retval EFI_SECURITY_VIOLATION The variable does NOT pass the validation
2215 check carried out by the firmware.
2216 @retval EFI_OUT_OF_RESOURCES Failed to process variable due to lack
2218 @retval EFI_SUCCESS Variable pass validation successfully.
2222 VerifyTimeBasedPayloadAndUpdate (
2223 IN CHAR16
*VariableName
,
2224 IN EFI_GUID
*VendorGuid
,
2227 IN UINT32 Attributes
,
2228 IN AUTHVAR_TYPE AuthVarType
,
2233 EFI_STATUS FindStatus
;
2236 EFI_VARIABLE_AUTHENTICATION_2
*CertData
;
2237 AUTH_VARIABLE_INFO OrgVariableInfo
;
2240 ZeroMem (&OrgVariableInfo
, sizeof (OrgVariableInfo
));
2241 FindStatus
= mAuthVarLibContextIn
->FindVariable (
2247 Status
= VerifyTimeBasedPayload (
2254 (!EFI_ERROR (FindStatus
)) ? OrgVariableInfo
.TimeStamp
: NULL
,
2258 if (EFI_ERROR (Status
)) {
2262 if (!EFI_ERROR(FindStatus
)
2263 && (PayloadSize
== 0)
2264 && ((Attributes
& EFI_VARIABLE_APPEND_WRITE
) == 0)) {
2270 CertData
= (EFI_VARIABLE_AUTHENTICATION_2
*) Data
;
2273 // Final step: Update/Append Variable if it pass Pkcs7Verify
2275 Status
= AuthServiceInternalUpdateVariableWithTimeStamp (
2281 &CertData
->TimeStamp
2285 // Delete signer's certificates when delete the common authenticated variable.
2287 if (IsDel
&& AuthVarType
== AuthVarTypePriv
&& !EFI_ERROR(Status
) ) {
2288 Status
= DeleteCertsFromDb (VariableName
, VendorGuid
, Attributes
);
2291 if (VarDel
!= NULL
) {
2292 if (IsDel
&& !EFI_ERROR(Status
)) {