85 if (TmpSigList ==
NULL) {
86 return EFI_OUT_OF_RESOURCES;
104 *SigList = TmpSigList;
130 UINTN NewSigListsSize;
135 if (TmpSigList ==
NULL) {
136 return EFI_OUT_OF_RESOURCES;
139 CopyMem (TmpSigList, SigLists, *SigListsSize);
141 Offset = (UINT8 *)TmpSigList;
142 Offset += *SigListsSize;
143 CopyMem ((VOID *)Offset, SigListAppend, SigListAppend->SignatureListSize);
145 *SigListsSize = NewSigListsSize;
146 *SigListOut = TmpSigList;
185 if ((SigListOut ==
NULL) || (SigListsSize ==
NULL)) {
186 return EFI_INVALID_PARAMETER;
189 if ((KeyInfoCount == 0) || (KeyInfo ==
NULL)) {
190 return EFI_INVALID_PARAMETER;
197 while (InputIndex < KeyInfoCount) {
198 if (KeyInfo[InputIndex].Data !=
NULL) {
199 Size = KeyInfo[InputIndex].DataSize;
201 if (Buffer ==
NULL) {
202 if (EfiSig !=
NULL) {
206 return EFI_OUT_OF_RESOURCES;
211 if (EFI_ERROR (Status)) {
237 return EFI_NOT_FOUND;
240 *SigListOut = EfiSig;
276 UINTN DescriptorSize;
278 if ((Data ==
NULL) || (DataSize ==
NULL) || (Time ==
NULL)) {
279 DEBUG ((DEBUG_ERROR,
"%a(), invalid arg\n", __func__));
280 return EFI_INVALID_PARAMETER;
290 PayloadSize = *DataSize;
294 if (NewData ==
NULL) {
295 DEBUG ((DEBUG_ERROR,
"%a() Out of resources.\n", __func__));
296 return EFI_OUT_OF_RESOURCES;
299 if ((Payload !=
NULL) && (PayloadSize != 0)) {
300 CopyMem (NewData + DescriptorSize, Payload, PayloadSize);
312 if (Payload !=
NULL) {
317 *DataSize = DescriptorSize + PayloadSize;
336 IN CHAR16 *VariableName,
347 if (Variable ==
NULL) {
359 if (EFI_ERROR (Status)) {
360 DEBUG ((DEBUG_ERROR,
"Fail to create time-based data payload: %r", Status));
364 Status =
gRT->SetVariable (
392 IN UINT8 SecureBootMode
395 return gRT->SetVariable (
397 &gEfiCustomModeEnableGuid,
420 Size =
sizeof (*SetupMode);
421 Status =
gRT->GetVariable (
423 &gEfiGlobalVariableGuid,
428 if (EFI_ERROR (Status)) {
457 if (EFI_ERROR (Status)) {
458 DEBUG ((DEBUG_ERROR,
"Cannot check SecureBoot variable %r \n ", Status));
465 if (*SecureBoot == SECURE_BOOT_MODE_DISABLE) {
490 &gEfiImageSecurityDatabaseGuid
513 &gEfiImageSecurityDatabaseGuid
536 &gEfiImageSecurityDatabaseGuid
559 &gEfiGlobalVariableGuid
581 if (EFI_ERROR (Status)) {
587 &gEfiGlobalVariableGuid
606 DEBUG ((DEBUG_INFO,
"%a - Attempting to delete the Secure Boot variables.\n", __func__));
611 if (EFI_ERROR (Status)) {
612 DEBUG ((DEBUG_ERROR,
"%a - Failed to signal PK update start! %r\n", __func__, Status));
614 Status = EFI_ABORTED;
620 if (!EFI_ERROR (Status)) {
622 DEBUG ((DEBUG_INFO,
"%a - PK Delete = %r\n", __func__, Status));
624 if (Status == EFI_NOT_FOUND) {
628 else if (EFI_ERROR (Status)) {
629 Status = EFI_ABORTED;
639 if (!EFI_ERROR (Status)) {
649 DEBUG ((DEBUG_INFO,
"%a - KEK Delete = %r\n", __func__, TempStatus));
650 if (EFI_ERROR (TempStatus) && (TempStatus != EFI_NOT_FOUND)) {
651 Status = EFI_ACCESS_DENIED;
655 DEBUG ((DEBUG_INFO,
"%a - db Delete = %r\n", __func__, TempStatus));
656 if (EFI_ERROR (TempStatus) && (TempStatus != EFI_NOT_FOUND)) {
657 Status = EFI_ACCESS_DENIED;
661 DEBUG ((DEBUG_INFO,
"%a - dbx Delete = %r\n", __func__, TempStatus));
662 if (EFI_ERROR (TempStatus) && (TempStatus != EFI_NOT_FOUND)) {
663 Status = EFI_ACCESS_DENIED;
667 DEBUG ((DEBUG_INFO,
"%a - dbt Delete = %r\n", __func__, TempStatus));
668 if (EFI_ERROR (TempStatus) && (TempStatus != EFI_NOT_FOUND)) {
669 Status = EFI_ACCESS_DENIED;
694 IN CHAR16 *VariableName,
706 if ((VariableName ==
NULL) || (VendorGuid == 0)) {
707 DEBUG ((DEBUG_ERROR,
"Input vendor variable invalid: %p and %p\n", VariableName, VendorGuid));
708 Status = EFI_INVALID_PARAMETER;
712 if ((Data ==
NULL) || (DataSize == 0)) {
714 DEBUG ((DEBUG_ERROR,
"Input argument invalid: %p: %x\n", Data, DataSize));
715 Status = EFI_INVALID_PARAMETER;
720 PayloadSize = DataSize;
723 if (Payload ==
NULL) {
724 return EFI_OUT_OF_RESOURCES;
726 CopyMem (Payload, Data, DataSize);
730 if (EFI_ERROR (Status) || (Payload ==
NULL)) {
731 DEBUG ((DEBUG_ERROR,
"Fail to create time-based data payload: %r\n", Status));
733 Status = EFI_OUT_OF_RESOURCES;
740 Status =
gRT->SetVariable (
744 EFI_VARIABLE_BOOTSERVICE_ACCESS |
745 EFI_VARIABLE_RUNTIME_ACCESS |
751 if (EFI_ERROR (Status)) {
754 "error: %a (\"%s\", %g): %r\n",
766 if (Payload !=
NULL) {
798 DEBUG ((DEBUG_INFO,
"%a() Entry\n", __func__));
800 if (SecureBootPayload ==
NULL) {
801 DEBUG ((DEBUG_ERROR,
"%a - Invalid SecureBoot payload is supplied!\n", __func__));
802 return EFI_INVALID_PARAMETER;
808 DEBUG ((DEBUG_ERROR,
"%a - Cannot set default keys while SecureBoot is enabled!\n", __func__));
812 DEBUG ((DEBUG_INFO,
"%a - Setting up key %s!\n", __func__, SecureBootPayload->SecureBootKeyName));
817 Data = (UINT8 *)SecureBootPayload->DbxPtr;
818 DataSize = SecureBootPayload->DbxSize;
821 &gEfiImageSecurityDatabaseGuid,
827 if (!EFI_ERROR (Status)) {
828 Data = (UINT8 *)SecureBootPayload->DbPtr;
829 DataSize = SecureBootPayload->DbSize;
832 &gEfiImageSecurityDatabaseGuid,
836 if (EFI_ERROR (Status)) {
837 DEBUG ((DEBUG_ERROR,
"%a - Failed to enroll DB %r!\n", __func__, Status));
840 DEBUG ((DEBUG_ERROR,
"%a - Failed to enroll DBX %r!\n", __func__, Status));
844 if (!EFI_ERROR (Status) && (SecureBootPayload->DbtPtr !=
NULL)) {
845 Data = (UINT8 *)SecureBootPayload->DbtPtr;
846 DataSize = SecureBootPayload->DbtSize;
849 &gEfiImageSecurityDatabaseGuid,
853 if (EFI_ERROR (Status)) {
854 DEBUG ((DEBUG_ERROR,
"%a - Failed to enroll DBT %r!\n", __func__, Status));
859 if (!EFI_ERROR (Status)) {
860 Data = (UINT8 *)SecureBootPayload->KekPtr;
861 DataSize = SecureBootPayload->KekSize;
864 &gEfiGlobalVariableGuid,
868 if (EFI_ERROR (Status)) {
869 DEBUG ((DEBUG_ERROR,
"%a - Failed to enroll KEK %r!\n", __func__, Status));
877 if (!EFI_ERROR (Status)) {
880 Data = (UINT8 *)SecureBootPayload->PkPtr;
881 DataSize = SecureBootPayload->PkSize;
884 &gEfiGlobalVariableGuid,
891 if (EFI_ERROR (Status)) {
892 DEBUG ((DEBUG_ERROR,
"%a - Failed to update the PK! - %r\n", __func__, Status));
893 Status = EFI_SECURITY_VIOLATION;
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
#define EFI_SETUP_MODE_NAME
#define EFI_KEY_EXCHANGE_KEY_NAME
#define EFI_PLATFORM_KEY_NAME
#define EFI_SECURE_BOOT_MODE_NAME
#define EFI_IMAGE_SECURITY_DATABASE2
#define EFI_IMAGE_SECURITY_DATABASE1
#define EFI_IMAGE_SECURITY_DATABASE
EFI_RUNTIME_SERVICES * gRT
#define OFFSET_OF(TYPE, Field)
#define DEBUG(Expression)
STATIC EFI_STATUS ConcatenateSigList(IN EFI_SIGNATURE_LIST *SigLists, IN EFI_SIGNATURE_LIST *SigListAppend, OUT EFI_SIGNATURE_LIST **SigListOut, IN OUT UINTN *SigListsSize)
EFI_STATUS EFIAPI SetSecureBootMode(IN UINT8 SecureBootMode)
EFI_STATUS EFIAPI CreateTimeBasedPayload(IN OUT UINTN *DataSize, IN OUT UINT8 **Data, IN EFI_TIME *Time)
BOOLEAN EFIAPI IsSecureBootEnabled(VOID)
EFI_STATUS EFIAPI GetSetupMode(OUT UINT8 *SetupMode)
EFI_STATUS EFIAPI DeleteVariable(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid)
EFI_STATUS EFIAPI SecureBootCreateDataFromInput(OUT UINTN *SigListsSize, OUT EFI_SIGNATURE_LIST **SigListOut, IN UINTN KeyInfoCount, IN CONST SECURE_BOOT_CERTIFICATE_INFO *KeyInfo)
EFI_STATUS EFIAPI DeleteDbx(VOID)
EFI_STATUS EFIAPI SetSecureBootVariablesToDefault(IN CONST SECURE_BOOT_PAYLOAD_INFO *SecureBootPayload)
EFI_STATUS EFIAPI DeletePlatformKey(VOID)
EFI_STATUS EFIAPI DeleteDb(VOID)
EFI_STATUS EFIAPI DeleteKEK(VOID)
EFI_STATUS EFIAPI DeleteDbt(VOID)
EFI_STATUS EFIAPI DeleteSecureBootVariables(VOID)
STATIC EFI_STATUS CreateSigList(IN VOID *Data, IN UINTN Size, OUT EFI_SIGNATURE_LIST **SigList)
EFI_STATUS EFIAPI EnrollFromInput(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINTN DataSize, IN VOID *Data)
VOID EFIAPI Exit(IN EFI_STATUS Status)
EFI_STATUS EFIAPI GetEfiGlobalVariable2(IN CONST CHAR16 *Name, OUT VOID **Value, OUT UINTN *Size OPTIONAL)
EFI_STATUS EFIAPI GetVariable2(IN CONST CHAR16 *Name, IN CONST EFI_GUID *Guid, OUT VOID **Value, OUT UINTN *Size OPTIONAL)
#define EFI_VARIABLE_NON_VOLATILE
#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
UINT32 SignatureHeaderSize
WIN_CERTIFICATE_UEFI_GUID AuthInfo