60 CONST CHAR8 *Base64Cert;
61 CHAR8 OvmfPkKek1AppPrefix[GUID_STRING_LENGTH + 1 + 1];
64 EFI_SMBIOS_HANDLE Handle;
69 UINTN DecodedCertSize;
79 sizeof OvmfPkKek1AppPrefix,
81 &gOvmfPkKek1AppPrefixGuid
87 Status =
gBS->LocateProtocol (
88 &gEfiSmbiosProtocolGuid,
92 if (EFI_ERROR (Status)) {
93 AsciiPrint (
"error: failed to locate EFI_SMBIOS_PROTOCOL: %r\n", Status);
98 Type = SMBIOS_TYPE_OEM_STRINGS;
99 for (Status = Smbios->GetNext (Smbios, &Handle, &Type, &Header,
NULL);
101 Status = Smbios->GetNext (Smbios, &Handle, &Type, &Header,
NULL))
103 CONST CHAR8 *OemString;
106 if (Header->Length <
sizeof *OemStringsTable) {
119 OemString = (
CONST CHAR8 *)(OemStringsTable + 1);
120 for (Idx = 0; Idx < OemStringsTable->StringCount; ++Idx) {
121 CHAR8 CandidatePrefix[
sizeof OvmfPkKek1AppPrefix];
128 sizeof CandidatePrefix,
130 GUID_STRING_LENGTH + 1
132 if (
AsciiStriCmp (OvmfPkKek1AppPrefix, CandidatePrefix) == 0) {
136 Base64Cert = OemString + GUID_STRING_LENGTH + 1;
143 if (Idx < OemStringsTable->StringCount) {
151 if (EFI_ERROR (Status)) {
156 "error: OEM String with app prefix %g not found: %r\n",
157 &gOvmfPkKek1AppPrefixGuid,
160 return EFI_NOT_FOUND;
163 ASSERT (Base64Cert !=
NULL);
172 case EFI_BUFFER_TOO_SMALL:
173 ASSERT (DecodedCertSize > 0);
177 "error: empty certificate after app prefix %g\n",
178 &gOvmfPkKek1AppPrefixGuid
180 return EFI_PROTOCOL_ERROR;
183 "error: invalid base64 string after app prefix %g\n",
184 &gOvmfPkKek1AppPrefixGuid
186 return EFI_PROTOCOL_ERROR;
193 if (DecodedCert ==
NULL) {
194 AsciiPrint (
"error: failed to allocate memory\n");
195 return EFI_OUT_OF_RESOURCES;
209 *PkKek1 = DecodedCert;
210 *SizeOfPkKek1 = DecodedCertSize;
261 IN CHAR16 *VariableName,
281 DataSize =
sizeof *SingleHeader;
292 if ((CertSize == 0) ||
293 (CertSize > MAX_UINT32 -
sizeof *RepeatingHeader) ||
294 (DataSize > MAX_UINT32 -
sizeof *RepeatingHeader - CertSize))
296 Status = EFI_INVALID_PARAMETER;
300 DataSize +=
sizeof *RepeatingHeader + CertSize;
305 if (DataSize ==
sizeof *SingleHeader) {
306 Status = EFI_INVALID_PARAMETER;
309 if (EFI_ERROR (Status)) {
315 Status = EFI_OUT_OF_RESOURCES;
322 Status =
gRT->GetTime (&SingleHeader->TimeStamp,
NULL);
323 if (EFI_ERROR (Status)) {
327 SingleHeader->TimeStamp.Pad1 = 0;
328 SingleHeader->TimeStamp.Nanosecond = 0;
329 SingleHeader->TimeStamp.TimeZone = 0;
330 SingleHeader->TimeStamp.Daylight = 0;
331 SingleHeader->TimeStamp.Pad2 = 0;
333 SingleHeader->dwLength = DataSize -
sizeof SingleHeader->TimeStamp;
341 SingleHeader->dwLength =
sizeof *SingleHeader
342 -
sizeof SingleHeader->TimeStamp;
344 SingleHeader->wRevision = 0x0200;
345 SingleHeader->wCertificateType = WIN_CERT_TYPE_EFI_GUID;
346 CopyGuid (&SingleHeader->CertType, &gEfiCertPkcs7Guid);
347 Position +=
sizeof *SingleHeader;
361 CopyGuid (&RepeatingHeader->SignatureType, CertType);
362 RepeatingHeader->SignatureListSize =
363 (UINT32)(
sizeof *RepeatingHeader + CertSize);
364 RepeatingHeader->SignatureHeaderSize = 0;
365 RepeatingHeader->SignatureSize =
366 (UINT32)(
sizeof RepeatingHeader->SignatureOwner + CertSize);
367 CopyGuid (&RepeatingHeader->SignatureOwner, OwnerGuid);
368 Position +=
sizeof *RepeatingHeader;
370 CopyMem (Position, Cert, CertSize);
371 Position += CertSize;
376 ASSERT (Data + DataSize == Position);
378 Status =
gRT->SetVariable (
382 EFI_VARIABLE_BOOTSERVICE_ACCESS |
383 EFI_VARIABLE_RUNTIME_ACCESS |
393 if (EFI_ERROR (Status)) {
395 "error: %a(\"%s\", %g): %r\n",
447 IN CHAR16 *VariableName,
451 IN BOOLEAN AllowMissing
458 Status =
gRT->GetVariable (VariableName, VendorGuid,
NULL, &Size, Data);
459 if (EFI_ERROR (Status)) {
460 if ((Status == EFI_NOT_FOUND) && AllowMissing) {
466 "error: GetVariable(\"%s\", %g): %r\n",
474 if (Size != DataSize) {
476 "error: GetVariable(\"%s\", %g): expected size 0x%Lx, "
483 return EFI_PROTOCOL_ERROR;
523 &gEfiGlobalVariableGuid,
524 &Settings->SetupMode,
525 sizeof Settings->SetupMode,
528 if (EFI_ERROR (Status)) {
534 &gEfiGlobalVariableGuid,
535 &Settings->SecureBoot,
536 sizeof Settings->SecureBoot,
539 if (EFI_ERROR (Status)) {
545 &gEfiSecureBootEnableDisableGuid,
546 &Settings->SecureBootEnable,
547 sizeof Settings->SecureBootEnable,
550 if (EFI_ERROR (Status)) {
556 &gEfiCustomModeEnableGuid,
557 &Settings->CustomMode,
558 sizeof Settings->CustomMode,
561 if (EFI_ERROR (Status)) {
567 &gEfiGlobalVariableGuid,
568 &Settings->VendorKeys,
569 sizeof Settings->VendorKeys,
587 "info: SetupMode=%d SecureBoot=%d SecureBootEnable=%d "
588 "CustomMode=%d VendorKeys=%d\n",
590 Settings->SecureBoot,
591 Settings->SecureBootEnable,
592 Settings->CustomMode,
614 if ((Argc == 2) && (
StrCmp (Argv[1], L
"--no-default") == 0)) {
629 if (EFI_ERROR (Status)) {
635 if (Settings.SetupMode != 1) {
651 Status =
GetPkKek1 (&PkKek1, &SizeOfPkKek1);
652 if (EFI_ERROR (Status)) {
660 if (Settings.CustomMode != CUSTOM_SECURE_BOOT_MODE) {
661 Settings.CustomMode = CUSTOM_SECURE_BOOT_MODE;
662 Status =
gRT->SetVariable (
664 &gEfiCustomModeEnableGuid,
666 EFI_VARIABLE_BOOTSERVICE_ACCESS),
667 sizeof Settings.CustomMode,
670 if (EFI_ERROR (Status)) {
672 "error: SetVariable(\"%s\", %g): %r\n",
674 &gEfiCustomModeEnableGuid,
687 &gEfiImageSecurityDatabaseGuid,
697 &gEfiImageSecurityDatabaseGuid,
701 &gMicrosoftVendorGuid,
703 mSizeOfMicrosoftUefiCa,
704 &gMicrosoftVendorGuid,
709 if (EFI_ERROR (Status)) {
718 &gEfiImageSecurityDatabaseGuid,
721 mSizeOfSha256OfDevNull,
725 if (EFI_ERROR (Status)) {
735 &gEfiGlobalVariableGuid,
745 &gEfiGlobalVariableGuid,
752 &gMicrosoftVendorGuid,
757 if (EFI_ERROR (Status)) {
766 &gEfiGlobalVariableGuid,
770 &gEfiGlobalVariableGuid,
773 if (EFI_ERROR (Status)) {
781 Settings.CustomMode = STANDARD_SECURE_BOOT_MODE;
782 Status =
gRT->SetVariable (
784 &gEfiCustomModeEnableGuid,
786 sizeof Settings.CustomMode,
789 if (EFI_ERROR (Status)) {
791 "error: SetVariable(\"%s\", %g): %r\n",
793 &gEfiCustomModeEnableGuid,
831 if (EFI_ERROR (Status)) {
837 if ((Settings.SetupMode != 0) || (Settings.SecureBoot != 1) ||
838 (Settings.SecureBootEnable != 1) || (Settings.CustomMode != 0) ||
839 (Settings.VendorKeys != 0))
INTN EFIAPI AsciiStriCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString)
RETURN_STATUS EFIAPI AsciiStrnCpyS(OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source, IN UINTN Length)
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
RETURN_STATUS EFIAPI Base64Decode(IN CONST CHAR8 *Source OPTIONAL, IN UINTN SourceSize, OUT UINT8 *Destination OPTIONAL, IN OUT UINTN *DestinationSize)
UINTN EFIAPI AsciiStrSize(IN CONST CHAR8 *String)
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 ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID EFIAPI FreePool(IN VOID *Buffer)
STATIC EFI_STATUS GetPkKek1(OUT UINT8 **PkKek1, OUT UINTN *SizeOfPkKek1)
STATIC VOID PrintSettings(IN CONST SETTINGS *Settings)
STATIC EFI_STATUS GetSettings(OUT SETTINGS *Settings)
STATIC EFI_STATUS GetExact(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT VOID *Data, IN UINTN DataSize, IN BOOLEAN AllowMissing)
INTN EFIAPI ShellAppMain(IN UINTN Argc, IN CHAR16 **Argv)
STATIC EFI_STATUS EFIAPI EnrollListOfCerts(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN EFI_GUID *CertType,...)
#define EFI_SETUP_MODE_NAME
#define EFI_KEY_EXCHANGE_KEY_NAME
#define EFI_PLATFORM_KEY_NAME
#define EFI_VENDOR_KEYS_VARIABLE_NAME
#define EFI_SECURE_BOOT_MODE_NAME
#define EFI_IMAGE_SECURITY_DATABASE1
#define EFI_IMAGE_SECURITY_DATABASE
#define SMBIOS_HANDLE_PI_RESERVED
UINTN EFIAPI AsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
EFI_RUNTIME_SERVICES * gRT
#define VA_ARG(Marker, TYPE)
#define VA_START(Marker, Parameter)
#define ASSERT_EFI_ERROR(StatusParameter)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
UINTN EFIAPI AsciiPrint(IN CONST CHAR8 *Format,...)
#define EFI_VARIABLE_NON_VOLATILE
#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS