2 Enroll default PK, KEK, db, dbx.
4 Copyright (c) 2021, ARM Ltd. All rights reserved.<BR>
5 Copyright (c) 2021, Semihalf All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Guid/AuthenticatedVariableFormat.h> // gEfiCustomModeEnableGuid
11 #include <Guid/GlobalVariable.h> // EFI_SETUP_MODE_NAME
12 #include <Guid/ImageAuthentication.h> // EFI_IMAGE_SECURITY_DATABASE
13 #include <Library/BaseLib.h> // GUID_STRING_LENGTH
14 #include <Library/BaseMemoryLib.h> // CopyGuid()
15 #include <Library/DebugLib.h> // ASSERT()
16 #include <Library/MemoryAllocationLib.h> // FreePool()
17 #include <Library/PrintLib.h> // AsciiSPrint()
18 #include <Library/UefiBootServicesTableLib.h> // gBS
19 #include <Library/UefiLib.h> // AsciiPrint()
20 #include <Library/UefiRuntimeServicesTableLib.h> // gRT
21 #include <Uefi/UefiMultiPhase.h>
22 #include <Library/SecureBootVariableLib.h>
23 #include <Library/SecureBootVariableProvisionLib.h>
26 Entry point function of this shell application.
27 @param[in] ImageHandle The firmware allocated handle for the EFI image.
28 @param[in] SystemTable A pointer to the EFI System Table.
30 @retval 0 The entry point is executed successfully.
31 @retval other Some error occurs when executing this entry point.
36 IN EFI_HANDLE ImageHandle
,
37 IN EFI_SYSTEM_TABLE
*SystemTable
43 Status
= GetSetupMode (&SetupMode
);
44 if (EFI_ERROR (Status
)) {
45 AsciiPrint ("EnrollFromDefaultKeysApp: Cannot get SetupMode variable: %r\n", Status
);
49 if (SetupMode
== USER_MODE
) {
50 AsciiPrint ("EnrollFromDefaultKeysApp: Skipped - USER_MODE\n");
54 Status
= SetSecureBootMode (CUSTOM_SECURE_BOOT_MODE
);
55 if (EFI_ERROR (Status
)) {
56 AsciiPrint ("EnrollFromDefaultKeysApp: Cannot set CUSTOM_SECURE_BOOT_MODE: %r\n", Status
);
60 Status
= EnrollDbFromDefault ();
61 if (EFI_ERROR (Status
)) {
62 AsciiPrint ("EnrollFromDefaultKeysApp: Cannot enroll db: %r\n", Status
);
66 Status
= EnrollDbxFromDefault ();
67 if (EFI_ERROR (Status
)) {
68 AsciiPrint ("EnrollFromDefaultKeysApp: Cannot enroll dbt: %r\n", Status
);
71 Status
= EnrollDbtFromDefault ();
72 if (EFI_ERROR (Status
)) {
73 AsciiPrint ("EnrollFromDefaultKeysApp: Cannot enroll dbx: %r\n", Status
);
76 Status
= EnrollKEKFromDefault ();
77 if (EFI_ERROR (Status
)) {
78 AsciiPrint ("EnrollFromDefaultKeysApp: Cannot enroll KEK: %r\n", Status
);
82 Status
= EnrollPKFromDefault ();
83 if (EFI_ERROR (Status
)) {
84 AsciiPrint ("EnrollFromDefaultKeysApp: Cannot enroll PK: %r\n", Status
);
88 Status
= SetSecureBootMode (STANDARD_SECURE_BOOT_MODE
);
89 if (EFI_ERROR (Status
)) {
91 "EnrollFromDefaultKeysApp: Cannot set CustomMode to STANDARD_SECURE_BOOT_MODE\n"
92 "Please do it manually, otherwise system can be easily compromised\n"
107 Status
= SetSecureBootMode (STANDARD_SECURE_BOOT_MODE
);
108 if (EFI_ERROR (Status
)) {
110 "EnrollFromDefaultKeysApp: Cannot set CustomMode to STANDARD_SECURE_BOOT_MODE\n"
111 "Please do it manually, otherwise system can be easily compromised\n"