Skip to content

Commit

Permalink
UefiPayloadPkg: Enroll Keys for SecureBoot
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Rhodes <[email protected]>
  • Loading branch information
Sean-StarLabs committed Nov 7, 2024
1 parent b8a9bd1 commit eb3fb0e
Show file tree
Hide file tree
Showing 16 changed files with 945 additions and 1 deletion.
605 changes: 605 additions & 0 deletions UefiPayloadPkg/EnrollDefaultKeys/EnrollDefaultKeys.c

Large diffs are not rendered by default.

121 changes: 121 additions & 0 deletions UefiPayloadPkg/EnrollDefaultKeys/EnrollDefaultKeys.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/** @file
Type definitions and object declarations for the EnrollDefaultKeys
application.
Copyright (C) 2014-2019, Red Hat, Inc.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef ENROLL_DEFAULT_KEYS_H_
#define ENROLL_DEFAULT_KEYS_H_

#include <Uefi/UefiBaseType.h>

//
// Convenience structure types for constructing "signature lists" for
// authenticated UEFI variables.
//
// The most important thing about the variable payload is that it is a list of
// lists, where the element size of any given *inner* list is constant.
//
// Since X509 certificates vary in size, each of our *inner* lists will contain
// one element only (one X.509 certificate). This is explicitly mentioned in
// the UEFI specification, in "28.4.1 Signature Database", in a Note.
//
// The list structure looks as follows:
//
// struct EFI_VARIABLE_AUTHENTICATION_2 { |
// struct EFI_TIME { |
// UINT16 Year; |
// UINT8 Month; |
// UINT8 Day; |
// UINT8 Hour; |
// UINT8 Minute; |
// UINT8 Second; |
// UINT8 Pad1; |
// UINT32 Nanosecond; |
// INT16 TimeZone; |
// UINT8 Daylight; |
// UINT8 Pad2; |
// } TimeStamp; |
// |
// struct WIN_CERTIFICATE_UEFI_GUID { | |
// struct WIN_CERTIFICATE { | |
// UINT32 dwLength; ----------------------------------------+ |
// UINT16 wRevision; | |
// UINT16 wCertificateType; | |
// } Hdr; | +- DataSize
// | |
// EFI_GUID CertType; | |
// UINT8 CertData[1] = { <--- "struct hack" | |
// struct EFI_SIGNATURE_LIST { | | |
// EFI_GUID SignatureType; | | |
// UINT32 SignatureListSize; -------------------------+ | |
// UINT32 SignatureHeaderSize; | | |
// UINT32 SignatureSize; ---------------------------+ | | |
// UINT8 SignatureHeader[SignatureHeaderSize]; | | | |
// v | | |
// struct EFI_SIGNATURE_DATA { | | | |
// EFI_GUID SignatureOwner; | | | |
// UINT8 SignatureData[1] = { <--- "struct hack" | | | |
// X.509 payload | | | |
// } | | | |
// } Signatures[]; | | |
// } SigLists[]; | |
// }; | |
// } AuthInfo; | |
// }; |
//
// Given that the "struct hack" invokes undefined behavior (which is why C99
// introduced the flexible array member), and because subtracting those pesky
// sizes of 1 is annoying, and because the format is fully specified in the
// UEFI specification, we'll introduce two matching convenience structures that
// are customized for our X.509 purposes.
//
#pragma pack (1)
typedef struct {
EFI_TIME TimeStamp;

//
// dwLength covers data below
//
UINT32 dwLength;
UINT16 wRevision;
UINT16 wCertificateType;
EFI_GUID CertType;
} SINGLE_HEADER;

typedef struct {
//
// SignatureListSize covers data below
//
EFI_GUID SignatureType;
UINT32 SignatureListSize;
UINT32 SignatureHeaderSize; // constant 0
UINT32 SignatureSize;

//
// SignatureSize covers data below
//
EFI_GUID SignatureOwner;

//
// X.509 certificate follows
//
} REPEATING_HEADER;
#pragma pack ()

//
// A structure that collects the values of UEFI variables related to Secure
// Boot.
//
typedef struct {
UINT8 SetupMode;
UINT8 SecureBoot;
UINT8 SecureBootEnable;
UINT8 CustomMode;
UINT8 VendorKeys;
} SETTINGS;

#endif /* ENROLL_DEFAULT_KEYS_H_ */
63 changes: 63 additions & 0 deletions UefiPayloadPkg/EnrollDefaultKeys/EnrollDefaultKeys.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
## @file
# This file handels SecureBoot setup.
#
# Copyright (c) 2013 - 2019, Intel Corporation. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
#
##

[Defines]
INF_VERSION = 0x00010005
BASE_NAME = EnrollDefaultKeys
FILE_GUID = 14693BD4-D114-4177-979E-37F279BAD620
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 0.1
ENTRY_POINT = DriverEntry

#
# VALID_ARCHITECTURES = IA32 X64
#

[Sources]
EnrollDefaultKeys.c

[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
SecurityPkg/SecurityPkg.dec
UefiPayloadPkg/UefiPayloadPkg.dec

[Guids]
gEfiCertPkcs7Guid
gEfiCertX509Guid
gEfiCustomModeEnableGuid
gEfiGlobalVariableGuid
gEfiImageSecurityDatabaseGuid
gEfiSecureBootEnableDisableGuid
gMicrosoftVendorGuid
gMicrosoftDbxUpdateGuid
gMicrosoftDbUefi2011Guid
gMicrosoftDbWin2011Guid
gMicrosoftDbUefi2023Guid
gMicrosoftDbWinUefi2023Guid
gMicrosoftKek2011Guid
gMicrosoftKek2023Guid
gMicrosoftKekUefi2023Guid
gMicrosoftPkOem2023Guid

[LibraryClasses]
BaseMemoryLib
DebugLib
DxeServicesLib
MemoryAllocationLib
UefiBootServicesTableLib
UefiDriverEntryPoint
UefiRuntimeServicesTableLib

[Protocols]
gEfiVariableWriteArchProtocolGuid ## CONSUMES

[Depex]
TRUE
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 5 additions & 1 deletion UefiPayloadPkg/SmmStoreFvb/SmmStoreFvbRuntimeDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ InitializeFvAndVariableStoreHeaders (
// VARIABLE_STORE_HEADER
//
VariableStoreHeader = (VARIABLE_STORE_HEADER *)((UINTN)Headers + FirmwareVolumeHeader->HeaderLength);
CopyGuid (&VariableStoreHeader->Signature, &gEfiVariableGuid);
//
// Should be gEfiVariableGuid as SMM doesn't authenticate, but userspace does
// Must be gEfiAuthenticatedVariableGuid for SecureBoot
//
CopyGuid (&VariableStoreHeader->Signature, &gEfiAuthenticatedVariableGuid);
VariableStoreHeader->Size = PcdGet32 (PcdFlashNvStorageVariableSize) - FirmwareVolumeHeader->HeaderLength;
VariableStoreHeader->Format = VARIABLE_STORE_FORMATTED;
VariableStoreHeader->State = VARIABLE_STORE_HEALTHY;
Expand Down
12 changes: 12 additions & 0 deletions UefiPayloadPkg/UefiPayloadPkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@

gEfiSmmStoreInfoHobGuid = { 0xf585ca19, 0x881b, 0x44fb, { 0x3f, 0x3d, 0x81, 0x89, 0x7c, 0x57, 0xbb, 0x01 } }

# Secure Boot keys and owners
gMicrosoftVendorGuid = { 0x77fa9abd, 0x0359, 0x4d32, { 0xbd, 0x60, 0x28, 0xf4, 0xe7, 0x8f, 0x78, 0x4b } }
gMicrosoftDbxUpdateGuid = { 0x4e52dd60, 0xd79e, 0x42c5, { 0x83, 0x37, 0x08, 0x92, 0x32, 0xea, 0x5c, 0x87 } }
gMicrosoftDbUefi2011Guid = { 0x73282f84, 0x7909, 0x4e87, { 0xad, 0xf0, 0x84, 0x5d, 0x5d, 0xa3, 0x35, 0xab } }
gMicrosoftDbWin2011Guid = { 0x9b29f606, 0x5102, 0x4de1, { 0xa8, 0x8a, 0xff, 0x62, 0x10, 0xbd, 0x8b, 0x65 } }
gMicrosoftDbUefi2023Guid = { 0xc7769261, 0xfe8d, 0x4e15, { 0xb3, 0x34, 0xca, 0xdf, 0x43, 0x64, 0xad, 0x92 } }
gMicrosoftDbWinUefi2023Guid = { 0x4ac66f32, 0x6895, 0x46fc, { 0xad, 0x00, 0xf1, 0xc8, 0x1d, 0x06, 0xc6, 0x68 } }
gMicrosoftKek2011Guid = { 0x73f89874, 0xb2ec, 0x4c28, { 0xa7, 0xe3, 0x7d, 0x80, 0x30, 0x13, 0x4e, 0x0b } }
gMicrosoftKek2023Guid = { 0xcce7d8e7, 0xaae8, 0x4697, { 0xb5, 0xc0, 0xef, 0x35, 0xa9, 0x2a, 0x05, 0x9f } }
gMicrosoftKekUefi2023Guid = { 0xf5a81b7b, 0x419a, 0x4a92, { 0x82, 0x12, 0x1c, 0x36, 0x9b, 0xcb, 0xe2, 0xcb } }
gMicrosoftPkOem2023Guid = { 0x701649dd, 0x8739, 0x40b9, { 0xbb, 0xdb, 0x9c, 0xa4, 0x34, 0xfd, 0xcd, 0x3b } }

[Ppis]
gEfiPayLoadHobBasePpiGuid = { 0xdbe23aa1, 0xa342, 0x4b97, {0x85, 0xb6, 0xb2, 0x26, 0xf1, 0x61, 0x73, 0x89} }

Expand Down
47 changes: 47 additions & 0 deletions UefiPayloadPkg/UefiPayloadPkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,22 @@
PerformanceLib|MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.inf
!endif

!if $(SECURE_BOOT_ENABLE) == TRUE
AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf
SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.inf
SecureBootVariableProvisionLib|SecurityPkg/Library/SecureBootVariableProvisionLib/SecureBootVariableProvisionLib.inf
PlatformPKProtectionLib|SecurityPkg/Library/PlatformPKProtectionLibVarPolicy/PlatformPKProtectionLibVarPolicy.inf

# re-use the UserPhysicalPresent() dummy implementation from the ovmf tree
PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf
!else
AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLibNull.inf
!endif

BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf

[LibraryClasses.common.DXE_DRIVER]
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
Expand All @@ -417,6 +433,24 @@
PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf
!endif

!if $(SECURE_BOOT_ENABLE) == TRUE
AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf
SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.inf
SecureBootVariableProvisionLib|SecurityPkg/Library/SecureBootVariableProvisionLib/SecureBootVariableProvisionLib.inf
PlatformPKProtectionLib|SecurityPkg/Library/PlatformPKProtectionLibVarPolicy/PlatformPKProtectionLibVarPolicy.inf

# re-use the UserPhysicalPresent() dummy implementation from the ovmf tree
PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf
!else
AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLibNull.inf
!endif

BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf
RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf


[LibraryClasses.common.DXE_RUNTIME_DRIVER]
!if $(SECURE_BOOT_ENABLE) == TRUE
BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf
Expand All @@ -429,6 +463,18 @@
PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf
!endif

!if $(SECURE_BOOT_ENABLE) == TRUE
AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf
SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.inf
SecureBootVariableProvisionLib|SecurityPkg/Library/SecureBootVariableProvisionLib/SecureBootVariableProvisionLib.inf
PlatformPKProtectionLib|SecurityPkg/Library/PlatformPKProtectionLibVarPolicy/PlatformPKProtectionLibVarPolicy.inf

# re-use the UserPhysicalPresent() dummy implementation from the ovmf tree
PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf
!else
AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLibNull.inf
!endif

[LibraryClasses.common.UEFI_DRIVER,LibraryClasses.common.UEFI_APPLICATION]
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
Expand Down Expand Up @@ -762,6 +808,7 @@

!if $(SECURE_BOOT_ENABLE) == TRUE
SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
UefiPayloadPkg/EnrollDefaultKeys/EnrollDefaultKeys.inf
!endif

UefiCpuPkg/CpuDxe/CpuDxe.inf
Expand Down
92 changes: 92 additions & 0 deletions UefiPayloadPkg/UefiPayloadPkg.fdf
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,52 @@ INF PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf
!if $(UNIVERSAL_PAYLOAD) == FALSE
!if $(SECURE_BOOT_ENABLE) == TRUE
INF SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
INF UefiPayloadPkg/EnrollDefaultKeys/EnrollDefaultKeys.inf

FILE FREEFORM = 4e52dd60-d79e-42c5-8337-089232ea5c87 {
SECTION RAW = UefiPayloadPkg/EnrollDefaultKeys/keys/dbx_microsoft_update.bin
SECTION UI = "Microsoft Corporation DBX Update"
}

FILE FREEFORM = 73282f84-7909-4e87-adf0-845d5da335ab {
SECTION RAW = UefiPayloadPkg/EnrollDefaultKeys/keys/db_microsoft_uefi_2011.der
SECTION UI = "Microsoft Corporation DB UEFI 2011"
}

FILE FREEFORM = 9b29f606-5102-4de1-a88a-ff6210bd8b65 {
SECTION RAW = UefiPayloadPkg/EnrollDefaultKeys/keys/db_microsoft_win_2011.der
SECTION UI = "Microsoft Corporation DB Windows 2011"
}

FILE FREEFORM = c7769261-fe8d-4e15-b334-cadf4364ad92 {
SECTION RAW = UefiPayloadPkg/EnrollDefaultKeys/keys/db_microsoft_uefi_2023.der
SECTION UI = "Microsoft Corporation DB UEFI 2023"
}

FILE FREEFORM = 4ac66f32-6895-46fc-ad00-f1c81d06c668 {
SECTION RAW = UefiPayloadPkg/EnrollDefaultKeys/keys/db_microsoft_win_uefi_2023.der
SECTION UI = "Microsoft Corporation DB Windows UEFI 2023"
}

FILE FREEFORM = 73f89874-b2ec-4c28-a7e3-7d8030134e0b {
SECTION RAW = UefiPayloadPkg/EnrollDefaultKeys/keys/kek_microsoft_2011.der
SECTION UI = "Microsoft Corporation KEK CA 2011"
}

FILE FREEFORM = cce7d8e7-aae8-4697-b5c0-ef35a92a059f {
SECTION RAW = UefiPayloadPkg/EnrollDefaultKeys/keys/kek_microsoft_2023.der
SECTION UI = "Microsoft Corporation KEK CA 2023"
}

FILE FREEFORM = f5a81b7b-419a-4a92-8212-1c369bcbe2cb {
SECTION RAW = UefiPayloadPkg/EnrollDefaultKeys/keys/kek_microsoft_uefi_2023.der
SECTION UI = "Microsoft Corporation UEFI KEK CA 2023"
}

FILE FREEFORM = 701649dd-8739-40b9-bbdb-9ca434fdcd3b {
SECTION RAW = UefiPayloadPkg/EnrollDefaultKeys/keys/pk_microsoft_oem_2023.der
SECTION UI = "Microsoft Corporation OEM PK 2023"
}
!endif
!endif

Expand Down Expand Up @@ -369,6 +415,52 @@ READ_LOCK_CAP = TRUE
READ_LOCK_STATUS = TRUE

INF SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
INF UefiPayloadPkg/EnrollDefaultKeys/EnrollDefaultKeys.inf

FILE FREEFORM = 4e52dd60-d79e-42c5-8337-089232ea5c87 {
SECTION RAW = UefiPayloadPkg/EnrollDefaultKeys/keys/dbx_microsoft_update.bin
SECTION UI = "Microsoft Corporation DBX Update"
}

FILE FREEFORM = 73282f84-7909-4e87-adf0-845d5da335ab {
SECTION RAW = UefiPayloadPkg/EnrollDefaultKeys/keys/db_microsoft_uefi_2011.der
SECTION UI = "Microsoft Corporation DB UEFI 2011"
}

FILE FREEFORM = 9b29f606-5102-4de1-a88a-ff6210bd8b65 {
SECTION RAW = UefiPayloadPkg/EnrollDefaultKeys/keys/db_microsoft_win_2011.der
SECTION UI = "Microsoft Corporation DB Windows 2011"
}

FILE FREEFORM = c7769261-fe8d-4e15-b334-cadf4364ad92 {
SECTION RAW = UefiPayloadPkg/EnrollDefaultKeys/keys/db_microsoft_uefi_2023.der
SECTION UI = "Microsoft Corporation DB UEFI 2023"
}

FILE FREEFORM = 4ac66f32-6895-46fc-ad00-f1c81d06c668 {
SECTION RAW = UefiPayloadPkg/EnrollDefaultKeys/keys/db_microsoft_win_uefi_2023.der
SECTION UI = "Microsoft Corporation DB Windows UEFI 2023"
}

FILE FREEFORM = 73f89874-b2ec-4c28-a7e3-7d8030134e0b {
SECTION RAW = UefiPayloadPkg/EnrollDefaultKeys/keys/kek_microsoft_2011.der
SECTION UI = "Microsoft Corporation KEK CA 2011"
}

FILE FREEFORM = cce7d8e7-aae8-4697-b5c0-ef35a92a059f {
SECTION RAW = UefiPayloadPkg/EnrollDefaultKeys/keys/kek_microsoft_2023.der
SECTION UI = "Microsoft Corporation KEK CA 2023"
}

FILE FREEFORM = f5a81b7b-419a-4a92-8212-1c369bcbe2cb {
SECTION RAW = UefiPayloadPkg/EnrollDefaultKeys/keys/kek_microsoft_uefi_2023.der
SECTION UI = "Microsoft Corporation UEFI KEK CA 2023"
}

FILE FREEFORM = 701649dd-8739-40b9-bbdb-9ca434fdcd3b {
SECTION RAW = UefiPayloadPkg/EnrollDefaultKeys/keys/pk_microsoft_oem_2023.der
SECTION UI = "Microsoft Corporation OEM PK 2023"
}

!endif
!endif
Expand Down

0 comments on commit eb3fb0e

Please sign in to comment.