]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigImpl.h
IntelFsp2WrapperPkg: Remove unused header files from Fspm and Fsps WrapperPeim
[mirror_edk2.git] / SecurityPkg / VariableAuthenticated / SecureBootConfigDxe / SecureBootConfigImpl.h
CommitLineData
beda2356 1/** @file\r
2 The header file of HII Config Access protocol implementation of SecureBoot\r
3 configuration module.\r
4\r
762d8ddb 5Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>\r
bc0c99b3 6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
beda2356 9http://opensource.org/licenses/bsd-license.php\r
10\r
bc0c99b3 11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
beda2356 12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#ifndef __SECUREBOOT_CONFIG_IMPL_H__\r
17#define __SECUREBOOT_CONFIG_IMPL_H__\r
18\r
19#include <Uefi.h>\r
20\r
21#include <Protocol/HiiConfigAccess.h>\r
22#include <Protocol/HiiConfigRouting.h>\r
ecc722ad 23#include <Protocol/SimpleFileSystem.h>\r
24#include <Protocol/BlockIo.h>\r
25#include <Protocol/DevicePath.h>\r
ecc722ad 26#include <Protocol/DebugPort.h>\r
27#include <Protocol/LoadFile.h>\r
beda2356 28\r
29#include <Library/BaseLib.h>\r
30#include <Library/BaseMemoryLib.h>\r
31#include <Library/DebugLib.h>\r
32#include <Library/MemoryAllocationLib.h>\r
33#include <Library/UefiBootServicesTableLib.h>\r
34#include <Library/UefiRuntimeServicesTableLib.h>\r
35#include <Library/UefiHiiServicesLib.h>\r
36#include <Library/UefiLib.h>\r
37#include <Library/HiiLib.h>\r
38#include <Library/DevicePathLib.h>\r
bc0c99b3 39#include <Library/PrintLib.h>\r
ecc722ad 40#include <Library/PlatformSecureLib.h>\r
41#include <Library/BaseCryptLib.h>\r
762d8ddb
DB
42#include <Library/FileExplorerLib.h>\r
43\r
beda2356 44#include <Guid/MdeModuleHii.h>\r
45#include <Guid/AuthenticatedVariableFormat.h>\r
ecc722ad 46#include <Guid/FileSystemVolumeLabelInfo.h>\r
47#include <Guid/ImageAuthentication.h>\r
48#include <Guid/FileInfo.h>\r
beda2356 49\r
50#include "SecureBootConfigNvData.h"\r
51\r
52//\r
53// Tool generated IFR binary data and String package data\r
54//\r
ecc722ad 55extern UINT8 SecureBootConfigBin[];\r
56extern UINT8 SecureBootConfigDxeStrings[];\r
57\r
58//\r
59// Shared IFR form update data\r
60//\r
61extern VOID *mStartOpCodeHandle;\r
62extern VOID *mEndOpCodeHandle;\r
63extern EFI_IFR_GUID_LABEL *mStartLabel;\r
64extern EFI_IFR_GUID_LABEL *mEndLabel;\r
65\r
66#define MAX_CHAR 480\r
67#define TWO_BYTE_ENCODE 0x82\r
68\r
69//\r
70// SHA-1 digest size in bytes.\r
71//\r
72#define SHA1_DIGEST_SIZE 20\r
73//\r
74// SHA-256 digest size in bytes\r
75//\r
76#define SHA256_DIGEST_SIZE 32\r
77//\r
20333c6d 78// SHA-384 digest size in bytes\r
ecc722ad 79//\r
20333c6d
QL
80#define SHA384_DIGEST_SIZE 48\r
81//\r
82// SHA-512 digest size in bytes\r
83//\r
84#define SHA512_DIGEST_SIZE 64\r
85\r
86//\r
87// Set max digest size as SHA512 Output (64 bytes) by far\r
88//\r
89#define MAX_DIGEST_SIZE SHA512_DIGEST_SIZE\r
ecc722ad 90\r
91#define WIN_CERT_UEFI_RSA2048_SIZE 256\r
92\r
93//\r
94// Support hash types\r
95//\r
96#define HASHALG_SHA1 0x00000000\r
97#define HASHALG_SHA224 0x00000001\r
98#define HASHALG_SHA256 0x00000002\r
99#define HASHALG_SHA384 0x00000003\r
100#define HASHALG_SHA512 0x00000004\r
20333c6d 101#define HASHALG_RAW 0x00000005\r
ecc722ad 102#define HASHALG_MAX 0x00000005\r
103\r
104\r
ecc722ad 105typedef struct {\r
106 UINTN Signature;\r
107 LIST_ENTRY Head;\r
108 UINTN MenuNumber;\r
109} SECUREBOOT_MENU_OPTION;\r
110\r
ecc722ad 111typedef struct {\r
ecc722ad 112 EFI_FILE_HANDLE FHandle;\r
113 UINT16 *FileName;\r
ecc722ad 114} SECUREBOOT_FILE_CONTEXT;\r
115\r
116\r
117//\r
118// We define another format of 5th directory entry: security directory\r
119//\r
120typedef struct {\r
121 UINT32 Offset; // Offset of certificate\r
122 UINT32 SizeOfCert; // size of certificate appended\r
123} EFI_IMAGE_SECURITY_DATA_DIRECTORY;\r
124\r
125typedef enum{\r
126 ImageType_IA32,\r
127 ImageType_X64\r
128} IMAGE_TYPE;\r
beda2356 129\r
130///\r
131/// HII specific Vendor Device Path definition.\r
132///\r
133typedef struct {\r
134 VENDOR_DEVICE_PATH VendorDevicePath;\r
135 EFI_DEVICE_PATH_PROTOCOL End;\r
136} HII_VENDOR_DEVICE_PATH;\r
137\r
138typedef struct {\r
139 UINTN Signature;\r
140\r
141 EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess;\r
142 EFI_HII_HANDLE HiiHandle;\r
143 EFI_HANDLE DriverHandle;\r
144\r
ecc722ad 145 SECUREBOOT_FILE_CONTEXT *FileContext;\r
146\r
147 EFI_GUID *SignatureGUID;\r
beda2356 148} SECUREBOOT_CONFIG_PRIVATE_DATA;\r
149\r
150extern SECUREBOOT_CONFIG_PRIVATE_DATA mSecureBootConfigPrivateDateTemplate;\r
762d8ddb 151extern SECUREBOOT_CONFIG_PRIVATE_DATA *gSecureBootPrivateData;\r
beda2356 152\r
153#define SECUREBOOT_CONFIG_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('S', 'E', 'C', 'B')\r
bc0c99b3 154#define SECUREBOOT_CONFIG_PRIVATE_FROM_THIS(a) CR (a, SECUREBOOT_CONFIG_PRIVATE_DATA, ConfigAccess, SECUREBOOT_CONFIG_PRIVATE_DATA_SIGNATURE)\r
155\r
ecc722ad 156//\r
157// Cryptograhpic Key Information\r
158//\r
1413b8e9 159#pragma pack(1)\r
ecc722ad 160typedef struct _CPL_KEY_INFO {\r
161 UINT32 KeyLengthInBits; // Key Length In Bits\r
162 UINT32 BlockSize; // Operation Block Size in Bytes\r
163 UINT32 CipherBlockSize; // Output Cipher Block Size in Bytes\r
164 UINT32 KeyType; // Key Type\r
165 UINT32 CipherMode; // Cipher Mode for Symmetric Algorithm\r
166 UINT32 Flags; // Additional Key Property Flags\r
167} CPL_KEY_INFO;\r
1413b8e9 168#pragma pack()\r
ecc722ad 169\r
170\r
171/**\r
172 Retrieves the size, in bytes, of the context buffer required for hash operations.\r
173\r
174 @return The size, in bytes, of the context buffer required for hash operations.\r
175\r
176**/\r
177typedef\r
178EFI_STATUS\r
179(EFIAPI *HASH_GET_CONTEXT_SIZE)(\r
180 VOID\r
181 );\r
182\r
183/**\r
184 Initializes user-supplied memory pointed by HashContext as hash context for\r
185 subsequent use.\r
186\r
187 If HashContext is NULL, then ASSERT().\r
188\r
189 @param[in, out] HashContext Pointer to Context being initialized.\r
190\r
191 @retval TRUE HASH context initialization succeeded.\r
192 @retval FALSE HASH context initialization failed.\r
193\r
194**/\r
195typedef\r
196BOOLEAN\r
197(EFIAPI *HASH_INIT)(\r
198 IN OUT VOID *HashContext\r
199 );\r
200\r
201\r
202/**\r
203 Performs digest on a data buffer of the specified length. This function can\r
204 be called multiple times to compute the digest of long or discontinuous data streams.\r
205\r
206 If HashContext is NULL, then ASSERT().\r
207\r
208 @param[in, out] HashContext Pointer to the MD5 context.\r
209 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
210 @param[in] DataLength Length of Data buffer in bytes.\r
211\r
212 @retval TRUE HASH data digest succeeded.\r
213 @retval FALSE Invalid HASH context. After HashFinal function has been called, the\r
214 HASH context cannot be reused.\r
215\r
216**/\r
217typedef\r
218BOOLEAN\r
219(EFIAPI *HASH_UPDATE)(\r
220 IN OUT VOID *HashContext,\r
221 IN CONST VOID *Data,\r
222 IN UINTN DataLength\r
223 );\r
224\r
225/**\r
226 Completes hash computation and retrieves the digest value into the specified\r
227 memory. After this function has been called, the context cannot be used again.\r
228\r
229 If HashContext is NULL, then ASSERT().\r
230 If HashValue is NULL, then ASSERT().\r
231\r
232 @param[in, out] HashContext Pointer to the MD5 context\r
233 @param[out] HashValue Pointer to a buffer that receives the HASH digest\r
234 value (16 bytes).\r
235\r
236 @retval TRUE HASH digest computation succeeded.\r
237 @retval FALSE HASH digest computation failed.\r
238\r
239**/\r
240typedef\r
241BOOLEAN\r
242(EFIAPI *HASH_FINAL)(\r
243 IN OUT VOID *HashContext,\r
244 OUT UINT8 *HashValue\r
245 );\r
246\r
247//\r
248// Hash Algorithm Table\r
249//\r
250typedef struct {\r
251 CHAR16 *Name; ///< Name for Hash Algorithm\r
252 UINTN DigestLength; ///< Digest Length\r
20333c6d 253 UINT8 *OidValue; ///< Hash Algorithm OID ASN.1 Value\r
ecc722ad 254 UINTN OidLength; ///< Length of Hash OID Value\r
255 HASH_GET_CONTEXT_SIZE GetContextSize; ///< Pointer to Hash GetContentSize function\r
256 HASH_INIT HashInit; ///< Pointer to Hash Init function\r
257 HASH_UPDATE HashUpdate; ///< Pointer to Hash Update function\r
258 HASH_FINAL HashFinal; ///< Pointer to Hash Final function\r
259} HASH_TABLE;\r
260\r
261typedef struct {\r
262 WIN_CERTIFICATE Hdr;\r
263 UINT8 CertData[1];\r
264} WIN_CERTIFICATE_EFI_PKCS;\r
265\r
beda2356 266\r
267/**\r
268 This function publish the SecureBoot configuration Form.\r
269\r
270 @param[in, out] PrivateData Points to SecureBoot configuration private data.\r
271\r
ecc722ad 272 @retval EFI_SUCCESS HII Form is installed successfully.\r
beda2356 273 @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.\r
274 @retval Others Other errors as indicated.\r
275\r
276**/\r
277EFI_STATUS\r
278InstallSecureBootConfigForm (\r
279 IN OUT SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData\r
280 );\r
281\r
ecc722ad 282\r
beda2356 283/**\r
284 This function removes SecureBoot configuration Form.\r
285\r
286 @param[in, out] PrivateData Points to SecureBoot configuration private data.\r
287\r
288**/\r
beda2356 289VOID\r
290UninstallSecureBootConfigForm (\r
291 IN OUT SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData\r
292 );\r
293\r
ecc722ad 294\r
beda2356 295/**\r
296 This function allows a caller to extract the current configuration for one\r
297 or more named elements from the target driver.\r
298\r
299 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
300 @param[in] Request A null-terminated Unicode string in\r
301 <ConfigRequest> format.\r
302 @param[out] Progress On return, points to a character in the Request\r
303 string. Points to the string's null terminator if\r
304 request was successful. Points to the most recent\r
305 '&' before the first failing name/value pair (or\r
306 the beginning of the string if the failure is in\r
307 the first name/value pair) if the request was not\r
308 successful.\r
309 @param[out] Results A null-terminated Unicode string in\r
310 <ConfigAltResp> format which has all values filled\r
311 in for the names in the Request string. String to\r
312 be allocated by the called function.\r
313\r
314 @retval EFI_SUCCESS The Results is filled with the requested values.\r
315 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r
316 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.\r
317 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r
318 driver.\r
319\r
320**/\r
321EFI_STATUS\r
322EFIAPI\r
323SecureBootExtractConfig (\r
324 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
325 IN CONST EFI_STRING Request,\r
326 OUT EFI_STRING *Progress,\r
327 OUT EFI_STRING *Results\r
328 );\r
329\r
ecc722ad 330\r
beda2356 331/**\r
332 This function processes the results of changes in configuration.\r
333\r
334 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
335 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>\r
336 format.\r
337 @param[out] Progress A pointer to a string filled in with the offset of\r
338 the most recent '&' before the first failing\r
339 name/value pair (or the beginning of the string if\r
340 the failure is in the first name/value pair) or\r
341 the terminating NULL if all was successful.\r
342\r
343 @retval EFI_SUCCESS The Results is processed successfully.\r
344 @retval EFI_INVALID_PARAMETER Configuration is NULL.\r
345 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r
346 driver.\r
347\r
348**/\r
349EFI_STATUS\r
350EFIAPI\r
351SecureBootRouteConfig (\r
352 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
353 IN CONST EFI_STRING Configuration,\r
354 OUT EFI_STRING *Progress\r
355 );\r
356\r
ecc722ad 357\r
beda2356 358/**\r
359 This function processes the results of changes in configuration.\r
360\r
361 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
362 @param[in] Action Specifies the type of action taken by the browser.\r
363 @param[in] QuestionId A unique value which is sent to the original\r
364 exporting driver so that it can identify the type\r
365 of data to expect.\r
366 @param[in] Type The type of value for the question.\r
367 @param[in] Value A pointer to the data being sent to the original\r
368 exporting driver.\r
369 @param[out] ActionRequest On return, points to the action requested by the\r
370 callback function.\r
371\r
372 @retval EFI_SUCCESS The callback successfully handled the action.\r
373 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the\r
374 variable and its data.\r
375 @retval EFI_DEVICE_ERROR The variable could not be saved.\r
376 @retval EFI_UNSUPPORTED The specified Action is not supported by the\r
377 callback.\r
378\r
379**/\r
380EFI_STATUS\r
381EFIAPI\r
382SecureBootCallback (\r
383 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
384 IN EFI_BROWSER_ACTION Action,\r
385 IN EFI_QUESTION_ID QuestionId,\r
386 IN UINT8 Type,\r
387 IN EFI_IFR_TYPE_VALUE *Value,\r
388 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
389 );\r
390\r
ecc722ad 391\r
392/**\r
393 This function converts an input device structure to a Unicode string.\r
394\r
395 @param[in] DevPath A pointer to the device path structure.\r
396\r
397 @return A new allocated Unicode string that represents the device path.\r
398\r
399**/\r
400CHAR16 *\r
401EFIAPI\r
402DevicePathToStr (\r
403 IN EFI_DEVICE_PATH_PROTOCOL *DevPath\r
404 );\r
405\r
406\r
407/**\r
20333c6d 408 Clean up the dynamic opcode at label and form specified by both LabelId.\r
ecc722ad 409\r
410 @param[in] LabelId It is both the Form ID and Label ID for opcode deletion.\r
411 @param[in] PrivateData Module private data.\r
412\r
413**/\r
414VOID\r
415CleanUpPage (\r
416 IN UINT16 LabelId,\r
417 IN SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData\r
418 );\r
419\r
420\r
ecc722ad 421/**\r
20333c6d 422 Read file content into BufferPtr, the size of the allocate buffer\r
ecc722ad 423 is *FileSize plus AddtionAllocateSize.\r
424\r
425 @param[in] FileHandle The file to be read.\r
426 @param[in, out] BufferPtr Pointers to the pointer of allocated buffer.\r
427 @param[out] FileSize Size of input file\r
20333c6d 428 @param[in] AddtionAllocateSize Addtion size the buffer need to be allocated.\r
ecc722ad 429 In case the buffer need to contain others besides the file content.\r
20333c6d 430\r
ecc722ad 431 @retval EFI_SUCCESS The file was read into the buffer.\r
432 @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
433 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
434 @retval others Unexpected error.\r
435\r
436**/\r
437EFI_STATUS\r
438ReadFileContent (\r
439 IN EFI_FILE_HANDLE FileHandle,\r
440 IN OUT VOID **BufferPtr,\r
441 OUT UINTN *FileSize,\r
442 IN UINTN AddtionAllocateSize\r
443 );\r
444\r
445\r
446/**\r
447 Close an open file handle.\r
448\r
449 @param[in] FileHandle The file handle to close.\r
20333c6d 450\r
ecc722ad 451**/\r
452VOID\r
453CloseFile (\r
454 IN EFI_FILE_HANDLE FileHandle\r
455 );\r
456\r
457\r
458/**\r
459 Converts a nonnegative integer to an octet string of a specified length.\r
460\r
461 @param[in] Integer Pointer to the nonnegative integer to be converted\r
462 @param[in] IntSizeInWords Length of integer buffer in words\r
20333c6d 463 @param[out] OctetString Converted octet string of the specified length\r
ecc722ad 464 @param[in] OSSizeInBytes Intended length of resulting octet string in bytes\r
465\r
466Returns:\r
467\r
468 @retval EFI_SUCCESS Data conversion successfully\r
469 @retval EFI_BUFFER_TOOL_SMALL Buffer is too small for output string\r
470\r
471**/\r
472EFI_STATUS\r
473EFIAPI\r
474Int2OctStr (\r
475 IN CONST UINTN *Integer,\r
476 IN UINTN IntSizeInWords,\r
477 OUT UINT8 *OctetString,\r
478 IN UINTN OSSizeInBytes\r
479 );\r
480\r
481\r
482/**\r
483 Convert a String to Guid Value.\r
484\r
485 @param[in] Str Specifies the String to be converted.\r
486 @param[in] StrLen Number of Unicode Characters of String (exclusive \0)\r
487 @param[out] Guid Return the result Guid value.\r
488\r
489 @retval EFI_SUCCESS The operation is finished successfully.\r
490 @retval EFI_NOT_FOUND Invalid string.\r
491\r
492**/\r
493EFI_STATUS\r
494StringToGuid (\r
20333c6d
QL
495 IN CHAR16 *Str,\r
496 IN UINTN StrLen,\r
ecc722ad 497 OUT EFI_GUID *Guid\r
498 );\r
499\r
500\r
501/**\r
502 Worker function that prints an EFI_GUID into specified Buffer.\r
503\r
504 @param[in] Guid Pointer to GUID to print.\r
505 @param[in] Buffer Buffer to print Guid into.\r
506 @param[in] BufferSize Size of Buffer.\r
20333c6d 507\r
ecc722ad 508 @retval Number of characters printed.\r
509\r
510**/\r
511UINTN\r
512GuidToString (\r
513 IN EFI_GUID *Guid,\r
514 IN CHAR16 *Buffer,\r
515 IN UINTN BufferSize\r
516 );\r
517\r
762d8ddb
DB
518/**\r
519 Update the PK form base on the input file path info.\r
520\r
521 @param FilePath Point to the file path.\r
522\r
523 @retval TRUE Exit caller function.\r
524 @retval FALSE Not exit caller function.\r
525**/\r
526BOOLEAN\r
bac308be 527EFIAPI\r
762d8ddb
DB
528UpdatePKFromFile (\r
529 IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r
530 );\r
531\r
532/**\r
533 Update the KEK form base on the input file path info.\r
534\r
535 @param FilePath Point to the file path.\r
536\r
537 @retval TRUE Exit caller function.\r
538 @retval FALSE Not exit caller function.\r
539**/\r
540BOOLEAN\r
bac308be 541EFIAPI\r
762d8ddb
DB
542UpdateKEKFromFile (\r
543 IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r
544 );\r
545\r
546/**\r
547 Update the DB form base on the input file path info.\r
548\r
549 @param FilePath Point to the file path.\r
550\r
551 @retval TRUE Exit caller function.\r
552 @retval FALSE Not exit caller function.\r
553**/\r
554BOOLEAN\r
bac308be 555EFIAPI\r
762d8ddb
DB
556UpdateDBFromFile (\r
557 IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r
558 );\r
559\r
560/**\r
561 Update the DBX form base on the input file path info.\r
562\r
563 @param FilePath Point to the file path.\r
564\r
565 @retval TRUE Exit caller function.\r
566 @retval FALSE Not exit caller function.\r
567**/\r
568BOOLEAN\r
bac308be 569EFIAPI\r
762d8ddb
DB
570UpdateDBXFromFile (\r
571 IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r
572 );\r
573\r
574/**\r
575 Update the DBT form base on the input file path info.\r
576\r
577 @param FilePath Point to the file path.\r
578\r
579 @retval TRUE Exit caller function.\r
580 @retval FALSE Not exit caller function.\r
581**/\r
582BOOLEAN\r
bac308be 583EFIAPI\r
762d8ddb
DB
584UpdateDBTFromFile (\r
585 IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r
586 );\r
587\r
2e728930 588#endif\r