18CHAR16 mSecureBootStorageName[] = L
"SECUREBOOT_CONFIGURATION";
21 SECUREBOOT_CONFIG_PRIVATE_DATA_SIGNATURE,
39 SECUREBOOT_CONFIG_FORM_SET_GUID
43 END_ENTIRE_DEVICE_PATH_SUBTYPE,
45 (UINT8)(END_DEVICE_PATH_LENGTH),
46 (UINT8)((END_DEVICE_PATH_LENGTH) >> 8)
51BOOLEAN mIsEnterSecureBootForm =
FALSE;
56UINT8 mHashOidValue[] = {
57 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05,
58 0x2B, 0x0E, 0x03, 0x02, 0x1A,
59 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04,
60 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01,
61 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02,
62 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03,
75UINT32 mPeCoffHeaderOffset = 0;
78UINT8 *mImageBase =
NULL;
80UINT8 mImageDigest[MAX_DIGEST_SIZE];
81UINTN mImageDigestSize;
89CHAR16 *mDerEncodedSuffix[] = {
95CHAR16 *mSupportX509Suffix = L
"*.cer/der/crt";
100CHAR16 *mX509EnrollPromptTitle[] = {
102 L
"ERROR: Unsupported file type!",
103 L
"ERROR: Unsupported certificate!",
106CHAR16 *mX509EnrollPromptString[] = {
108 L
"Only DER encoded certificate file (*.cer/der/crt) is supported.",
109 L
"Public key length should be equal to or greater than 2048 bits.",
127 if (FileContext->FHandle !=
NULL) {
129 FileContext->FHandle =
NULL;
132 if (FileContext->FileName !=
NULL) {
134 FileContext->FileName =
NULL;
137 FileContext->FileType = UNKNOWN_FILE_TYPE;
156 return EFI_INVALID_PARAMETER;
159 Status =
gBS->LocateProtocol (&gEfiRealTimeClockArchProtocolGuid,
NULL, &TestPointer);
160 if (EFI_ERROR (Status)) {
165 Status =
gRT->GetTime (Time,
NULL);
166 if (EFI_ERROR (Status)) {
169 "%a(), GetTime() failed, status = '%r'\n",
177 Time->Nanosecond = 0;
201 for (Index = 0; mDerEncodedSuffix[Index] !=
NULL; Index++) {
202 if (
StrCmp (FileSuffix, mDerEncodedSuffix[Index]) == 0) {
227 BOOLEAN IsAuth2Format;
229 IsAuth2Format =
FALSE;
236 (VOID **)&mImageBase,
240 if (EFI_ERROR (Status)) {
250 IsAuth2Format =
TRUE;
257 if (mImageBase !=
NULL) {
262 return IsAuth2Format;
281 Status =
gRT->SetVariable (
283 &gEfiSecureBootEnableDisableGuid,
307 OUT ENROLL_KEY_ERROR *Error
318 if (X509FileContext->FileName ==
NULL) {
319 *Error = Unsupported_Type;
320 return EFI_INVALID_PARAMETER;
331 NameLength =
StrLen (X509FileContext->FileName);
332 if (NameLength <= 4) {
333 DEBUG ((DEBUG_ERROR,
"Wrong X509 NameLength\n"));
334 *Error = Unsupported_Type;
335 return EFI_INVALID_PARAMETER;
338 FilePostFix = X509FileContext->FileName + NameLength - 4;
340 DEBUG ((DEBUG_ERROR,
"Unsupported file type, only DER encoded certificate (%s) is supported.\n", mSupportX509Suffix));
341 *Error = Unsupported_Type;
342 return EFI_INVALID_PARAMETER;
345 DEBUG ((DEBUG_INFO,
"FileName= %s\n", X509FileContext->FileName));
346 DEBUG ((DEBUG_INFO,
"FilePostFix = %s\n", FilePostFix));
351 Status =
ReadFileContent (X509FileContext->FHandle, (VOID **)&X509Data, &X509DataSize, 0);
352 if (EFI_ERROR (Status)) {
353 DEBUG ((DEBUG_ERROR,
"Error occured while reading the file.\n"));
361 DEBUG ((DEBUG_ERROR,
"Error occured while parsing the pubkey from certificate.\n"));
362 Status = EFI_INVALID_PARAMETER;
363 *Error = Unsupported_Type;
371 if (X509PubKey !=
NULL) {
373 if (PubKeyModSize < CER_PUBKEY_MIN_SIZE) {
374 DEBUG ((DEBUG_ERROR,
"Unqualified PK size, key size should be equal to or greater than 2048 bits.\n"));
375 Status = EFI_INVALID_PARAMETER;
376 *Error = Unqualified_Key;
383 if (X509Data !=
NULL) {
415 Status =
ReadFileContent (X509File, (VOID **)&X509Data, &X509DataSize, 0);
416 if (EFI_ERROR (Status)) {
420 ASSERT (X509Data !=
NULL);
430 if (*PkCert ==
NULL) {
431 Status = EFI_OUT_OF_RESOURCES;
439 (*PkCert)->SignatureHeaderSize = 0;
440 CopyGuid (&(*PkCert)->SignatureType, &gEfiCertX509Guid);
443 + (*PkCert)->SignatureHeaderSize);
452 if (X509Data !=
NULL) {
456 if (EFI_ERROR (Status) && (*PkCert !=
NULL)) {
490 if (EFI_ERROR (Status)) {
498 Private->FileContext->FHandle,
501 if (EFI_ERROR (Status)) {
505 ASSERT (PkCert !=
NULL);
514 if (EFI_ERROR (Status)) {
515 DEBUG ((DEBUG_ERROR,
"Fail to fetch valid time data: %r", Status));
520 if (EFI_ERROR (Status)) {
521 DEBUG ((DEBUG_ERROR,
"Fail to create time-based data payload: %r", Status));
525 Status =
gRT->SetVariable (
527 &gEfiGlobalVariableGuid,
532 if (EFI_ERROR (Status)) {
533 if (Status == EFI_OUT_OF_RESOURCES) {
534 DEBUG ((DEBUG_ERROR,
"Enroll PK failed with out of resource.\n"));
542 if (PkCert !=
NULL) {
575 UINTN KekSigListSize;
595 Private->FileContext->FHandle,
600 if (EFI_ERROR (Status)) {
604 ASSERT (KeyBlob !=
NULL);
606 if (KeyInfo->KeyLengthInBits / 8 != WIN_CERT_UEFI_RSA2048_SIZE) {
607 DEBUG ((DEBUG_ERROR,
"Unsupported key length, Only RSA2048 is supported.\n"));
608 Status = EFI_UNSUPPORTED;
615 KeyLenInBytes = KeyInfo->KeyLengthInBits / 8;
617 if (KeyBuffer ==
NULL) {
618 Status = EFI_OUT_OF_RESOURCES;
624 KeyLenInBytes /
sizeof (
UINTN),
635 + WIN_CERT_UEFI_RSA2048_SIZE;
638 if (KekSigList ==
NULL) {
639 Status = EFI_OUT_OF_RESOURCES;
645 + WIN_CERT_UEFI_RSA2048_SIZE;
655 WIN_CERT_UEFI_RSA2048_SIZE
666 if (EFI_ERROR (Status)) {
667 DEBUG ((DEBUG_ERROR,
"Fail to fetch valid time data: %r", Status));
672 if (EFI_ERROR (Status)) {
673 DEBUG ((DEBUG_ERROR,
"Fail to create time-based data payload: %r", Status));
677 Status =
gRT->GetVariable (
679 &gEfiGlobalVariableGuid,
684 if (Status == EFI_BUFFER_TOO_SMALL) {
685 Attr |= EFI_VARIABLE_APPEND_WRITE;
686 }
else if (Status != EFI_NOT_FOUND) {
693 Status =
gRT->SetVariable (
695 &gEfiGlobalVariableGuid,
700 if (EFI_ERROR (Status)) {
708 if (Private->SignatureGUID !=
NULL) {
710 Private->SignatureGUID =
NULL;
713 if (KeyBlob !=
NULL) {
717 if (KeyBuffer !=
NULL) {
721 if (KekSigList !=
NULL) {
750 UINTN KekSigListSize;
762 Private->FileContext->FHandle,
767 if (EFI_ERROR (Status)) {
771 ASSERT (X509Data !=
NULL);
775 if (KekSigList ==
NULL) {
776 Status = EFI_OUT_OF_RESOURCES;
800 if (EFI_ERROR (Status)) {
801 DEBUG ((DEBUG_ERROR,
"Fail to fetch valid time data: %r", Status));
806 if (EFI_ERROR (Status)) {
807 DEBUG ((DEBUG_ERROR,
"Fail to create time-based data payload: %r", Status));
811 Status =
gRT->GetVariable (
813 &gEfiGlobalVariableGuid,
818 if (Status == EFI_BUFFER_TOO_SMALL) {
819 Attr |= EFI_VARIABLE_APPEND_WRITE;
820 }
else if (Status != EFI_NOT_FOUND) {
824 Status =
gRT->SetVariable (
826 &gEfiGlobalVariableGuid,
831 if (EFI_ERROR (Status)) {
839 if (Private->SignatureGUID !=
NULL) {
841 Private->SignatureGUID =
NULL;
844 if (KekSigList !=
NULL) {
871 if ((Private->FileContext->FHandle ==
NULL) || (Private->FileContext->FileName ==
NULL) || (Private->SignatureGUID ==
NULL)) {
872 return EFI_INVALID_PARAMETER;
876 if (EFI_ERROR (Status)) {
884 NameLength =
StrLen (Private->FileContext->FileName);
885 if (NameLength <= 4) {
886 return EFI_INVALID_PARAMETER;
889 FilePostFix = Private->FileContext->FileName + NameLength - 4;
892 }
else if (
CompareMem (FilePostFix, L
".pbk", 4) == 0) {
900 return EFI_INVALID_PARAMETER;
919 IN CHAR16 *VariableName
938 SigDBCertData =
NULL;
942 Private->FileContext->FHandle,
947 if (EFI_ERROR (Status)) {
951 ASSERT (X509Data !=
NULL);
957 Status = EFI_OUT_OF_RESOURCES;
982 if (EFI_ERROR (Status)) {
983 DEBUG ((DEBUG_ERROR,
"Fail to fetch valid time data: %r", Status));
988 if (EFI_ERROR (Status)) {
989 DEBUG ((DEBUG_ERROR,
"Fail to create time-based data payload: %r", Status));
993 Status =
gRT->GetVariable (
995 &gEfiImageSecurityDatabaseGuid,
1000 if (Status == EFI_BUFFER_TOO_SMALL) {
1001 Attr |= EFI_VARIABLE_APPEND_WRITE;
1002 }
else if (Status != EFI_NOT_FOUND) {
1006 Status =
gRT->SetVariable (
1008 &gEfiImageSecurityDatabaseGuid,
1013 if (EFI_ERROR (Status)) {
1021 if (Private->SignatureGUID !=
NULL) {
1023 Private->SignatureGUID =
NULL;
1030 if (X509Data !=
NULL) {
1050 IN CHAR16 *VariableName,
1051 IN UINT8 *Signature,
1070 Status =
gRT->GetVariable (VariableName, &gEfiImageSecurityDatabaseGuid,
NULL, &DataSize,
NULL);
1071 if (Status != EFI_BUFFER_TOO_SMALL) {
1080 Status =
gRT->GetVariable (VariableName, &gEfiImageSecurityDatabaseGuid,
NULL, &DataSize, Data);
1081 if (EFI_ERROR (Status)) {
1093 for (Index = 0; Index < CertCount; Index++) {
1151 if (HashAlg >= HASHALG_MAX) {
1158 if (!
X509GetTBSCert (CertData, CertSize, &TBSCert, &TBSCertSize)) {
1167 ASSERT (HashCtx !=
NULL);
1172 Status = mHash[HashAlg].
HashInit (HashCtx);
1180 Status = mHash[HashAlg].
HashUpdate (HashCtx, TBSCert, TBSCertSize);
1188 ZeroMem (CertHash, mHash[HashAlg].DigestLength);
1189 Status = mHash[HashAlg].
HashFinal (HashCtx, CertHash);
1192 if (HashCtx !=
NULL) {
1211 IN UINT8 *Certificate,
1219 UINTN CertHashCount;
1222 UINT8 CertDigest[MAX_DIGEST_SIZE];
1224 UINTN SiglistHeaderSize;
1229 HashAlg = HASHALG_MAX;
1237 if (Status != EFI_BUFFER_TOO_SMALL) {
1247 if (EFI_ERROR (Status)) {
1260 HashAlg = HASHALG_SHA256;
1262 HashAlg = HASHALG_SHA384;
1264 HashAlg = HASHALG_SHA512;
1281 for (Index = 0; Index < CertHashCount; Index++) {
1286 if (
CompareMem (DbxCertHash, CertDigest, mHash[HashAlg].DigestLength) == 0) {
1335 if ((Database ==
NULL) || (DatabaseSize == 0)) {
1341 SiglistSize = DatabaseSize;
1344 *Offset = DatabaseSize - SiglistSize;
1377 IN BOOLEAN AlwaysRevocation
1384 UINTN SignatureListSize;
1391 UINTN SignatureSize;
1394 UINT8 CertHash[MAX_DIGEST_SIZE];
1395 UINT16 *FilePostFix;
1403 SignatureData =
NULL;
1404 SignatureList =
NULL;
1408 if ((Private->FileContext->FileName ==
NULL) || (Private->FileContext->FHandle ==
NULL) || (Private->SignatureGUID ==
NULL)) {
1409 return EFI_INVALID_PARAMETER;
1413 if (EFI_ERROR (Status)) {
1420 NameLength =
StrLen (Private->FileContext->FileName);
1421 if (NameLength <= 4) {
1422 return EFI_INVALID_PARAMETER;
1425 FilePostFix = Private->FileContext->FileName + NameLength - 4;
1430 return EFI_INVALID_PARAMETER;
1437 Private->FileContext->FHandle,
1442 if (EFI_ERROR (Status)) {
1446 ASSERT (X509Data !=
NULL);
1457 if (Status == EFI_BUFFER_TOO_SMALL) {
1460 return EFI_OUT_OF_RESOURCES;
1464 if (EFI_ERROR (Status)) {
1474 if (SignatureData ==
NULL) {
1475 return EFI_OUT_OF_RESOURCES;
1484 if (!AlwaysRevocation) {
1486 Time->Year = RevocationDate->Year;
1487 Time->Month = RevocationDate->Month;
1488 Time->Day = RevocationDate->Day;
1489 Time->Hour = RevocationTime->Hour;
1490 Time->Minute = RevocationTime->Minute;
1491 Time->Second = RevocationTime->Second;
1498 case HASHALG_SHA256:
1499 SignatureType = gEfiCertX509Sha256Guid;
1501 case HASHALG_SHA384:
1502 SignatureType = gEfiCertX509Sha384Guid;
1504 case HASHALG_SHA512:
1505 SignatureType = gEfiCertX509Sha512Guid;
1518 DbSize = DataSize + SignatureSize;
1520 if (NewData ==
NULL) {
1521 Status = EFI_OUT_OF_RESOURCES;
1527 CopyMem (NewData, Data, Offset + SignatureListSize);
1532 Offset += SignatureListSize;
1533 CopyMem (NewData + Offset, SignatureData, SignatureSize);
1534 CopyMem (NewData + Offset + SignatureSize, Data + Offset, DataSize - Offset);
1545 if (NewData ==
NULL) {
1546 Status = EFI_OUT_OF_RESOURCES;
1559 if ((DataSize != 0) && (Data !=
NULL)) {
1560 CopyMem (NewData, Data, DataSize);
1569 if (EFI_ERROR (Status)) {
1570 DEBUG ((DEBUG_ERROR,
"Fail to fetch valid time data: %r", Status));
1575 if (EFI_ERROR (Status)) {
1581 Status =
gRT->SetVariable (
1583 &gEfiImageSecurityDatabaseGuid,
1588 if (EFI_ERROR (Status)) {
1596 if (Private->SignatureGUID !=
NULL) {
1598 Private->SignatureGUID =
NULL;
1605 if (SignatureData !=
NULL) {
1609 if (X509Data !=
NULL) {
1629 IN CHAR16 *VariableName
1643 Private->FileContext->FHandle,
1648 if (EFI_ERROR (Status)) {
1670 if (X509Data !=
NULL) {
1695 IN VOID *FileHandle,
1703 if ((FileHandle ==
NULL) || (ReadSize ==
NULL) || (Buffer ==
NULL)) {
1704 return EFI_INVALID_PARAMETER;
1708 return EFI_INVALID_PARAMETER;
1711 EndPosition = FileOffset + *ReadSize;
1712 if (EndPosition > mImageSize) {
1713 *ReadSize = (UINT32)(mImageSize - FileOffset);
1716 if (FileOffset >= mImageSize) {
1720 CopyMem (Buffer, (UINT8 *)((
UINTN)FileHandle + FileOffset), *ReadSize);
1747 ZeroMem (&ImageContext,
sizeof (ImageContext));
1748 ImageContext.
Handle = (VOID *)mImageBase;
1755 if (EFI_ERROR (Status)) {
1759 DEBUG ((DEBUG_INFO,
"SecureBootConfigDxe: PeImage invalid. \n"));
1767 if (DosHdr->
e_magic == EFI_IMAGE_DOS_SIGNATURE) {
1772 mPeCoffHeaderOffset = DosHdr->
e_lfanew;
1774 mPeCoffHeaderOffset = 0;
1781 if (NtHeader32->Signature != EFI_IMAGE_NT_SIGNATURE) {
1782 return EFI_UNSUPPORTED;
1785 mNtHeader.Pe32 = NtHeader32;
1798 mImageType = ImageType_IA32;
1807 mImageType = ImageType_X64;
1811 return EFI_UNSUPPORTED;
1841 UINTN SumOfBytesHashed;
1847 SectionHeader =
NULL;
1850 if ((HashAlg >= HASHALG_MAX)) {
1857 ZeroMem (mImageDigest, MAX_DIGEST_SIZE);
1860 case HASHALG_SHA256:
1862 mCertType = gEfiCertSha256Guid;
1865 case HASHALG_SHA384:
1867 mCertType = gEfiCertSha384Guid;
1870 case HASHALG_SHA512:
1872 mCertType = gEfiCertSha512Guid;
1882 ASSERT (HashCtx !=
NULL);
1887 Status = mHash[HashAlg].
HashInit (HashCtx);
1901 HashBase = mImageBase;
1906 HashSize = (
UINTN)(&mNtHeader.Pe32->OptionalHeader.CheckSum) - (
UINTN)HashBase;
1911 HashSize = (
UINTN)(&mNtHeader.Pe32Plus->OptionalHeader.CheckSum) - (
UINTN)HashBase;
1914 Status = mHash[HashAlg].
HashUpdate (HashCtx, HashBase, HashSize);
1928 HashBase = (UINT8 *)&mNtHeader.Pe32->OptionalHeader.CheckSum + sizeof (UINT32);
1929 HashSize = (
UINTN)(&mNtHeader.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY]) - (
UINTN)HashBase;
1934 HashBase = (UINT8 *)&mNtHeader.Pe32Plus->OptionalHeader.CheckSum + sizeof (UINT32);
1935 HashSize = (
UINTN)(&mNtHeader.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY]) - (
UINTN)HashBase;
1938 Status = mHash[HashAlg].
HashUpdate (HashCtx, HashBase, HashSize);
1951 HashBase = (UINT8 *)&mNtHeader.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY + 1];
1952 HashSize = mNtHeader.Pe32->OptionalHeader.SizeOfHeaders - ((
UINTN)(&mNtHeader.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY + 1]) - (
UINTN)mImageBase);
1957 HashBase = (UINT8 *)&mNtHeader.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY + 1];
1958 HashSize = mNtHeader.Pe32Plus->OptionalHeader.SizeOfHeaders - ((
UINTN)(&mNtHeader.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY + 1]) - (
UINTN)mImageBase);
1961 Status = mHash[HashAlg].
HashUpdate (HashCtx, HashBase, HashSize);
1973 SumOfBytesHashed = mNtHeader.Pe32->OptionalHeader.SizeOfHeaders;
1978 SumOfBytesHashed = mNtHeader.Pe32Plus->OptionalHeader.SizeOfHeaders;
1988 ASSERT (SectionHeader !=
NULL);
1997 mPeCoffHeaderOffset +
2000 mNtHeader.Pe32->FileHeader.SizeOfOptionalHeader
2002 for (Index = 0; Index < mNtHeader.Pe32->FileHeader.NumberOfSections; Index++) {
2004 while ((Pos > 0) && (Section->PointerToRawData < SectionHeader[Pos - 1].PointerToRawData)) {
2020 for (Index = 0; Index < mNtHeader.Pe32->FileHeader.NumberOfSections; Index++) {
2021 Section = &SectionHeader[Index];
2022 if (Section->SizeOfRawData == 0) {
2026 HashBase = mImageBase + Section->PointerToRawData;
2027 HashSize = (
UINTN)Section->SizeOfRawData;
2029 Status = mHash[HashAlg].
HashUpdate (HashCtx, HashBase, HashSize);
2034 SumOfBytesHashed += HashSize;
2043 if (mImageSize > SumOfBytesHashed) {
2044 HashBase = mImageBase + SumOfBytesHashed;
2051 mNtHeader.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY].Size -
2059 mNtHeader.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY].Size -
2063 Status = mHash[HashAlg].
HashUpdate (HashCtx, HashBase, HashSize);
2069 Status = mHash[HashAlg].
HashFinal (HashCtx, mImageDigest);
2072 if (HashCtx !=
NULL) {
2076 if (SectionHeader !=
NULL) {
2102 for (Index = 0; Index < HASHALG_MAX; Index++) {
2115 if ((*(PkcsCertData->CertData + 1) & TWO_BYTE_ENCODE) != TWO_BYTE_ENCODE) {
2128 if (Index == HASHALG_MAX) {
2129 return EFI_UNSUPPORTED;
2136 return EFI_UNSUPPORTED;
2159 IN CHAR16 *VariableName
2173 return EFI_UNSUPPORTED;
2180 Private->FileContext->FHandle,
2181 (VOID **)&mImageBase,
2185 if (EFI_ERROR (Status)) {
2189 ASSERT (mImageBase !=
NULL);
2200 Status =
gRT->GetVariable (
2202 &gEfiImageSecurityDatabaseGuid,
2207 if (Status == EFI_BUFFER_TOO_SMALL) {
2208 Attr |= EFI_VARIABLE_APPEND_WRITE;
2209 }
else if (Status != EFI_NOT_FOUND) {
2216 Status =
gRT->SetVariable (
2218 &gEfiImageSecurityDatabaseGuid,
2224 DEBUG ((DEBUG_INFO,
"Enroll AUTH_2 data to Var:%s Status: %x\n", VariableName, Status));
2234 if (mImageBase !=
NULL) {
2259 IN CHAR16 *VariableName
2274 GuidCertData =
NULL;
2277 return EFI_UNSUPPORTED;
2293 Private->FileContext->FHandle,
2294 (VOID **)&mImageBase,
2298 if (EFI_ERROR (Status)) {
2302 ASSERT (mImageBase !=
NULL);
2305 if (EFI_ERROR (Status)) {
2309 if (mSecDataDir->SizeOfCert == 0) {
2310 Status = EFI_SECURITY_VIOLATION;
2311 HashAlg =
sizeof (mHash) /
sizeof (
HASH_TABLE);
2312 while (HashAlg > 0) {
2324 if (EFI_ERROR (Status)) {
2325 DEBUG ((DEBUG_ERROR,
"Fail to get hash digest: %r", Status));
2337 Status = EFI_ABORTED;
2342 Status = EFI_ABORTED;
2345 }
else if (mCertificate->
wCertificateType == WIN_CERT_TYPE_PKCS_SIGNED_DATA) {
2347 if (EFI_ERROR (Status)) {
2351 Status = EFI_ABORTED;
2361 + (UINT32)mImageDigestSize;
2365 Status = EFI_OUT_OF_RESOURCES;
2385 if (EFI_ERROR (Status)) {
2386 DEBUG ((DEBUG_ERROR,
"Fail to fetch valid time data: %r", Status));
2391 if (EFI_ERROR (Status)) {
2392 DEBUG ((DEBUG_ERROR,
"Fail to create time-based data payload: %r", Status));
2402 Status =
gRT->GetVariable (
2404 &gEfiImageSecurityDatabaseGuid,
2409 if (Status == EFI_BUFFER_TOO_SMALL) {
2410 Attr |= EFI_VARIABLE_APPEND_WRITE;
2411 }
else if (Status != EFI_NOT_FOUND) {
2418 Status =
gRT->SetVariable (
2420 &gEfiImageSecurityDatabaseGuid,
2425 if (EFI_ERROR (Status)) {
2433 if (Private->SignatureGUID !=
NULL) {
2435 Private->SignatureGUID =
NULL;
2442 if (mImageBase !=
NULL) {
2466 IN CHAR16 *VariableName
2469 UINT16 *FilePostFix;
2473 if ((Private->FileContext->FileName ==
NULL) || (Private->FileContext->FHandle ==
NULL) || (Private->SignatureGUID ==
NULL)) {
2474 return EFI_INVALID_PARAMETER;
2478 if (EFI_ERROR (Status)) {
2485 NameLength =
StrLen (Private->FileContext->FileName);
2486 if (NameLength <= 4) {
2487 return EFI_INVALID_PARAMETER;
2490 FilePostFix = Private->FileContext->FileName + NameLength - 4;
2521 IN CHAR16 *VariableName,
2523 IN UINT16 LabelNumber,
2524 IN EFI_FORM_ID FormId,
2525 IN EFI_QUESTION_ID QuestionIdBase
2532 VOID *StartOpCodeHandle;
2533 VOID *EndOpCodeHandle;
2540 UINT32 ItemDataSize;
2542 EFI_STRING_ID GuidID;
2549 StartOpCodeHandle =
NULL;
2550 EndOpCodeHandle =
NULL;
2556 if (StartOpCodeHandle ==
NULL) {
2557 Status = EFI_OUT_OF_RESOURCES;
2562 if (EndOpCodeHandle ==
NULL) {
2563 Status = EFI_OUT_OF_RESOURCES;
2577 StartLabel->
Number = LabelNumber;
2586 EndLabel->
Number = LABEL_END;
2592 Status =
gRT->GetVariable (VariableName, VendorGuid,
NULL, &DataSize, Data);
2593 if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
2599 Status = EFI_OUT_OF_RESOURCES;
2603 Status =
gRT->GetVariable (VariableName, VendorGuid,
NULL, &DataSize, Data);
2604 if (EFI_ERROR (Status)) {
2609 if (GuidStr ==
NULL) {
2610 Status = EFI_OUT_OF_RESOURCES;
2617 ItemDataSize = (UINT32)DataSize;
2623 Help =
STRING_TOKEN (STR_CERT_TYPE_RSA2048_SHA256_GUID);
2646 for (Index = 0; Index < CertCount; Index++) {
2658 (EFI_QUESTION_ID)(QuestionIdBase + GuidIndex++),
2663 EFI_IFR_FLAG_CALLBACK,
2675 PrivateData->HiiHandle,
2676 &gSecureBootConfigFormSetGuid,
2682 if (StartOpCodeHandle !=
NULL) {
2686 if (EndOpCodeHandle !=
NULL) {
2694 if (GuidStr !=
NULL) {
2714 IN EFI_QUESTION_ID QuestionId
2728 BOOLEAN IsKEKItemFound;
2730 UINTN DeleteKekIndex;
2739 DeleteKekIndex = QuestionId - OPTION_DEL_KEK_QUESTION_ID;
2742 if (EFI_ERROR (Status)) {
2751 if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
2756 if (OldData ==
NULL) {
2757 Status = EFI_OUT_OF_RESOURCES;
2762 if (EFI_ERROR (Status)) {
2771 Status = EFI_OUT_OF_RESOURCES;
2778 IsKEKItemFound =
FALSE;
2779 KekDataSize = (UINT32)DataSize;
2792 for (Index = 0; Index < CertCount; Index++) {
2793 if (GuidIndex == DeleteKekIndex ) {
2798 IsKEKItemFound =
TRUE;
2822 if (!IsKEKItemFound) {
2826 Status = EFI_NOT_FOUND;
2833 KekDataSize = Offset;
2836 ZeroMem (OldData, KekDataSize);
2839 DEBUG ((DEBUG_INFO,
" CertCount = %x\n", CertCount));
2840 if (CertCount != 0) {
2852 if (EFI_ERROR (Status)) {
2853 DEBUG ((DEBUG_ERROR,
"Fail to fetch valid time data: %r", Status));
2858 if (EFI_ERROR (Status)) {
2859 DEBUG ((DEBUG_ERROR,
"Fail to create time-based data payload: %r", Status));
2864 Status =
gRT->SetVariable (
2866 &gEfiGlobalVariableGuid,
2871 if (EFI_ERROR (Status)) {
2872 DEBUG ((DEBUG_ERROR,
"Failed to set variable, Status = %r\n", Status));
2881 if (OldData !=
NULL) {
2888 &gEfiGlobalVariableGuid,
2890 FORMID_DELETE_KEK_FORM,
2891 OPTION_DEL_KEK_QUESTION_ID
2913 IN CHAR16 *VariableName,
2915 IN UINT16 LabelNumber,
2916 IN EFI_FORM_ID FormId,
2917 IN EFI_QUESTION_ID QuestionIdBase,
2932 BOOLEAN IsItemFound;
2933 UINT32 ItemDataSize;
2944 if (EFI_ERROR (Status)) {
2952 Status =
gRT->GetVariable (VariableName, VendorGuid,
NULL, &DataSize,
NULL);
2953 if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
2958 if (OldData ==
NULL) {
2959 Status = EFI_OUT_OF_RESOURCES;
2963 Status =
gRT->GetVariable (VariableName, VendorGuid, &Attr, &DataSize, OldData);
2964 if (EFI_ERROR (Status)) {
2973 Status = EFI_OUT_OF_RESOURCES;
2980 IsItemFound =
FALSE;
2981 ItemDataSize = (UINT32)DataSize;
3003 for (Index = 0; Index < CertCount; Index++) {
3004 if (GuidIndex == DeleteIndex) {
3037 Status = EFI_NOT_FOUND;
3044 ItemDataSize = Offset;
3047 ZeroMem (OldData, ItemDataSize);
3050 DEBUG ((DEBUG_INFO,
" CertCount = %x\n", CertCount));
3051 if (CertCount != 0) {
3063 if (EFI_ERROR (Status)) {
3064 DEBUG ((DEBUG_ERROR,
"Fail to fetch valid time data: %r", Status));
3069 if (EFI_ERROR (Status)) {
3070 DEBUG ((DEBUG_ERROR,
"Fail to create time-based data payload: %r", Status));
3075 Status =
gRT->SetVariable (
3082 if (EFI_ERROR (Status)) {
3083 DEBUG ((DEBUG_ERROR,
"Failed to set variable, Status = %r\n", Status));
3092 if (OldData !=
NULL) {
3120 IN SIGNATURE_DELETE_TYPE DelType,
3121 IN UINT32 CheckedCount
3128 CHAR16 VariableName[BUFFER_MAX_SIZE];
3129 UINT32 VariableAttr;
3130 UINTN VariableDataSize;
3131 UINTN RemainingSize;
3135 UINT8 *VariableData;
3136 UINT8 *NewVariableData;
3141 VariableDataSize = 0;
3144 VariableData =
NULL;
3145 NewVariableData =
NULL;
3147 if (PrivateData->VariableName == Variable_DB) {
3149 }
else if (PrivateData->VariableName == Variable_DBX) {
3151 }
else if (PrivateData->VariableName == Variable_DBT) {
3157 Status =
gRT->GetVariable (
3159 &gEfiImageSecurityDatabaseGuid,
3164 if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
3169 if (VariableData ==
NULL) {
3170 Status = EFI_OUT_OF_RESOURCES;
3174 Status =
gRT->GetVariable (
3176 &gEfiImageSecurityDatabaseGuid,
3181 if (EFI_ERROR (Status)) {
3186 if (EFI_ERROR (Status)) {
3191 if (NewVariableData ==
NULL) {
3192 Status = EFI_OUT_OF_RESOURCES;
3196 RemainingSize = VariableDataSize;
3198 if (DelType == Delete_Signature_List_All) {
3199 VariableDataSize = 0;
3204 while ((RemainingSize > 0) && (RemainingSize >= ListWalker->
SignatureListSize) && ListIndex < PrivateData->ListIndex) {
3218 if ((CheckedCount < SIGNATURE_DATA_COUNTS (ListWalker)) && (DelType == Delete_Signature_Data)) {
3227 for (Index = 0; Index < SIGNATURE_DATA_COUNTS (ListWalker); Index = Index + 1) {
3228 if (PrivateData->CheckArray[Index]) {
3251 CopyMem ((UINT8 *)NewVariableData + Offset, ListWalker, RemainingSize);
3252 Offset += RemainingSize;
3254 VariableDataSize = Offset;
3259 if (EFI_ERROR (Status)) {
3260 DEBUG ((DEBUG_ERROR,
"Fail to fetch valid time data: %r", Status));
3265 if (EFI_ERROR (Status)) {
3266 DEBUG ((DEBUG_ERROR,
"Fail to create time-based data payload: %r", Status));
3271 Status =
gRT->SetVariable (
3273 &gEfiImageSecurityDatabaseGuid,
3278 if (EFI_ERROR (Status)) {
3279 DEBUG ((DEBUG_ERROR,
"Failed to set variable, Status = %r", Status));
3284 SECUREBOOT_FREE_NON_NULL (VariableData);
3285 SECUREBOOT_FREE_NON_NULL (NewVariableData);
3314 if (SecureBoot ==
NULL) {
3315 return EFI_NOT_FOUND;
3318 if (*SecureBoot == SECURE_BOOT_MODE_ENABLE) {
3342 UINT8 *SecureBootEnable;
3344 UINT8 *SecureBootMode;
3347 SecureBootEnable =
NULL;
3349 SecureBootMode =
NULL;
3354 ConfigData->CertificateFormat = HASHALG_RAW;
3355 ConfigData->AlwaysRevocation =
TRUE;
3356 gRT->GetTime (&CurrTime,
NULL);
3357 ConfigData->RevocationDate.Year = CurrTime.Year;
3358 ConfigData->RevocationDate.Month = CurrTime.Month;
3359 ConfigData->RevocationDate.Day = CurrTime.Day;
3360 ConfigData->RevocationTime.Hour = CurrTime.Hour;
3361 ConfigData->RevocationTime.Minute = CurrTime.Minute;
3362 ConfigData->RevocationTime.Second = 0;
3363 if (Private->FileContext->FHandle !=
NULL) {
3364 ConfigData->FileEnrollType = Private->FileContext->FileType;
3366 ConfigData->FileEnrollType = UNKNOWN_FILE_TYPE;
3369 ConfigData->ListCount = Private->ListCount;
3375 ConfigData->PhysicalPresent =
TRUE;
3377 ConfigData->PhysicalPresent =
FALSE;
3384 if ((SetupMode ==
NULL) || ((*SetupMode) == SETUP_MODE)) {
3385 ConfigData->HasPk =
FALSE;
3387 ConfigData->HasPk =
TRUE;
3395 ConfigData->AttemptSecureBoot =
FALSE;
3401 if ((SetupMode !=
NULL) && ((*SetupMode) == USER_MODE)) {
3402 ConfigData->HideSecureBoot =
FALSE;
3403 if ((SecureBootEnable !=
NULL) && (*SecureBootEnable == SECURE_BOOT_ENABLE)) {
3404 ConfigData->AttemptSecureBoot =
TRUE;
3407 ConfigData->HideSecureBoot =
TRUE;
3414 if (SecureBootMode ==
NULL) {
3415 ConfigData->SecureBootMode = STANDARD_SECURE_BOOT_MODE;
3417 ConfigData->SecureBootMode = *(SecureBootMode);
3420 if (SecureBootEnable !=
NULL) {
3424 if (SetupMode !=
NULL) {
3428 if (SecureBootMode !=
NULL) {
3464 OUT EFI_STRING *Progress,
3465 OUT EFI_STRING *Results
3472 EFI_STRING ConfigRequest;
3473 EFI_STRING ConfigRequestHdr;
3475 BOOLEAN AllocatedRequest;
3477 if ((Progress ==
NULL) || (Results ==
NULL)) {
3478 return EFI_INVALID_PARAMETER;
3481 AllocatedRequest =
FALSE;
3482 ConfigRequestHdr =
NULL;
3483 ConfigRequest =
NULL;
3486 ZeroMem (&Configuration,
sizeof (Configuration));
3487 PrivateData = SECUREBOOT_CONFIG_PRIVATE_FROM_THIS (This);
3488 *Progress = Request;
3490 if ((Request !=
NULL) && !
HiiIsConfigHdrMatch (Request, &gSecureBootConfigFormSetGuid, mSecureBootStorageName)) {
3491 return EFI_NOT_FOUND;
3502 ConfigRequest = Request;
3503 if ((Request ==
NULL) || (
StrStr (Request, L
"OFFSET") ==
NULL)) {
3510 ConfigRequestHdr =
HiiConstructConfigHdr (&gSecureBootConfigFormSetGuid, mSecureBootStorageName, PrivateData->DriverHandle);
3511 Size = (
StrLen (ConfigRequestHdr) + 32 + 1) *
sizeof (CHAR16);
3513 ASSERT (ConfigRequest !=
NULL);
3514 AllocatedRequest =
TRUE;
3515 UnicodeSPrint (ConfigRequest, Size, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
3517 ConfigRequestHdr =
NULL;
3523 (UINT8 *)&Configuration,
3532 if (AllocatedRequest) {
3539 if (Request ==
NULL) {
3541 }
else if (
StrStr (Request, L
"OFFSET") ==
NULL) {
3542 *Progress = Request +
StrLen (Request);
3570 IN CONST EFI_STRING Configuration,
3571 OUT EFI_STRING *Progress
3579 if ((Configuration ==
NULL) || (Progress ==
NULL)) {
3580 return EFI_INVALID_PARAMETER;
3583 *Progress = Configuration;
3584 if (!
HiiIsConfigHdrMatch (Configuration, &gSecureBootConfigFormSetGuid, mSecureBootStorageName)) {
3585 return EFI_NOT_FOUND;
3588 PrivateData = SECUREBOOT_CONFIG_PRIVATE_FROM_THIS (This);
3602 (UINT8 *)&IfrNvData,
3606 if (EFI_ERROR (Status)) {
3613 if (!IfrNvData.HideSecureBoot) {
3615 if (EFI_ERROR (Status)) {
3620 *Progress = Configuration +
StrLen (Configuration);
3639 IN EFI_FORM_ID FormId,
3640 IN EFI_QUESTION_ID QuestionIdBase
3644 EFI_STRING_ID ListType;
3645 EFI_STRING FormatNameString;
3646 EFI_STRING FormatHelpString;
3647 EFI_STRING FormatTypeString;
3653 EFI_FORM_ID DstFormId;
3654 VOID *StartOpCodeHandle;
3655 VOID *EndOpCodeHandle;
3656 VOID *StartGotoHandle;
3657 VOID *EndGotoHandle;
3659 UINTN RemainingSize;
3661 UINT8 *VariableData;
3662 CHAR16 VariableName[BUFFER_MAX_SIZE];
3663 CHAR16 NameBuffer[BUFFER_MAX_SIZE];
3664 CHAR16 HelpBuffer[BUFFER_MAX_SIZE];
3667 FormatNameString =
NULL;
3668 FormatHelpString =
NULL;
3669 StartOpCodeHandle =
NULL;
3670 EndOpCodeHandle =
NULL;
3671 StartGotoHandle =
NULL;
3672 EndGotoHandle =
NULL;
3674 VariableData =
NULL;
3680 if (StartOpCodeHandle ==
NULL) {
3681 Status = EFI_OUT_OF_RESOURCES;
3686 if (EndOpCodeHandle ==
NULL) {
3687 Status = EFI_OUT_OF_RESOURCES;
3692 if (StartGotoHandle ==
NULL) {
3693 Status = EFI_OUT_OF_RESOURCES;
3698 if (EndGotoHandle ==
NULL) {
3699 Status = EFI_OUT_OF_RESOURCES;
3713 StartLabel->
Number = LabelId;
3722 EndLabel->
Number = LABEL_END;
3731 StartGoto->
Number = LABEL_DELETE_ALL_LIST_BUTTON;
3740 EndGoto->
Number = LABEL_END;
3742 if (PrivateData->VariableName == Variable_DB) {
3744 DstFormId = FORMID_SECURE_BOOT_DB_OPTION_FORM;
3745 }
else if (PrivateData->VariableName == Variable_DBX) {
3747 DstFormId = FORMID_SECURE_BOOT_DBX_OPTION_FORM;
3748 }
else if (PrivateData->VariableName == Variable_DBT) {
3750 DstFormId = FORMID_SECURE_BOOT_DBT_OPTION_FORM;
3760 EFI_IFR_FLAG_CALLBACK,
3761 KEY_SECURE_BOOT_DELETE_ALL_LIST
3768 Status =
gRT->GetVariable (VariableName, &gEfiImageSecurityDatabaseGuid,
NULL, &DataSize, VariableData);
3769 if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
3774 if (VariableData ==
NULL) {
3775 Status = EFI_OUT_OF_RESOURCES;
3779 Status =
gRT->GetVariable (VariableName, &gEfiImageSecurityDatabaseGuid,
NULL, &DataSize, VariableData);
3780 if (EFI_ERROR (Status)) {
3786 if ((FormatNameString ==
NULL) || (FormatHelpString ==
NULL)) {
3790 RemainingSize = DataSize;
3792 while ((RemainingSize > 0) && (RemainingSize >= ListWalker->
SignatureListSize)) {
3794 ListType =
STRING_TOKEN (STR_LIST_TYPE_RSA2048_SHA256);
3816 if (FormatTypeString ==
NULL) {
3820 ZeroMem (NameBuffer,
sizeof (NameBuffer));
3821 UnicodeSPrint (NameBuffer,
sizeof (NameBuffer), FormatNameString, Index + 1);
3823 ZeroMem (HelpBuffer,
sizeof (HelpBuffer));
3826 sizeof (HelpBuffer),
3829 SIGNATURE_DATA_COUNTS (ListWalker)
3831 SECUREBOOT_FREE_NON_NULL (FormatTypeString);
3832 FormatTypeString =
NULL;
3836 SECUREBOOT_DELETE_SIGNATURE_DATA_FORM,
3839 EFI_IFR_FLAG_CALLBACK,
3840 QuestionIdBase + Index++
3849 PrivateData->HiiHandle,
3850 &gSecureBootConfigFormSetGuid,
3857 PrivateData->HiiHandle,
3858 &gSecureBootConfigFormSetGuid,
3864 SECUREBOOT_FREE_NON_OPCODE (StartOpCodeHandle);
3865 SECUREBOOT_FREE_NON_OPCODE (EndOpCodeHandle);
3866 SECUREBOOT_FREE_NON_OPCODE (StartGotoHandle);
3867 SECUREBOOT_FREE_NON_OPCODE (EndGotoHandle);
3869 SECUREBOOT_FREE_NON_NULL (VariableData);
3870 SECUREBOOT_FREE_NON_NULL (FormatNameString);
3871 SECUREBOOT_FREE_NON_NULL (FormatHelpString);
3873 PrivateData->ListCount = Index;
3894 OUT CHAR16 **BufferToReturn
3909 if ((ListEntry ==
NULL) || (DataEntry ==
NULL) || (BufferToReturn ==
NULL)) {
3910 return EFI_INVALID_PARAMETER;
3913 DataSize = ListEntry->SignatureSize -
sizeof (
EFI_GUID);
3914 Line = (DataSize + OneLineBytes - 1) / OneLineBytes;
3919 TotalSize = ((DataSize + Line) * 2 *
sizeof (CHAR16));
3922 if (*BufferToReturn ==
NULL) {
3923 return EFI_OUT_OF_RESOURCES;
3926 for (Index = 0, BufferIndex = 0; Index < DataSize; Index = Index + 1) {
3927 if ((Index > 0) && (Index % OneLineBytes == 0)) {
3928 BufferIndex +=
UnicodeSPrint (&(*BufferToReturn)[BufferIndex], TotalSize -
sizeof (CHAR16) * BufferIndex, L
"\n");
3931 BufferIndex +=
UnicodeSPrint (&(*BufferToReturn)[BufferIndex], TotalSize -
sizeof (CHAR16) * BufferIndex, L
"%02x", DataEntry->SignatureData[Index]);
3934 BufferIndex +=
UnicodeSPrint (&(*BufferToReturn)[BufferIndex], TotalSize -
sizeof (CHAR16) * BufferIndex, L
"\n");
3956 OUT CHAR16 **BufferToReturn
3967 if (CNBuffer ==
NULL) {
3968 Status = EFI_OUT_OF_RESOURCES;
3974 (UINT8 *)DataEntry +
sizeof (
EFI_GUID),
3975 ListEntry->SignatureSize - sizeof (
EFI_GUID),
3981 if (*BufferToReturn ==
NULL) {
3982 Status = EFI_OUT_OF_RESOURCES;
3989 SECUREBOOT_FREE_NON_NULL (CNBuffer);
4013 OUT EFI_STRING_ID *StringId
4018 EFI_STRING_ID ListTypeId;
4019 EFI_STRING FormatHelpString;
4020 EFI_STRING FormatTypeString;
4022 UINTN HelpInfoIndex;
4024 CHAR16 GuidString[BUFFER_MAX_SIZE];
4025 CHAR16 TimeString[BUFFER_MAX_SIZE];
4027 CHAR16 *HelpInfoString;
4032 FormatTypeString =
NULL;
4035 HelpInfoString =
NULL;
4038 if (
CompareGuid (&ListEntry->SignatureType, &gEfiCertRsa2048Guid)) {
4039 ListTypeId =
STRING_TOKEN (STR_LIST_TYPE_RSA2048_SHA256);
4040 DataSize = ListEntry->SignatureSize -
sizeof (
EFI_GUID);
4042 }
else if (
CompareGuid (&ListEntry->SignatureType, &gEfiCertX509Guid)) {
4044 DataSize = ListEntry->SignatureSize -
sizeof (
EFI_GUID);
4046 }
else if (
CompareGuid (&ListEntry->SignatureType, &gEfiCertSha1Guid)) {
4049 }
else if (
CompareGuid (&ListEntry->SignatureType, &gEfiCertSha256Guid)) {
4052 }
else if (
CompareGuid (&ListEntry->SignatureType, &gEfiCertSha384Guid)) {
4055 }
else if (
CompareGuid (&ListEntry->SignatureType, &gEfiCertSha512Guid)) {
4058 }
else if (
CompareGuid (&ListEntry->SignatureType, &gEfiCertX509Sha256Guid)) {
4061 Time = (
EFI_TIME *)(DataEntry->SignatureData + DataSize);
4062 }
else if (
CompareGuid (&ListEntry->SignatureType, &gEfiCertX509Sha384Guid)) {
4065 Time = (
EFI_TIME *)(DataEntry->SignatureData + DataSize);
4066 }
else if (
CompareGuid (&ListEntry->SignatureType, &gEfiCertX509Sha512Guid)) {
4069 Time = (
EFI_TIME *)(DataEntry->SignatureData + DataSize);
4071 Status = EFI_UNSUPPORTED;
4075 FormatTypeString =
HiiGetString (PrivateData->HiiHandle, ListTypeId,
NULL);
4076 if (FormatTypeString ==
NULL) {
4082 if (HelpInfoString ==
NULL) {
4083 Status = EFI_OUT_OF_RESOURCES;
4090 ZeroMem (GuidString,
sizeof (GuidString));
4091 GuidToString (&DataEntry->SignatureOwner, GuidString, BUFFER_MAX_SIZE);
4093 if (FormatHelpString ==
NULL) {
4098 &HelpInfoString[HelpInfoIndex],
4099 TotalSize -
sizeof (CHAR16) * HelpInfoIndex,
4103 SECUREBOOT_FREE_NON_NULL (FormatHelpString);
4104 FormatHelpString =
NULL;
4120 if (FormatHelpString ==
NULL) {
4125 &HelpInfoString[HelpInfoIndex],
4126 TotalSize -
sizeof (CHAR16) * HelpInfoIndex,
4132 SECUREBOOT_FREE_NON_NULL (FormatHelpString);
4133 FormatHelpString =
NULL;
4139 ZeroMem (TimeString,
sizeof (TimeString));
4142 sizeof (TimeString),
4143 L
"%d-%d-%d %d:%d:%d",
4152 if (FormatHelpString ==
NULL) {
4157 &HelpInfoString[HelpInfoIndex],
4158 TotalSize -
sizeof (CHAR16) * HelpInfoIndex,
4162 SECUREBOOT_FREE_NON_NULL (FormatHelpString);
4163 FormatHelpString =
NULL;
4166 *StringId =
HiiSetString (PrivateData->HiiHandle, 0, HelpInfoString,
NULL);
4168 SECUREBOOT_FREE_NON_NULL (DataString);
4169 SECUREBOOT_FREE_NON_NULL (HelpInfoString);
4171 SECUREBOOT_FREE_NON_NULL (FormatTypeString);
4192 IN EFI_FORM_ID FormId,
4193 IN EFI_QUESTION_ID QuestionIdBase,
4202 EFI_STRING_ID HelpStringId;
4203 EFI_STRING FormatNameString;
4204 VOID *StartOpCodeHandle;
4205 VOID *EndOpCodeHandle;
4207 UINTN RemainingSize;
4209 UINT8 *VariableData;
4210 CHAR16 VariableName[BUFFER_MAX_SIZE];
4211 CHAR16 NameBuffer[BUFFER_MAX_SIZE];
4214 FormatNameString =
NULL;
4215 StartOpCodeHandle =
NULL;
4216 EndOpCodeHandle =
NULL;
4218 VariableData =
NULL;
4224 if (StartOpCodeHandle ==
NULL) {
4225 Status = EFI_OUT_OF_RESOURCES;
4230 if (EndOpCodeHandle ==
NULL) {
4231 Status = EFI_OUT_OF_RESOURCES;
4245 StartLabel->
Number = LabelId;
4254 EndLabel->
Number = LABEL_END;
4256 if (PrivateData->VariableName == Variable_DB) {
4258 }
else if (PrivateData->VariableName == Variable_DBX) {
4260 }
else if (PrivateData->VariableName == Variable_DBT) {
4270 Status =
gRT->GetVariable (VariableName, &gEfiImageSecurityDatabaseGuid,
NULL, &DataSize, VariableData);
4271 if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
4276 if (VariableData ==
NULL) {
4277 Status = EFI_OUT_OF_RESOURCES;
4281 Status =
gRT->GetVariable (VariableName, &gEfiImageSecurityDatabaseGuid,
NULL, &DataSize, VariableData);
4282 if (EFI_ERROR (Status)) {
4286 RemainingSize = DataSize;
4292 while ((RemainingSize > 0) && (RemainingSize >= ListWalker->
SignatureListSize) && ListIndex-- > 0) {
4298 if (FormatNameString ==
NULL) {
4303 for (Index = 0; Index < SIGNATURE_DATA_COUNTS (ListWalker); Index = Index + 1) {
4307 ZeroMem (NameBuffer,
sizeof (NameBuffer));
4308 UnicodeSPrint (NameBuffer,
sizeof (NameBuffer), FormatNameString, Index + 1);
4313 Status =
FormatHelpInfo (PrivateData, ListWalker, DataWalker, &HelpStringId);
4314 if (EFI_ERROR (Status)) {
4320 (EFI_QUESTION_ID)(QuestionIdBase + Index),
4325 EFI_IFR_FLAG_CALLBACK,
4338 PrivateData->CheckArray =
AllocateZeroPool (SIGNATURE_DATA_COUNTS (ListWalker) *
sizeof (BOOLEAN));
4341 PrivateData->HiiHandle,
4342 &gSecureBootConfigFormSetGuid,
4348 SECUREBOOT_FREE_NON_OPCODE (StartOpCodeHandle);
4349 SECUREBOOT_FREE_NON_OPCODE (EndOpCodeHandle);
4351 SECUREBOOT_FREE_NON_NULL (VariableData);
4352 SECUREBOOT_FREE_NON_NULL (FormatNameString);
4375 if (EFI_ERROR (Status)) {
4381 if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
4382 DEBUG ((DEBUG_ERROR,
"Fail to clear DB: %r\n", Status));
4387 if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
4388 DEBUG ((DEBUG_ERROR,
"Fail to clear DBX: %r\n", Status));
4393 if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
4394 DEBUG ((DEBUG_ERROR,
"Fail to clear DBT: %r\n", Status));
4399 if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
4400 DEBUG ((DEBUG_ERROR,
"Fail to clear KEK: %r\n", Status));
4405 if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
4406 DEBUG ((DEBUG_ERROR,
"Fail to clear PK: %r\n", Status));
4412 if (EFI_ERROR (Status)) {
4415 "Cannot get SetupMode variable: %r\n",
4421 if (SetupMode == USER_MODE) {
4422 DEBUG ((DEBUG_INFO,
"Skipped - USER_MODE\n"));
4427 if (EFI_ERROR (Status)) {
4430 "Cannot set CUSTOM_SECURE_BOOT_MODE: %r\n",
4438 if (EFI_ERROR (Status)) {
4439 DEBUG ((DEBUG_ERROR,
"Cannot enroll db: %r\n", Status));
4444 if (EFI_ERROR (Status)) {
4445 DEBUG ((DEBUG_ERROR,
"Cannot enroll dbx: %r\n", Status));
4449 if (EFI_ERROR (Status)) {
4450 DEBUG ((DEBUG_ERROR,
"Cannot enroll dbt: %r\n", Status));
4454 if (EFI_ERROR (Status)) {
4455 DEBUG ((DEBUG_ERROR,
"Cannot enroll KEK: %r\n", Status));
4460 if (EFI_ERROR (Status)) {
4461 DEBUG ((DEBUG_ERROR,
"Cannot enroll PK: %r\n", Status));
4466 if (EFI_ERROR (Status)) {
4469 "Cannot set CustomMode to STANDARD_SECURE_BOOT_MODE\n"
4470 "Please do it manually, otherwise system can be easily compromised\n"
4486 DEBUG ((DEBUG_ERROR,
"Cannot set mode to Secure: %r\n", Status));
4518 IN EFI_BROWSER_ACTION Action,
4519 IN EFI_QUESTION_ID QuestionId,
4522 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
4527 RETURN_STATUS RStatus;
4532 UINT8 *SecureBootEnable;
4534 UINT8 *SecureBootMode;
4536 CHAR16 PromptString[100];
4539 UINT16 *FilePostFix;
4541 BOOLEAN GetBrowserDataResult;
4542 ENROLL_KEY_ERROR EnrollKeyErrorCode;
4544 EFI_HII_POPUP_SELECTION UserSelection;
4547 SecureBootEnable =
NULL;
4548 SecureBootMode =
NULL;
4551 EnrollKeyErrorCode = None_Error;
4552 GetBrowserDataResult =
FALSE;
4554 if ((This ==
NULL) || (Value ==
NULL) || (ActionRequest ==
NULL)) {
4555 return EFI_INVALID_PARAMETER;
4558 Private = SECUREBOOT_CONFIG_PRIVATE_FROM_THIS (This);
4560 gSecureBootPrivateData = Private;
4567 if (IfrNvData ==
NULL) {
4568 return EFI_OUT_OF_RESOURCES;
4571 if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {
4572 if (QuestionId == KEY_SECURE_BOOT_MODE) {
4577 mIsEnterSecureBootForm =
TRUE;
4583 if ((QuestionId == KEY_SECURE_BOOT_PK_OPTION) ||
4584 (QuestionId == KEY_SECURE_BOOT_KEK_OPTION) ||
4585 (QuestionId == KEY_SECURE_BOOT_DB_OPTION) ||
4586 (QuestionId == KEY_SECURE_BOOT_DBX_OPTION) ||
4587 (QuestionId == KEY_SECURE_BOOT_DBT_OPTION))
4596 GetBrowserDataResult =
HiiGetBrowserData (&gSecureBootConfigFormSetGuid, mSecureBootStorageName, BufferSize, (UINT8 *)IfrNvData);
4598 if (Action == EFI_BROWSER_ACTION_RETRIEVE) {
4599 Status = EFI_UNSUPPORTED;
4600 if (QuestionId == KEY_SECURE_BOOT_MODE) {
4601 if (mIsEnterSecureBootForm) {
4602 if (GetBrowserDataResult) {
4606 Value->u8 = SECURE_BOOT_MODE_STANDARD;
4614 if ((Action != EFI_BROWSER_ACTION_CHANGED) &&
4615 (Action != EFI_BROWSER_ACTION_CHANGING) &&
4616 (Action != EFI_BROWSER_ACTION_FORM_CLOSE) &&
4617 (Action != EFI_BROWSER_ACTION_DEFAULT_STANDARD))
4619 Status = EFI_UNSUPPORTED;
4623 if (Action == EFI_BROWSER_ACTION_CHANGING) {
4624 switch (QuestionId) {
4625 case KEY_SECURE_BOOT_ENABLE:
4627 if (
NULL != SecureBootEnable) {
4631 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
4633 L
"Only Physical Presence User could disable secure boot!",
4636 Status = EFI_UNSUPPORTED;
4639 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
4641 L
"Configuration changed, please reset the platform to take effect!",
4649 case KEY_SECURE_BOOT_KEK_OPTION:
4650 case KEY_SECURE_BOOT_DB_OPTION:
4651 case KEY_SECURE_BOOT_DBX_OPTION:
4652 case KEY_SECURE_BOOT_DBT_OPTION:
4653 PrivateData = SECUREBOOT_CONFIG_PRIVATE_FROM_THIS (This);
4657 ZeroMem (IfrNvData->SignatureGuid, sizeof (IfrNvData->SignatureGuid));
4658 if (Private->SignatureGUID ==
NULL) {
4660 if (Private->SignatureGUID ==
NULL) {
4661 return EFI_OUT_OF_RESOURCES;
4670 if (QuestionId == KEY_SECURE_BOOT_DB_OPTION) {
4671 LabelId = SECUREBOOT_ENROLL_SIGNATURE_TO_DB;
4672 }
else if (QuestionId == KEY_SECURE_BOOT_DBX_OPTION) {
4673 LabelId = SECUREBOOT_ENROLL_SIGNATURE_TO_DBX;
4674 }
else if (QuestionId == KEY_SECURE_BOOT_DBT_OPTION) {
4675 LabelId = SECUREBOOT_ENROLL_SIGNATURE_TO_DBT;
4677 LabelId = FORMID_ENROLL_KEK_FORM;
4685 case KEY_SECURE_BOOT_PK_OPTION:
4686 LabelId = FORMID_ENROLL_PK_FORM;
4693 case FORMID_ENROLL_PK_FORM:
4697 case FORMID_ENROLL_KEK_FORM:
4701 case SECUREBOOT_ENROLL_SIGNATURE_TO_DB:
4705 case SECUREBOOT_ENROLL_SIGNATURE_TO_DBX:
4708 if (Private->FileContext->FHandle !=
NULL) {
4712 NameLength =
StrLen (Private->FileContext->FileName);
4713 if (NameLength <= 4) {
4717 FilePostFix = Private->FileContext->FileName + NameLength - 4;
4723 IfrNvData->FileEnrollType = X509_CERT_FILE_TYPE;
4725 IfrNvData->FileEnrollType = AUTHENTICATION_2_FILE_TYPE;
4727 IfrNvData->FileEnrollType = PE_IMAGE_FILE_TYPE;
4730 Private->FileContext->FileType = IfrNvData->FileEnrollType;
4735 if (IfrNvData->FileEnrollType != X509_CERT_FILE_TYPE) {
4736 IfrNvData->CertificateFormat = HASHALG_RAW;
4739 DEBUG ((DEBUG_ERROR,
"IfrNvData->FileEnrollType %d\n", Private->FileContext->FileType));
4744 case SECUREBOOT_ENROLL_SIGNATURE_TO_DBT:
4748 case KEY_SECURE_BOOT_DELETE_PK:
4751 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
4753 L
"Are you sure you want to delete PK? Secure boot will be disabled!",
4754 L
"Press 'Y' to delete PK and exit, 'N' to discard change and return",
4757 if ((Key.UnicodeChar ==
'y') || (Key.UnicodeChar ==
'Y')) {
4759 if (EFI_ERROR (Status)) {
4761 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
4763 L
"Only Physical Presence User could delete PK in custom mode!",
4774 case KEY_DELETE_KEK:
4778 &gEfiGlobalVariableGuid,
4780 FORMID_DELETE_KEK_FORM,
4781 OPTION_DEL_KEK_QUESTION_ID
4785 case SECUREBOOT_DELETE_SIGNATURE_FROM_DB:
4789 &gEfiImageSecurityDatabaseGuid,
4791 SECUREBOOT_DELETE_SIGNATURE_FROM_DB,
4792 OPTION_DEL_DB_QUESTION_ID
4799 case KEY_VALUE_FROM_DBX_TO_LIST_FORM:
4800 Private->VariableName = Variable_DBX;
4803 LABEL_SIGNATURE_LIST_START,
4804 SECUREBOOT_DELETE_SIGNATURE_LIST_FORM,
4805 OPTION_SIGNATURE_LIST_QUESTION_ID
4812 case KEY_SECURE_BOOT_DELETE_ALL_LIST:
4814 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
4816 L
"Press 'Y' to delete signature list.",
4817 L
"Press other key to cancel and exit.",
4821 if ((Key.UnicodeChar == L
'Y') || (Key.UnicodeChar == L
'y')) {
4822 DeleteSignatureEx (Private, Delete_Signature_List_All, IfrNvData->CheckedDataCount);
4827 LABEL_SIGNATURE_LIST_START,
4828 SECUREBOOT_DELETE_SIGNATURE_LIST_FORM,
4829 OPTION_SIGNATURE_LIST_QUESTION_ID
4831 IfrNvData->ListCount = Private->ListCount;
4837 case KEY_SECURE_BOOT_DELETE_ALL_DATA:
4839 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
4841 L
"Press 'Y' to delete signature data.",
4842 L
"Press other key to cancel and exit.",
4846 if ((Key.UnicodeChar == L
'Y') || (Key.UnicodeChar == L
'y')) {
4847 DeleteSignatureEx (Private, Delete_Signature_List_One, IfrNvData->CheckedDataCount);
4852 LABEL_SIGNATURE_LIST_START,
4853 SECUREBOOT_DELETE_SIGNATURE_LIST_FORM,
4854 OPTION_SIGNATURE_LIST_QUESTION_ID
4856 IfrNvData->ListCount = Private->ListCount;
4862 case KEY_SECURE_BOOT_DELETE_CHECK_DATA:
4864 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
4866 L
"Press 'Y' to delete signature data.",
4867 L
"Press other key to cancel and exit.",
4871 if ((Key.UnicodeChar == L
'Y') || (Key.UnicodeChar == L
'y')) {
4872 DeleteSignatureEx (Private, Delete_Signature_Data, IfrNvData->CheckedDataCount);
4877 LABEL_SIGNATURE_LIST_START,
4878 SECUREBOOT_DELETE_SIGNATURE_LIST_FORM,
4879 OPTION_SIGNATURE_LIST_QUESTION_ID
4881 IfrNvData->ListCount = Private->ListCount;
4884 case SECUREBOOT_DELETE_SIGNATURE_FROM_DBT:
4888 &gEfiImageSecurityDatabaseGuid,
4890 SECUREBOOT_DELETE_SIGNATURE_FROM_DBT,
4891 OPTION_DEL_DBT_QUESTION_ID
4896 case KEY_VALUE_SAVE_AND_EXIT_KEK:
4898 if (EFI_ERROR (Status)) {
4900 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
4902 L
"ERROR: Unsupported file type!",
4903 L
"Only supports DER-encoded X509 certificate",
4910 case KEY_VALUE_SAVE_AND_EXIT_DB:
4912 if (EFI_ERROR (Status)) {
4914 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
4916 L
"ERROR: Unsupported file type!",
4917 L
"Only supports DER-encoded X509 certificate and executable EFI image",
4924 case KEY_VALUE_SAVE_AND_EXIT_DBX:
4927 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
4929 L
"Enrollment failed! Same certificate had already been in the dbx!",
4940 if ((IfrNvData !=
NULL) && (IfrNvData->CertificateFormat < HASHALG_MAX)) {
4943 IfrNvData->CertificateFormat,
4944 &IfrNvData->RevocationDate,
4945 &IfrNvData->RevocationTime,
4946 IfrNvData->AlwaysRevocation
4948 IfrNvData->CertificateFormat = HASHALG_RAW;
4953 if (EFI_ERROR (Status)) {
4955 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
4957 L
"ERROR: Unsupported file type!",
4958 L
"Only supports DER-encoded X509 certificate, AUTH_2 format data & executable EFI image",
4962 IfrNvData->ListCount = Private->ListCount;
4967 case KEY_VALUE_SAVE_AND_EXIT_DBT:
4969 if (EFI_ERROR (Status)) {
4971 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
4973 L
"ERROR: Unsupported file type!",
4974 L
"Only supports DER-encoded X509 certificate.",
4980 case KEY_VALUE_SAVE_AND_EXIT_PK:
4985 if (EFI_ERROR (Status)) {
4986 if ((EnrollKeyErrorCode != None_Error) && (EnrollKeyErrorCode < Enroll_Error_Max)) {
4988 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
4990 mX509EnrollPromptTitle[EnrollKeyErrorCode],
4991 mX509EnrollPromptString[EnrollKeyErrorCode],
5000 if (EFI_ERROR (Status)) {
5003 sizeof (PromptString),
5004 L
"Error status: %x.",
5008 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
5010 L
"ERROR: Enrollment failed!",
5020 if ((QuestionId >= OPTION_DEL_KEK_QUESTION_ID) &&
5021 (QuestionId < (OPTION_DEL_KEK_QUESTION_ID + OPTION_CONFIG_RANGE)))
5024 }
else if ((QuestionId >= OPTION_DEL_DB_QUESTION_ID) &&
5025 (QuestionId < (OPTION_DEL_DB_QUESTION_ID + OPTION_CONFIG_RANGE)))
5030 &gEfiImageSecurityDatabaseGuid,
5032 SECUREBOOT_DELETE_SIGNATURE_FROM_DB,
5033 OPTION_DEL_DB_QUESTION_ID,
5034 QuestionId - OPTION_DEL_DB_QUESTION_ID
5036 }
else if ((QuestionId >= OPTION_SIGNATURE_LIST_QUESTION_ID) &&
5037 (QuestionId < (OPTION_SIGNATURE_LIST_QUESTION_ID + OPTION_CONFIG_RANGE)))
5041 LABEL_SIGNATURE_DATA_START,
5042 SECUREBOOT_DELETE_SIGNATURE_DATA_FORM,
5043 OPTION_SIGNATURE_DATA_QUESTION_ID,
5044 QuestionId - OPTION_SIGNATURE_LIST_QUESTION_ID
5046 Private->ListIndex = QuestionId - OPTION_SIGNATURE_LIST_QUESTION_ID;
5047 }
else if ((QuestionId >= OPTION_SIGNATURE_DATA_QUESTION_ID) &&
5048 (QuestionId < (OPTION_SIGNATURE_DATA_QUESTION_ID + OPTION_CONFIG_RANGE)))
5050 if (Private->CheckArray[QuestionId - OPTION_SIGNATURE_DATA_QUESTION_ID]) {
5051 IfrNvData->CheckedDataCount--;
5052 Private->CheckArray[QuestionId - OPTION_SIGNATURE_DATA_QUESTION_ID] =
FALSE;
5054 IfrNvData->CheckedDataCount++;
5055 Private->CheckArray[QuestionId - OPTION_SIGNATURE_DATA_QUESTION_ID] =
TRUE;
5057 }
else if ((QuestionId >= OPTION_DEL_DBT_QUESTION_ID) &&
5058 (QuestionId < (OPTION_DEL_DBT_QUESTION_ID + OPTION_CONFIG_RANGE)))
5063 &gEfiImageSecurityDatabaseGuid,
5065 SECUREBOOT_DELETE_SIGNATURE_FROM_DBT,
5066 OPTION_DEL_DBT_QUESTION_ID,
5067 QuestionId - OPTION_DEL_DBT_QUESTION_ID
5073 case KEY_VALUE_NO_SAVE_AND_EXIT_PK:
5074 case KEY_VALUE_NO_SAVE_AND_EXIT_KEK:
5075 case KEY_VALUE_NO_SAVE_AND_EXIT_DB:
5076 case KEY_VALUE_NO_SAVE_AND_EXIT_DBX:
5077 case KEY_VALUE_NO_SAVE_AND_EXIT_DBT:
5080 if (Private->SignatureGUID !=
NULL) {
5082 Private->SignatureGUID =
NULL;
5087 }
else if (Action == EFI_BROWSER_ACTION_CHANGED) {
5088 switch (QuestionId) {
5089 case KEY_SECURE_BOOT_ENABLE:
5090 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
5092 case KEY_SECURE_BOOT_MODE:
5093 mIsEnterSecureBootForm =
FALSE;
5095 case KEY_SECURE_BOOT_KEK_GUID:
5096 case KEY_SECURE_BOOT_SIGNATURE_GUID_DB:
5097 case KEY_SECURE_BOOT_SIGNATURE_GUID_DBX:
5098 case KEY_SECURE_BOOT_SIGNATURE_GUID_DBT:
5099 ASSERT (Private->SignatureGUID !=
NULL);
5100 RStatus =
StrToGuid (IfrNvData->SignatureGuid, Private->SignatureGUID);
5101 if (
RETURN_ERROR (RStatus) || (IfrNvData->SignatureGuid[GUID_STRING_LENGTH] != L
'\0')) {
5102 Status = EFI_INVALID_PARAMETER;
5106 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
5108 case KEY_SECURE_BOOT_DELETE_PK:
5110 if ((SetupMode ==
NULL) || ((*SetupMode) == SETUP_MODE)) {
5111 IfrNvData->DeletePk =
TRUE;
5112 IfrNvData->HasPk =
FALSE;
5113 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;
5115 IfrNvData->DeletePk =
FALSE;
5116 IfrNvData->HasPk =
TRUE;
5117 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
5120 if (SetupMode !=
NULL) {
5125 case KEY_SECURE_BOOT_RESET_TO_DEFAULT:
5127 Status =
gBS->LocateProtocol (&gEfiHiiPopupProtocolGuid,
NULL, (VOID **)&HiiPopup);
5128 if (EFI_ERROR (Status)) {
5132 Status = HiiPopup->CreatePopup (
5134 EfiHiiPopupStyleInfo,
5135 EfiHiiPopupTypeYesNo,
5140 if (UserSelection == EfiHiiPopupSelectionYes) {
5155 }
else if (Action == EFI_BROWSER_ACTION_DEFAULT_STANDARD) {
5156 if (QuestionId == KEY_HIDE_SECURE_BOOT) {
5159 IfrNvData->HideSecureBoot =
TRUE;
5162 IfrNvData->HideSecureBoot =
FALSE;
5165 Value->b = IfrNvData->HideSecureBoot;
5167 }
else if (Action == EFI_BROWSER_ACTION_FORM_CLOSE) {
5172 if ((
NULL != SecureBootMode) && (*SecureBootMode == CUSTOM_SECURE_BOOT_MODE)) {
5173 IfrNvData->SecureBootMode = STANDARD_SECURE_BOOT_MODE;
5177 if (SecureBootMode !=
NULL) {
5181 if (QuestionId == KEY_SECURE_BOOT_DELETE_ALL_DATA) {
5185 SECUREBOOT_FREE_NON_NULL (Private->CheckArray);
5186 IfrNvData->CheckedDataCount = 0;
5192 if (!EFI_ERROR (Status) && GetBrowserDataResult) {
5194 HiiSetBrowserData (&gSecureBootConfigFormSetGuid, mSecureBootStorageName, BufferSize, (UINT8 *)IfrNvData,
NULL);
5227 DriverHandle =
NULL;
5228 ConfigAccess = &PrivateData->ConfigAccess;
5229 Status =
gBS->InstallMultipleProtocolInterfaces (
5231 &gEfiDevicePathProtocolGuid,
5232 &mSecureBootHiiVendorDevicePath,
5233 &gEfiHiiConfigAccessProtocolGuid,
5237 if (EFI_ERROR (Status)) {
5241 PrivateData->DriverHandle = DriverHandle;
5247 &gSecureBootConfigFormSetGuid,
5249 SecureBootConfigDxeStrings,
5250 SecureBootConfigBin,
5253 if (HiiHandle ==
NULL) {
5254 gBS->UninstallMultipleProtocolInterfaces (
5256 &gEfiDevicePathProtocolGuid,
5257 &mSecureBootHiiVendorDevicePath,
5258 &gEfiHiiConfigAccessProtocolGuid,
5262 return EFI_OUT_OF_RESOURCES;
5265 PrivateData->HiiHandle = HiiHandle;
5269 if (PrivateData->FileContext ==
NULL) {
5271 return EFI_OUT_OF_RESOURCES;
5278 if (mStartOpCodeHandle ==
NULL) {
5280 return EFI_OUT_OF_RESOURCES;
5284 if (mEndOpCodeHandle ==
NULL) {
5286 return EFI_OUT_OF_RESOURCES;
5310 mEndLabel->
Number = LABEL_END;
5329 if (PrivateData->HiiHandle !=
NULL) {
5331 PrivateData->HiiHandle =
NULL;
5337 if (PrivateData->DriverHandle !=
NULL) {
5338 gBS->UninstallMultipleProtocolInterfaces (
5339 PrivateData->DriverHandle,
5340 &gEfiDevicePathProtocolGuid,
5341 &mSecureBootHiiVendorDevicePath,
5342 &gEfiHiiConfigAccessProtocolGuid,
5343 &PrivateData->ConfigAccess,
5346 PrivateData->DriverHandle =
NULL;
5349 if (PrivateData->SignatureGUID !=
NULL) {
5350 FreePool (PrivateData->SignatureGUID);
5353 if (PrivateData->FileContext !=
NULL) {
5354 FreePool (PrivateData->FileContext);
5359 if (mStartOpCodeHandle !=
NULL) {
5363 if (mEndOpCodeHandle !=
NULL) {
@ RsaKeyN
RSA public Modulus (N)
UINTN EFIAPI Sha256GetContextSize(VOID)
UINTN EFIAPI Sha384GetContextSize(VOID)
BOOLEAN EFIAPI Sha512Final(IN OUT VOID *Sha512Context, OUT UINT8 *HashValue)
UINTN EFIAPI Sha512GetContextSize(VOID)
BOOLEAN EFIAPI Sha512Init(OUT VOID *Sha512Context)
#define SHA512_DIGEST_SIZE
BOOLEAN EFIAPI Sha256Init(OUT VOID *Sha256Context)
BOOLEAN EFIAPI RsaGetPublicKeyFromX509(IN CONST UINT8 *Cert, IN UINTN CertSize, OUT VOID **RsaContext)
BOOLEAN EFIAPI Sha256Final(IN OUT VOID *Sha256Context, OUT UINT8 *HashValue)
#define SHA256_DIGEST_SIZE
BOOLEAN EFIAPI Sha384Update(IN OUT VOID *Sha384Context, IN CONST VOID *Data, IN UINTN DataSize)
BOOLEAN EFIAPI RsaGetKey(IN OUT VOID *RsaContext, IN RSA_KEY_TAG KeyTag, OUT UINT8 *BigNumber, IN OUT UINTN *BnSize)
BOOLEAN EFIAPI Sha256Update(IN OUT VOID *Sha256Context, IN CONST VOID *Data, IN UINTN DataSize)
VOID EFIAPI RsaFree(IN VOID *RsaContext)
BOOLEAN EFIAPI Sha384Final(IN OUT VOID *Sha384Context, OUT UINT8 *HashValue)
BOOLEAN EFIAPI Sha384Init(OUT VOID *Sha384Context)
BOOLEAN EFIAPI X509GetTBSCert(IN CONST UINT8 *Cert, IN UINTN CertSize, OUT UINT8 **TBSCert, OUT UINTN *TBSCertSize)
BOOLEAN EFIAPI Sha512Update(IN OUT VOID *Sha512Context, IN CONST VOID *Data, IN UINTN DataSize)
RETURN_STATUS EFIAPI X509GetCommonName(IN CONST UINT8 *Cert, IN UINTN CertSize, OUT CHAR8 *CommonName OPTIONAL, IN OUT UINTN *CommonNameSize)
#define SHA384_DIGEST_SIZE
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
RETURN_STATUS EFIAPI StrToGuid(IN CONST CHAR16 *String, OUT GUID *Guid)
UINT32 EFIAPI WriteUnaligned32(OUT UINT32 *Buffer, IN UINT32 Value)
RETURN_STATUS EFIAPI AsciiStrToUnicodeStrS(IN CONST CHAR8 *Source, OUT CHAR16 *Destination, IN UINTN DestMax)
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
CHAR16 *EFIAPI StrStr(IN CONST CHAR16 *String, IN CONST CHAR16 *SearchString)
UINT32 EFIAPI ReadUnaligned32(IN CONST UINT32 *Buffer)
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID CleanUpPage(IN UINT16 LabelId, IN BMM_CALLBACK_DATA *CallbackData)
#define HARDWARE_DEVICE_PATH
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI ChooseFile(IN EFI_DEVICE_PATH_PROTOCOL *RootDirectory, IN CHAR16 *FileType OPTIONAL, IN CHOOSE_HANDLER ChooseHandler OPTIONAL, OUT EFI_DEVICE_PATH_PROTOCOL **File OPTIONAL)
#define EFI_SETUP_MODE_NAME
#define EFI_KEY_EXCHANGE_KEY_NAME
#define EFI_PLATFORM_KEY_NAME
#define EFI_SECURE_BOOT_MODE_NAME
EFI_STATUS EFIAPI HashUpdate(IN HASH_HANDLE HashHandle, IN VOID *DataToHash, IN UINTN DataToHashLen)
EFI_STRING EFIAPI HiiConstructConfigHdr(IN CONST EFI_GUID *Guid OPTIONAL, IN CONST CHAR16 *Name OPTIONAL, IN EFI_HANDLE DriverHandle)
BOOLEAN EFIAPI HiiGetBrowserData(IN CONST EFI_GUID *VariableGuid OPTIONAL, IN CONST CHAR16 *VariableName OPTIONAL, IN UINTN BufferSize, OUT UINT8 *Buffer)
UINT8 *EFIAPI HiiCreateGotoOpCode(IN VOID *OpCodeHandle, IN EFI_FORM_ID FormId, IN EFI_STRING_ID Prompt, IN EFI_STRING_ID Help, IN UINT8 QuestionFlags, IN EFI_QUESTION_ID QuestionId)
VOID *EFIAPI HiiAllocateOpCodeHandle(VOID)
VOID EFIAPI HiiFreeOpCodeHandle(VOID *OpCodeHandle)
EFI_HII_HANDLE EFIAPI HiiAddPackages(IN CONST EFI_GUID *PackageListGuid, IN EFI_HANDLE DeviceHandle OPTIONAL,...)
UINT8 *EFIAPI HiiCreateGuidOpCode(IN VOID *OpCodeHandle, IN CONST EFI_GUID *Guid, IN CONST VOID *GuidOpCode OPTIONAL, IN UINTN OpCodeSize)
UINT8 *EFIAPI HiiCreateCheckBoxOpCode(IN VOID *OpCodeHandle, IN EFI_QUESTION_ID QuestionId, IN EFI_VARSTORE_ID VarStoreId, IN UINT16 VarOffset, IN EFI_STRING_ID Prompt, IN EFI_STRING_ID Help, IN UINT8 QuestionFlags, IN UINT8 CheckBoxFlags, IN VOID *DefaultsOpCodeHandle OPTIONAL)
BOOLEAN EFIAPI HiiSetBrowserData(IN CONST EFI_GUID *VariableGuid OPTIONAL, IN CONST CHAR16 *VariableName OPTIONAL, IN UINTN BufferSize, IN CONST UINT8 *Buffer, IN CONST CHAR16 *RequestElement OPTIONAL)
EFI_STRING EFIAPI HiiGetString(IN EFI_HII_HANDLE HiiHandle, IN EFI_STRING_ID StringId, IN CONST CHAR8 *Language OPTIONAL)
EFI_STATUS EFIAPI HiiUpdateForm(IN EFI_HII_HANDLE HiiHandle, IN EFI_GUID *FormSetGuid OPTIONAL, IN EFI_FORM_ID FormId, IN VOID *StartOpCodeHandle, IN VOID *EndOpCodeHandle OPTIONAL)
BOOLEAN EFIAPI HiiIsConfigHdrMatch(IN CONST EFI_STRING ConfigHdr, IN CONST EFI_GUID *Guid OPTIONAL, IN CONST CHAR16 *Name OPTIONAL)
EFI_STRING_ID EFIAPI HiiSetString(IN EFI_HII_HANDLE HiiHandle, IN EFI_STRING_ID StringId OPTIONAL, IN CONST EFI_STRING String, IN CONST CHAR8 *SupportedLanguages OPTIONAL)
VOID EFIAPI HiiRemovePackages(IN EFI_HII_HANDLE HiiHandle)
#define EFI_IMAGE_SECURITY_DATABASE2
#define EFI_IMAGE_SECURITY_DATABASE1
#define EFI_IMAGE_SECURITY_DATABASE
#define EFI_IFR_EXTEND_OP_LABEL
UINTN EFIAPI UnicodeSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString,...)
EFI_RUNTIME_SERVICES * gRT
#define RETURN_ERROR(StatusCode)
#define DEBUG(Expression)
RETURN_STATUS(EFIAPI * PE_COFF_LOADER_READ_FILE)(IN VOID *FileHandle, IN UINTN FileOffset, IN OUT UINTN *ReadSize, OUT VOID *Buffer)
RETURN_STATUS EFIAPI PeCoffLoaderGetImageInfo(IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext)
#define EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
EFI_STATUS CreateTimeBasedPayload(IN OUT UINTN *DataSize, IN OUT UINT8 **Data)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
BOOLEAN EFIAPI UpdatePKFromFile(IN EFI_DEVICE_PATH_PROTOCOL *FilePath)
BOOLEAN EFIAPI UpdateDBTFromFile(IN EFI_DEVICE_PATH_PROTOCOL *FilePath)
BOOLEAN EFIAPI UpdateDBXFromFile(IN EFI_DEVICE_PATH_PROTOCOL *FilePath)
BOOLEAN EFIAPI UpdateKEKFromFile(IN EFI_DEVICE_PATH_PROTOCOL *FilePath)
BOOLEAN EFIAPI UpdateDBFromFile(IN EFI_DEVICE_PATH_PROTOCOL *FilePath)
EFI_STATUS LoadSignatureList(IN SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData, IN UINT16 LabelId, IN EFI_FORM_ID FormId, IN EFI_QUESTION_ID QuestionIdBase)
BOOLEAN HashPeImage(IN UINT32 HashAlg)
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)
BOOLEAN IsDerEncodeCertificate(IN CONST CHAR16 *FileSuffix)
EFI_STATUS FormatHelpInfo(IN SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData, IN EFI_SIGNATURE_LIST *ListEntry, IN EFI_SIGNATURE_DATA *DataEntry, OUT EFI_STRING_ID *StringId)
EFI_STATUS ParseHashValue(IN EFI_SIGNATURE_LIST *ListEntry, IN EFI_SIGNATURE_DATA *DataEntry, OUT CHAR16 **BufferToReturn)
BOOLEAN GetSignaturelistOffset(IN EFI_SIGNATURE_LIST *Database, IN UINTN DatabaseSize, IN EFI_GUID *SignatureType, OUT UINTN *Offset)
EFI_STATUS EFIAPI SecureBootConfigImageRead(IN VOID *FileHandle, IN UINTN FileOffset, IN OUT UINTN *ReadSize, OUT VOID *Buffer)
EFI_STATUS DeleteKeyExchangeKey(IN SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData, IN EFI_QUESTION_ID QuestionId)
EFI_STATUS EnrollKeyExchangeKey(IN SECUREBOOT_CONFIG_PRIVATE_DATA *Private)
STATIC EFI_STATUS GetCurrentTime(IN EFI_TIME *Time)
EFI_STATUS EnrollAuthentication2Descriptor(IN SECUREBOOT_CONFIG_PRIVATE_DATA *Private, IN CHAR16 *VariableName)
EFI_STATUS CreatePkX509SignatureList(IN EFI_FILE_HANDLE X509File, OUT EFI_SIGNATURE_LIST **PkCert)
EFI_STATUS EFIAPI SecureBootRouteConfig(IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, IN CONST EFI_STRING Configuration, OUT EFI_STRING *Progress)
EFI_STATUS GetCommonNameFromX509(IN EFI_SIGNATURE_LIST *ListEntry, IN EFI_SIGNATURE_DATA *DataEntry, OUT CHAR16 **BufferToReturn)
BOOLEAN CalculateCertHash(IN UINT8 *CertData, IN UINTN CertSize, IN UINT32 HashAlg, OUT UINT8 *CertHash)
EFI_STATUS HashPeImageByType(VOID)
BOOLEAN IsCertHashFoundInDbx(IN UINT8 *Certificate, IN UINTN CertSize)
EFI_STATUS EnrollRsa2048ToKek(IN SECUREBOOT_CONFIG_PRIVATE_DATA *Private)
EFI_STATUS UpdateSecureBootString(IN SECUREBOOT_CONFIG_PRIVATE_DATA *Private)
EFI_STATUS LoadSignatureData(IN SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData, IN UINT16 LabelId, IN EFI_FORM_ID FormId, IN EFI_QUESTION_ID QuestionIdBase, IN UINT16 ListIndex)
EFI_STATUS EnrollX509ToKek(IN SECUREBOOT_CONFIG_PRIVATE_DATA *Private)
EFI_STATUS CheckX509Certificate(IN SECUREBOOT_FILE_CONTEXT *X509FileContext, OUT ENROLL_KEY_ERROR *Error)
VOID CloseEnrolledFile(IN SECUREBOOT_FILE_CONTEXT *FileContext)
EFI_STATUS InstallSecureBootConfigForm(IN OUT SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData)
BOOLEAN IsSignatureFoundInDatabase(IN CHAR16 *VariableName, IN UINT8 *Signature, IN UINTN SignatureSize)
BOOLEAN IsX509CertInDbx(IN SECUREBOOT_CONFIG_PRIVATE_DATA *Private, IN CHAR16 *VariableName)
EFI_STATUS UpdateDeletePage(IN SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData, IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT16 LabelNumber, IN EFI_FORM_ID FormId, IN EFI_QUESTION_ID QuestionIdBase)
EFI_STATUS SaveSecureBootVariable(IN UINT8 VarValue)
EFI_STATUS EnrollPlatformKey(IN SECUREBOOT_CONFIG_PRIVATE_DATA *Private)
EFI_STATUS EnrollX509HashtoSigDB(IN SECUREBOOT_CONFIG_PRIVATE_DATA *Private, IN UINT32 HashAlg, IN EFI_HII_DATE *RevocationDate, IN EFI_HII_TIME *RevocationTime, IN BOOLEAN AlwaysRevocation)
EFI_STATUS LoadPeImage(VOID)
EFI_STATUS EnrollSignatureDatabase(IN SECUREBOOT_CONFIG_PRIVATE_DATA *Private, IN CHAR16 *VariableName)
EFI_STATUS EnrollX509toSigDB(IN SECUREBOOT_CONFIG_PRIVATE_DATA *Private, IN CHAR16 *VariableName)
EFI_STATUS DeleteSignatureEx(IN SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData, IN SIGNATURE_DELETE_TYPE DelType, IN UINT32 CheckedCount)
BOOLEAN IsAuthentication2Format(IN EFI_FILE_HANDLE FileHandle)
VOID SecureBootExtractConfigFromVariable(IN SECUREBOOT_CONFIG_PRIVATE_DATA *Private, IN OUT SECUREBOOT_CONFIGURATION *ConfigData)
STATIC EFI_STATUS EFIAPI KeyEnrollReset(VOID)
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)
EFI_STATUS EnrollImageSignatureToSigDB(IN SECUREBOOT_CONFIG_PRIVATE_DATA *Private, IN CHAR16 *VariableName)
EFI_STATUS DeleteSignature(IN SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData, IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT16 LabelNumber, IN EFI_FORM_ID FormId, IN EFI_QUESTION_ID QuestionIdBase, IN UINTN DeleteIndex)
VOID UninstallSecureBootConfigForm(IN OUT SECUREBOOT_CONFIG_PRIVATE_DATA *PrivateData)
EFI_STATUS EFIAPI Int2OctStr(IN CONST UINTN *Integer, IN UINTN IntSizeInWords, OUT UINT8 *OctetString, IN UINTN OSSizeInBytes)
VOID CloseFile(IN EFI_FILE_HANDLE FileHandle)
EFI_STATUS EFIAPI SetSecureBootMode(IN UINT8 SecureBootMode)
EFI_STATUS EFIAPI GetSetupMode(OUT UINT8 *SetupMode)
EFI_STATUS EFIAPI DeleteDbx(VOID)
EFI_STATUS EFIAPI DeletePlatformKey(VOID)
EFI_STATUS EFIAPI DeleteDb(VOID)
EFI_STATUS EFIAPI DeleteKEK(VOID)
EFI_STATUS EFIAPI DeleteDbt(VOID)
EFI_STATUS EFIAPI EnrollPKFromDefault(VOID)
EFI_STATUS EFIAPI EnrollKEKFromDefault(VOID)
EFI_STATUS EFIAPI EnrollDbFromDefault(VOID)
EFI_STATUS EFIAPI EnrollDbtFromDefault(VOID)
EFI_STATUS EFIAPI EnrollDbxFromDefault(VOID)
UINTN GuidToString(IN EFI_GUID *Guid, IN CHAR16 *Buffer, IN UINTN BufferSize)
EFI_STATUS ReadFileContent(IN EFI_FILE_HANDLE FileHandle, IN OUT VOID **BufferPtr, OUT UINTN *FileSize, IN UINTN AddtionAllocateSize)
#define EFI_IMAGE_MACHINE_AARCH64
#define EFI_IMAGE_MACHINE_EBC
#define EFI_IMAGE_MACHINE_IA32
#define EFI_IMAGE_MACHINE_IA64
#define EFI_IMAGE_MACHINE_X64
#define EFI_IMAGE_MACHINE_ARMTHUMB_MIXED
EFI_HII_CONFIG_ROUTING_PROTOCOL * gHiiConfigRouting
EFI_STATUS EFIAPI GetVariable2(IN CONST CHAR16 *Name, IN CONST EFI_GUID *Guid, OUT VOID **Value, OUT UINTN *Size OPTIONAL)
VOID EFIAPI CreatePopUp(IN UINTN Attribute, OUT EFI_INPUT_KEY *Key OPTIONAL,...)
#define EFI_VARIABLE_NON_VOLATILE
#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
UINT32 e_lfanew
File address of new exe header.
UINT16 e_magic
Magic number.
UINT32 SignatureHeaderSize
WIN_CERTIFICATE_UEFI_GUID AuthInfo
HASH_FINAL HashFinal
Pointer to Hash Final function.
UINTN DigestLength
Digest Length.
UINTN OidLength
Length of Hash OID Value.
HASH_UPDATE HashUpdate
Pointer to Hash Update function.
UINT8 * OidValue
Hash Algorithm OID ASN.1 Value.
HASH_GET_CONTEXT_SIZE GetContextSize
Pointer to Hash GetContentSize function.
HASH_INIT HashInit
Pointer to Hash Init function.
PE_COFF_LOADER_READ_FILE ImageRead