TianoCore EDK2 master
Loading...
Searching...
No Matches
SecureBootConfigImpl.h
Go to the documentation of this file.
1
10#ifndef __SECUREBOOT_CONFIG_IMPL_H__
11#define __SECUREBOOT_CONFIG_IMPL_H__
12
13#include <Uefi.h>
14
18#include <Protocol/BlockIo.h>
19#include <Protocol/DevicePath.h>
20#include <Protocol/DebugPort.h>
21#include <Protocol/LoadFile.h>
22
23#include <Library/BaseLib.h>
25#include <Library/DebugLib.h>
30#include <Library/UefiLib.h>
31#include <Library/HiiLib.h>
33#include <Library/PrintLib.h>
37#include <Library/PeCoffLib.h>
38
39#include <Guid/MdeModuleHii.h>
43#include <Guid/FileInfo.h>
44#include <Guid/WinCertificate.h>
45
47
48//
49// Tool generated IFR binary data and String package data
50//
51extern UINT8 SecureBootConfigBin[];
52extern UINT8 SecureBootConfigDxeStrings[];
53
54//
55// Shared IFR form update data
56//
57extern VOID *mStartOpCodeHandle;
58extern VOID *mEndOpCodeHandle;
59extern EFI_IFR_GUID_LABEL *mStartLabel;
60extern EFI_IFR_GUID_LABEL *mEndLabel;
61
62#define MAX_CHAR 480
63#define TWO_BYTE_ENCODE 0x82
64#define BUFFER_MAX_SIZE 100
65
66//
67// SHA-256 digest size in bytes
68//
69#define SHA256_DIGEST_SIZE 32
70//
71// SHA-384 digest size in bytes
72//
73#define SHA384_DIGEST_SIZE 48
74//
75// SHA-512 digest size in bytes
76//
77#define SHA512_DIGEST_SIZE 64
78
79//
80// Set max digest size as SHA512 Output (64 bytes) by far
81//
82#define MAX_DIGEST_SIZE SHA512_DIGEST_SIZE
83
84#define WIN_CERT_UEFI_RSA2048_SIZE 256
85#define WIN_CERT_UEFI_RSA3072_SIZE 384
86#define WIN_CERT_UEFI_RSA4096_SIZE 512
87
88//
89// Support hash types
90//
91#define HASHALG_SHA224 0x00000000
92#define HASHALG_SHA256 0x00000001
93#define HASHALG_SHA384 0x00000002
94#define HASHALG_SHA512 0x00000003
95#define HASHALG_RAW 0x00000004
96#define HASHALG_MAX 0x00000004
97
98//
99// Certificate public key minimum size (bytes)
100//
101#define CER_PUBKEY_MIN_SIZE 256
102
103//
104// Define KeyType for public key storing file
105//
106#define KEY_TYPE_RSASSA 0
107
108//
109// Types of errors may occur during certificate enrollment.
110//
111typedef enum {
112 None_Error = 0,
113 //
114 // Unsupported_type indicates the certificate type is not supported.
115 //
116 Unsupported_Type,
117 //
118 // Unqualified_key indicates the key strength of certificate is not
119 // strong enough.
120 //
121 Unqualified_Key,
122 Enroll_Error_Max
123} ENROLL_KEY_ERROR;
124
125typedef struct {
126 UINTN Signature;
127 LIST_ENTRY Head;
128 UINTN MenuNumber;
130
131typedef struct {
132 EFI_FILE_HANDLE FHandle;
133 UINT16 *FileName;
134 UINT8 FileType;
136
137#define SECUREBOOT_FREE_NON_NULL(Pointer) \
138 do { \
139 if ((Pointer) != NULL) { \
140 FreePool((Pointer)); \
141 (Pointer) = NULL; \
142 } \
143 } while (FALSE)
144
145#define SECUREBOOT_FREE_NON_OPCODE(Handle) \
146 do{ \
147 if ((Handle) != NULL) { \
148 HiiFreeOpCodeHandle((Handle)); \
149 } \
150 } while (FALSE)
151
152#define SIGNATURE_DATA_COUNTS(List) \
153 (((List)->SignatureListSize - sizeof(EFI_SIGNATURE_LIST) - (List)->SignatureHeaderSize) / (List)->SignatureSize)
154
155//
156// We define another format of 5th directory entry: security directory
157//
158typedef struct {
159 UINT32 Offset; // Offset of certificate
160 UINT32 SizeOfCert; // size of certificate appended
162
163typedef enum {
164 ImageType_IA32,
165 ImageType_X64
166} IMAGE_TYPE;
167
171typedef struct {
172 VENDOR_DEVICE_PATH VendorDevicePath;
175
176typedef enum {
177 Variable_DB,
178 Variable_DBX,
179 Variable_DBT,
180 Variable_MAX
181} CURRENT_VARIABLE_NAME;
182
183typedef enum {
184 Delete_Signature_List_All,
185 Delete_Signature_List_One,
186 Delete_Signature_Data
187} SIGNATURE_DELETE_TYPE;
188
189typedef struct {
190 UINTN Signature;
191
193 EFI_HII_HANDLE HiiHandle;
194 EFI_HANDLE DriverHandle;
195
196 SECUREBOOT_FILE_CONTEXT *FileContext;
197
198 EFI_GUID *SignatureGUID;
199
200 CURRENT_VARIABLE_NAME VariableName; // The variable name we are processing.
201 UINT32 ListCount; // Record current variable has how many signature list.
202 UINTN ListIndex; // Record which signature list is processing.
203 BOOLEAN *CheckArray; // Record which signature data checked.
205
206extern SECUREBOOT_CONFIG_PRIVATE_DATA mSecureBootConfigPrivateDateTemplate;
207extern SECUREBOOT_CONFIG_PRIVATE_DATA *gSecureBootPrivateData;
208
209#define SECUREBOOT_CONFIG_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('S', 'E', 'C', 'B')
210#define SECUREBOOT_CONFIG_PRIVATE_FROM_THIS(a) CR (a, SECUREBOOT_CONFIG_PRIVATE_DATA, ConfigAccess, SECUREBOOT_CONFIG_PRIVATE_DATA_SIGNATURE)
211
212//
213// Cryptographic Key Information
214//
215#pragma pack(1)
216typedef struct _CPL_KEY_INFO {
217 UINT32 KeyLengthInBits; // Key Length In Bits
218 UINT32 BlockSize; // Operation Block Size in Bytes
219 UINT32 CipherBlockSize; // Output Cipher Block Size in Bytes
220 UINT32 KeyType; // Key Type
221 UINT32 CipherMode; // Cipher Mode for Symmetric Algorithm
222 UINT32 Flags; // Additional Key Property Flags
224#pragma pack()
225
232typedef
234(EFIAPI *HASH_GET_CONTEXT_SIZE)(
235 VOID
236 );
237
250typedef
251BOOLEAN
252(EFIAPI *HASH_INIT)(
253 IN OUT VOID *HashContext
254 );
255
271typedef
272BOOLEAN
273(EFIAPI *HASH_UPDATE)(
274 IN OUT VOID *HashContext,
275 IN CONST VOID *Data,
276 IN UINTN DataLength
277 );
278
294typedef
295BOOLEAN
296(EFIAPI *HASH_FINAL)(
297 IN OUT VOID *HashContext,
298 OUT UINT8 *HashValue
299 );
300
301//
302// Hash Algorithm Table
303//
304typedef struct {
305 CHAR16 *Name;
306 UINTN DigestLength;
307 UINT8 *OidValue;
308 UINTN OidLength;
309 HASH_GET_CONTEXT_SIZE GetContextSize;
310 HASH_INIT HashInit;
312 HASH_FINAL HashFinal;
313} HASH_TABLE;
314
315typedef struct {
316 WIN_CERTIFICATE Hdr;
317 UINT8 CertData[1];
319
333 );
334
341VOID
344 );
345
373EFIAPI
376 IN CONST EFI_STRING Request,
377 OUT EFI_STRING *Progress,
378 OUT EFI_STRING *Results
379 );
380
400EFIAPI
403 IN CONST EFI_STRING Configuration,
404 OUT EFI_STRING *Progress
405 );
406
430EFIAPI
433 IN EFI_BROWSER_ACTION Action,
434 IN EFI_QUESTION_ID QuestionId,
435 IN UINT8 Type,
436 IN EFI_IFR_TYPE_VALUE *Value,
437 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
438 );
439
448CHAR16 *
449EFIAPI
452 );
453
461VOID
463 IN UINT16 LabelId,
465 );
466
485 IN EFI_FILE_HANDLE FileHandle,
486 IN OUT VOID **BufferPtr,
487 OUT UINTN *FileSize,
488 IN UINTN AdditionAllocateSize
489 );
490
497VOID
498CloseFile (
499 IN EFI_FILE_HANDLE FileHandle
500 );
501
517EFIAPI
519 IN CONST UINTN *Integer,
520 IN UINTN IntSizeInWords,
521 OUT UINT8 *OctetString,
522 IN UINTN OSSizeInBytes
523 );
524
535UINTN
537 IN EFI_GUID *Guid,
538 IN CHAR16 *Buffer,
539 IN UINTN BufferSize
540 );
541
550BOOLEAN
551EFIAPI
554 );
555
564BOOLEAN
565EFIAPI
568 );
569
578BOOLEAN
579EFIAPI
582 );
583
592BOOLEAN
593EFIAPI
596 );
597
606BOOLEAN
607EFIAPI
610 );
611
612#endif
UINT64 UINTN
EFI_STATUS EFIAPI HashUpdate(IN HASH_HANDLE HashHandle, IN VOID *DataToHash, IN UINTN DataToHashLen)
Definition: HashLibTdx.c:69
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
BOOLEAN EFIAPI UpdatePKFromFile(IN EFI_DEVICE_PATH_PROTOCOL *FilePath)
EFI_STATUS EFIAPI Int2OctStr(IN CONST UINTN *Integer, IN UINTN IntSizeInWords, OUT UINT8 *OctetString, IN UINTN OSSizeInBytes)
BOOLEAN EFIAPI UpdateDBTFromFile(IN EFI_DEVICE_PATH_PROTOCOL *FilePath)
UINTN GuidToString(IN EFI_GUID *Guid, IN CHAR16 *Buffer, IN UINTN BufferSize)
EFI_STATUS EFIAPI SecureBootExtractConfig(IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, IN CONST EFI_STRING Request, OUT EFI_STRING *Progress, OUT EFI_STRING *Results)
EFI_STATUS ReadFileContent(IN EFI_FILE_HANDLE FileHandle, IN OUT VOID **BufferPtr, OUT UINTN *FileSize, IN UINTN AdditionAllocateSize)
EFI_STATUS EFIAPI SecureBootRouteConfig(IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, IN CONST EFI_STRING Configuration, OUT EFI_STRING *Progress)
VOID CleanUpPage(IN UINT16 LabelId, IN SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData)
BOOLEAN(EFIAPI * HASH_UPDATE)(IN OUT VOID *HashContext, IN CONST VOID *Data, IN UINTN DataLength)
BOOLEAN EFIAPI UpdateDBXFromFile(IN EFI_DEVICE_PATH_PROTOCOL *FilePath)
VOID CloseFile(IN EFI_FILE_HANDLE FileHandle)
EFI_STATUS(EFIAPI * HASH_GET_CONTEXT_SIZE)(VOID)
BOOLEAN EFIAPI UpdateKEKFromFile(IN EFI_DEVICE_PATH_PROTOCOL *FilePath)
EFI_STATUS InstallSecureBootConfigForm(IN OUT SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData)
CHAR16 *EFIAPI DevicePathToStr(IN EFI_DEVICE_PATH_PROTOCOL *DevPath)
BOOLEAN(EFIAPI * HASH_INIT)(IN OUT VOID *HashContext)
EFI_STATUS EFIAPI SecureBootCallback(IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, IN EFI_BROWSER_ACTION Action, IN EFI_QUESTION_ID QuestionId, IN UINT8 Type, IN EFI_IFR_TYPE_VALUE *Value, OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest)
BOOLEAN EFIAPI UpdateDBFromFile(IN EFI_DEVICE_PATH_PROTOCOL *FilePath)
VOID UninstallSecureBootConfigForm(IN OUT SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData)
BOOLEAN(EFIAPI * HASH_FINAL)(IN OUT VOID *HashContext, OUT UINT8 *HashValue)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
VOID * EFI_HII_HANDLE
Definition: Base.h:213