28UINT32 mPeCoffHeaderOffset;
35UINT8 *mImageBase =
NULL;
36UINT8 mImageDigest[MAX_DIGEST_SIZE];
37UINTN mImageDigestSize;
42CHAR16 mNotifyString1[MAX_NOTIFY_STRING_LEN] = L
"Image verification pass but not found in authorized database!";
43CHAR16 mNotifyString2[MAX_NOTIFY_STRING_LEN] = L
"Launch this image anyway? (Yes/Defer/No)";
47CONST UINT8 mRsaE[] = { 0x01, 0x00, 0x01 };
52UINT8 mHashOidValue[] = {
53 0x2B, 0x0E, 0x03, 0x02, 0x1A,
54 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04,
55 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01,
56 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02,
57 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03,
61 #ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
72EFI_STRING mHashTypeStr;
87 IN CHAR16 *VariableName,
119 if ((FileHandle ==
NULL) || (ReadSize ==
NULL) || (Buffer ==
NULL)) {
120 return EFI_INVALID_PARAMETER;
124 return EFI_INVALID_PARAMETER;
127 EndPosition = FileOffset + *ReadSize;
128 if (EndPosition > mImageSize) {
129 *ReadSize = (UINT32)(mImageSize - FileOffset);
132 if (FileOffset >= mImageSize) {
136 CopyMem (Buffer, (UINT8 *)((
UINTN)FileHandle + FileOffset), *ReadSize);
161 return IMAGE_UNKNOWN;
169 Status =
gBS->LocateDevicePath (
170 &gEfiFirmwareVolume2ProtocolGuid,
174 if (!EFI_ERROR (Status)) {
175 Status =
gBS->OpenProtocol (
177 &gEfiFirmwareVolume2ProtocolGuid,
181 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
183 if (!EFI_ERROR (Status)) {
184 return IMAGE_FROM_FV;
193 Status =
gBS->LocateDevicePath (
194 &gEfiBlockIoProtocolGuid,
198 if (!EFI_ERROR (Status)) {
200 Status =
gBS->OpenProtocol (
202 &gEfiBlockIoProtocolGuid,
206 EFI_OPEN_PROTOCOL_GET_PROTOCOL
208 if (!EFI_ERROR (Status) && (BlockIo !=
NULL)) {
214 return IMAGE_FROM_REMOVABLE_MEDIA;
219 return IMAGE_FROM_FIXED_MEDIA;
231 Status =
gBS->LocateDevicePath (
232 &gEfiSimpleFileSystemProtocolGuid,
236 if (!EFI_ERROR (Status)) {
240 return IMAGE_FROM_FIXED_MEDIA;
250 case MEDIA_DEVICE_PATH:
252 return IMAGE_FROM_OPTION_ROM;
259 return IMAGE_FROM_REMOVABLE_MEDIA;
271 return IMAGE_UNKNOWN;
302 UINTN SumOfBytesHashed;
307 UINT32 NumberOfRvaAndSizes;
310 SectionHeader =
NULL;
313 if ((HashAlg >= HASHALG_MAX)) {
320 ZeroMem (mImageDigest, MAX_DIGEST_SIZE);
323 #ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
326 mCertType = gEfiCertSha1Guid;
332 mCertType = gEfiCertSha256Guid;
337 mCertType = gEfiCertSha384Guid;
342 mCertType = gEfiCertSha512Guid;
349 mHashTypeStr = mHash[HashAlg].
Name;
353 if (HashCtx ==
NULL) {
360 Status = mHash[HashAlg].
HashInit (HashCtx);
375 HashBase = mImageBase;
380 HashSize = (
UINTN)(&mNtHeader.Pe32->OptionalHeader.CheckSum) - (
UINTN)HashBase;
381 NumberOfRvaAndSizes = mNtHeader.Pe32->OptionalHeader.NumberOfRvaAndSizes;
386 HashSize = (
UINTN)(&mNtHeader.Pe32Plus->OptionalHeader.CheckSum) - (
UINTN)HashBase;
387 NumberOfRvaAndSizes = mNtHeader.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;
396 Status = mHash[HashAlg].
HashUpdate (HashCtx, HashBase, HashSize);
404 if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_SECURITY) {
413 HashBase = (UINT8 *)&mNtHeader.Pe32->OptionalHeader.CheckSum + sizeof (UINT32);
414 HashSize = mNtHeader.Pe32->OptionalHeader.SizeOfHeaders - ((
UINTN)HashBase - (
UINTN)mImageBase);
419 HashBase = (UINT8 *)&mNtHeader.Pe32Plus->OptionalHeader.CheckSum + sizeof (UINT32);
420 HashSize = mNtHeader.Pe32Plus->OptionalHeader.SizeOfHeaders - ((
UINTN)HashBase - (
UINTN)mImageBase);
424 Status = mHash[HashAlg].
HashUpdate (HashCtx, HashBase, HashSize);
437 HashBase = (UINT8 *)&mNtHeader.Pe32->OptionalHeader.CheckSum + sizeof (UINT32);
438 HashSize = (
UINTN)(&mNtHeader.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY]) - (
UINTN)HashBase;
443 HashBase = (UINT8 *)&mNtHeader.Pe32Plus->OptionalHeader.CheckSum + sizeof (UINT32);
444 HashSize = (
UINTN)(&mNtHeader.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY]) - (
UINTN)HashBase;
448 Status = mHash[HashAlg].
HashUpdate (HashCtx, HashBase, HashSize);
462 HashBase = (UINT8 *)&mNtHeader.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY + 1];
463 HashSize = mNtHeader.Pe32->OptionalHeader.SizeOfHeaders - ((
UINTN)HashBase - (
UINTN)mImageBase);
468 HashBase = (UINT8 *)&mNtHeader.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY + 1];
469 HashSize = mNtHeader.Pe32Plus->OptionalHeader.SizeOfHeaders - ((
UINTN)HashBase - (
UINTN)mImageBase);
473 Status = mHash[HashAlg].
HashUpdate (HashCtx, HashBase, HashSize);
487 SumOfBytesHashed = mNtHeader.Pe32->OptionalHeader.SizeOfHeaders;
492 SumOfBytesHashed = mNtHeader.Pe32Plus->OptionalHeader.SizeOfHeaders;
497 mPeCoffHeaderOffset +
500 mNtHeader.Pe32->FileHeader.SizeOfOptionalHeader
510 if (SectionHeader ==
NULL) {
521 for (Index = 0; Index < mNtHeader.Pe32->FileHeader.NumberOfSections; Index++) {
523 while ((Pos > 0) && (Section->PointerToRawData < SectionHeader[Pos - 1].PointerToRawData)) {
539 for (Index = 0; Index < mNtHeader.Pe32->FileHeader.NumberOfSections; Index++) {
540 Section = &SectionHeader[Index];
541 if (Section->SizeOfRawData == 0) {
545 HashBase = mImageBase + Section->PointerToRawData;
546 HashSize = (
UINTN)Section->SizeOfRawData;
548 Status = mHash[HashAlg].
HashUpdate (HashCtx, HashBase, HashSize);
553 SumOfBytesHashed += HashSize;
562 if (mImageSize > SumOfBytesHashed) {
563 HashBase = mImageBase + SumOfBytesHashed;
565 if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_SECURITY) {
572 CertSize = mNtHeader.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY].Size;
577 CertSize = mNtHeader.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY].Size;
581 if (mImageSize > CertSize + SumOfBytesHashed) {
582 HashSize = (
UINTN)(mImageSize - CertSize - SumOfBytesHashed);
584 Status = mHash[HashAlg].
HashUpdate (HashCtx, HashBase, HashSize);
588 }
else if (mImageSize < CertSize + SumOfBytesHashed) {
594 Status = mHash[HashAlg].
HashFinal (HashCtx, mImageDigest);
597 if (HashCtx !=
NULL) {
601 if (SectionHeader !=
NULL) {
632 for (Index = 0; Index < HASHALG_MAX; Index++) {
645 if ((*(AuthData + 1) & TWO_BYTE_ENCODE) != TWO_BYTE_ENCODE) {
652 if (AuthDataSize < 32 + mHash[Index].OidLength) {
653 return EFI_UNSUPPORTED;
656 if (
CompareMem (AuthData + 32, mHash[Index].OidValue, mHash[Index].OidLength) == 0) {
661 if (Index == HASHALG_MAX) {
662 return EFI_UNSUPPORTED;
669 return EFI_UNSUPPORTED;
696 if (ImageExeInfoTable ==
NULL) {
702 for (Index = 0; Index < ImageExeInfoTable->
NumberOfImages; Index++) {
722 IN EFI_IMAGE_EXECUTION_ACTION Action,
723 IN CHAR16 *Name OPTIONAL,
732 UINTN ImageExeInfoTableSize;
733 UINTN NewImageExeInfoEntrySize;
735 UINTN DevicePathSize;
738 ImageExeInfoTable =
NULL;
739 NewImageExeInfoTable =
NULL;
740 ImageExeInfoEntry =
NULL;
744 if (DevicePath ==
NULL) {
749 NameStringLen =
StrSize (Name);
751 NameStringLen =
sizeof (CHAR16);
755 if (ImageExeInfoTable !=
NULL) {
774 ASSERT (Signature !=
NULL || SignatureSize == 0);
778 if (NewImageExeInfoTable ==
NULL) {
782 if (ImageExeInfoTable !=
NULL) {
783 CopyMem (NewImageExeInfoTable, ImageExeInfoTable, ImageExeInfoTableSize);
794 WriteUnaligned32 ((UINT32 *)((UINT8 *)ImageExeInfoEntry +
sizeof (EFI_IMAGE_EXECUTION_ACTION)), (UINT32)NewImageExeInfoEntrySize);
796 NameStr = (CHAR16 *)(ImageExeInfoEntry + 1);
798 CopyMem ((UINT8 *)NameStr, Name, NameStringLen);
800 ZeroMem ((UINT8 *)NameStr,
sizeof (CHAR16));
804 (UINT8 *)NameStr + NameStringLen,
808 if (Signature !=
NULL) {
810 (UINT8 *)NameStr + NameStringLen + DevicePathSize,
819 gBS->InstallConfigurationTable (&gEfiImageSecurityDatabaseGuid, (VOID *)NewImageExeInfoTable);
824 if (ImageExeInfoTable !=
NULL) {
845 IN UINT8 *Certificate,
861 UINT8 CertDigest[MAX_DIGEST_SIZE];
863 UINTN SiglistHeaderSize;
867 Status = EFI_ABORTED;
869 DbxList = SignatureList;
870 DbxSize = SignatureListSize;
872 HashAlg = HASHALG_MAX;
874 if ((RevocationTime ==
NULL) || (DbxList ==
NULL)) {
875 return EFI_INVALID_PARAMETER;
881 if (!
X509GetTBSCert (Certificate, CertSize, &TBSCert, &TBSCertSize)) {
890 HashAlg = HASHALG_SHA256;
892 HashAlg = HASHALG_SHA384;
894 HashAlg = HASHALG_SHA512;
904 if (mHash[HashAlg].GetContextSize ==
NULL) {
908 ZeroMem (CertDigest, MAX_DIGEST_SIZE);
909 HashCtx =
AllocatePool (mHash[HashAlg].GetContextSize ());
910 if (HashCtx ==
NULL) {
914 if (!mHash[HashAlg].HashInit (HashCtx)) {
918 if (!mHash[HashAlg].
HashUpdate (HashCtx, TBSCert, TBSCertSize)) {
922 if (!mHash[HashAlg].HashFinal (HashCtx, CertDigest)) {
932 for (Index = 0; Index < CertHashCount; Index++) {
937 if (
CompareMem (DbxCertHash, CertDigest, mHash[HashAlg].DigestLength) == 0) {
961 if (HashCtx !=
NULL) {
983 IN CHAR16 *VariableName,
1004 Status =
gRT->GetVariable (VariableName, &gEfiImageSecurityDatabaseGuid,
NULL, &DataSize,
NULL);
1005 if (Status != EFI_BUFFER_TOO_SMALL) {
1006 if (Status == EFI_NOT_FOUND) {
1018 return EFI_OUT_OF_RESOURCES;
1021 Status =
gRT->GetVariable (VariableName, &gEfiImageSecurityDatabaseGuid,
NULL, &DataSize, Data);
1022 if (EFI_ERROR (Status)) {
1034 for (Index = 0; Index < CertCount; Index++) {
1086 if (SigningTime->Year != RevocationTime->Year) {
1087 return (BOOLEAN)(SigningTime->Year < RevocationTime->Year);
1088 }
else if (SigningTime->Month != RevocationTime->Month) {
1089 return (BOOLEAN)(SigningTime->Month < RevocationTime->Month);
1090 }
else if (SigningTime->Day != RevocationTime->Day) {
1091 return (BOOLEAN)(SigningTime->Day < RevocationTime->Day);
1092 }
else if (SigningTime->Hour != RevocationTime->Hour) {
1093 return (BOOLEAN)(SigningTime->Hour < RevocationTime->Hour);
1094 }
else if (SigningTime->Minute != RevocationTime->Minute) {
1095 return (BOOLEAN)(SigningTime->Minute < RevocationTime->Minute);
1098 return (BOOLEAN)(SigningTime->Second <= RevocationTime->Second);
1115 if ((Time->Year == 0) && (Time->Month == 0) && (Time->Day == 0) &&
1116 (Time->Hour == 0) && (Time->Minute == 0) && (Time->Second == 0))
1146 BOOLEAN VerifyStatus;
1160 VerifyStatus =
FALSE;
1180 if (Status != EFI_BUFFER_TOO_SMALL) {
1185 if (DbtData ==
NULL) {
1190 if (EFI_ERROR (Status)) {
1199 for (Index = 0; Index < CertCount; Index++) {
1213 VerifyStatus =
TRUE;
1227 if (DbtData !=
NULL) {
1231 return VerifyStatus;
1252 BOOLEAN IsForbidden;
1266 UINTN TrustedCertLength;
1286 TrustedCertLength = 0;
1293 ASSERT (EFI_ERROR (Status));
1294 if (Status != EFI_BUFFER_TOO_SMALL) {
1295 if (Status == EFI_NOT_FOUND) {
1299 IsForbidden =
FALSE;
1311 if (EFI_ERROR (Status)) {
1320 CertListSize = DataSize;
1326 for (Index = 0; Index < CertCount; Index++) {
1345 DEBUG ((DEBUG_INFO,
"DxeImageVerificationLib: Image is signed but signature is forbidden by DBX.\n"));
1373 Pkcs7GetSigners (AuthData, AuthDataSize, &CertBuffer, &BufferLength, &TrustedCert, &TrustedCertLength);
1374 if ((BufferLength == 0) || (CertBuffer ==
NULL) || ((*CertBuffer) == 0)) {
1382 CertNumber = (UINT8)(*CertBuffer);
1383 CertPtr = CertBuffer + 1;
1384 for (Index = 0; Index < CertNumber; Index++) {
1386 Cert = (UINT8 *)CertPtr +
sizeof (UINT32);
1390 CertPtr = CertPtr +
sizeof (UINT32) + CertSize;
1393 if (EFI_ERROR (Status)) {
1399 }
else if (IsFound) {
1405 IsForbidden =
FALSE;
1412 DEBUG ((DEBUG_INFO,
"DxeImageVerificationLib: Image is signed but signature failed the timestamp check.\n"));
1418 IsForbidden =
FALSE;
1448 BOOLEAN VerifyStatus;
1468 VerifyStatus =
FALSE;
1476 ASSERT (EFI_ERROR (Status));
1477 if (Status != EFI_BUFFER_TOO_SMALL) {
1478 return VerifyStatus;
1483 return VerifyStatus;
1487 if (EFI_ERROR (Status)) {
1498 ASSERT (EFI_ERROR (Status));
1499 if (Status != EFI_BUFFER_TOO_SMALL) {
1500 if (Status != EFI_NOT_FOUND) {
1512 if (DbxData ==
NULL) {
1517 if (EFI_ERROR (Status)) {
1531 for (Index = 0; Index < CertCount; Index++) {
1553 if (DbxData !=
NULL) {
1558 if (EFI_ERROR (Status)) {
1563 VerifyStatus =
FALSE;
1564 }
else if (IsFound) {
1569 if (!VerifyStatus) {
1570 DEBUG ((DEBUG_INFO,
"DxeImageVerificationLib: Image is signed and signature is accepted by DB, but its root cert failed the timestamp check.\n"));
1602 if (DbxData !=
NULL) {
1606 return VerifyStatus;
1659 IN UINT32 AuthenticationStatus,
1661 IN VOID *FileBuffer,
1663 IN BOOLEAN BootPolicy
1669 UINTN SignatureListSize;
1671 EFI_IMAGE_EXECUTION_ACTION Action;
1675 UINTN SecureBootSize;
1677 UINT32 NumberOfRvaAndSizes;
1683 UINT32 SecDataDirEnd;
1684 UINT32 SecDataDirLeft;
1687 RETURN_STATUS PeCoffStatus;
1694 BOOLEAN IsFoundInDatabase;
1696 SignatureList =
NULL;
1697 SignatureListSize = 0;
1698 WinCertificate =
NULL;
1700 PkcsCertData =
NULL;
1701 Action = EFI_IMAGE_EXECUTION_AUTH_UNTESTED;
1704 IsFoundInDatabase =
FALSE;
1711 Policy = ALWAYS_EXECUTE;
1714 case IMAGE_FROM_OPTION_ROM:
1715 Policy =
PcdGet32 (PcdOptionRomImageVerificationPolicy);
1718 case IMAGE_FROM_REMOVABLE_MEDIA:
1719 Policy =
PcdGet32 (PcdRemovableMediaImageVerificationPolicy);
1722 case IMAGE_FROM_FIXED_MEDIA:
1723 Policy =
PcdGet32 (PcdFixedMediaImageVerificationPolicy);
1727 Policy = DENY_EXECUTE_ON_SECURITY_VIOLATION;
1734 if (Policy == ALWAYS_EXECUTE) {
1738 if (Policy == NEVER_EXECUTE) {
1739 return EFI_ACCESS_DENIED;
1746 ASSERT (Policy != QUERY_USER_ON_SECURITY_VIOLATION && Policy != ALLOW_EXECUTE_ON_SECURITY_VIOLATION);
1747 if ((Policy == QUERY_USER_ON_SECURITY_VIOLATION) || (Policy == ALLOW_EXECUTE_ON_SECURITY_VIOLATION)) {
1751 SecureBootSize =
sizeof (SecureBoot);
1756 if (VarStatus == EFI_NOT_FOUND) {
1764 (VarAttr == (EFI_VARIABLE_BOOTSERVICE_ACCESS |
1765 EFI_VARIABLE_RUNTIME_ACCESS)) &&
1766 (SecureBoot == SECURE_BOOT_MODE_DISABLE))
1774 if (FileBuffer ==
NULL) {
1775 return EFI_ACCESS_DENIED;
1778 mImageBase = (UINT8 *)FileBuffer;
1779 mImageSize = FileSize;
1781 ZeroMem (&ImageContext,
sizeof (ImageContext));
1782 ImageContext.
Handle = (VOID *)FileBuffer;
1793 DEBUG ((DEBUG_INFO,
"DxeImageVerificationLib: PeImage invalid. Cannot retrieve image information.\n"));
1798 if (DosHdr->
e_magic == EFI_IMAGE_DOS_SIGNATURE) {
1803 mPeCoffHeaderOffset = DosHdr->
e_lfanew;
1805 mPeCoffHeaderOffset = 0;
1812 if (mNtHeader.Pe32->Signature != EFI_IMAGE_NT_SIGNATURE) {
1816 DEBUG ((DEBUG_INFO,
"DxeImageVerificationLib: Not a valid PE/COFF image.\n"));
1824 NumberOfRvaAndSizes = mNtHeader.Pe32->OptionalHeader.NumberOfRvaAndSizes;
1825 if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_SECURITY) {
1826 SecDataDir = (
EFI_IMAGE_DATA_DIRECTORY *)&mNtHeader.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY];
1832 NumberOfRvaAndSizes = mNtHeader.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;
1833 if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_SECURITY) {
1834 SecDataDir = (
EFI_IMAGE_DATA_DIRECTORY *)&mNtHeader.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY];
1841 if ((SecDataDir ==
NULL) || (SecDataDir->Size == 0)) {
1846 HashAlg =
sizeof (mHash) /
sizeof (
HASH_TABLE);
1847 while (HashAlg > 0) {
1864 if (EFI_ERROR (DbStatus) || IsFound) {
1868 DEBUG ((DEBUG_INFO,
"DxeImageVerificationLib: Image is not signed and %s hash of image is forbidden by DBX.\n", mHashTypeStr));
1879 if (!EFI_ERROR (DbStatus) && IsFound) {
1883 IsFoundInDatabase =
TRUE;
1887 if (IsFoundInDatabase) {
1894 DEBUG ((DEBUG_INFO,
"DxeImageVerificationLib: Image is not signed and %s hash of image is not found in DB/DBX.\n", mHashTypeStr));
1903 SecDataDirEnd = SecDataDir->VirtualAddress + SecDataDir->Size;
1904 for (OffSet = SecDataDir->VirtualAddress;
1905 OffSet < SecDataDirEnd;
1906 OffSet += (WinCertificate->
dwLength + ALIGN_SIZE (WinCertificate->
dwLength)))
1908 SecDataDirLeft = SecDataDirEnd - OffSet;
1914 if ((SecDataDirLeft < WinCertificate->dwLength) ||
1915 (SecDataDirLeft - WinCertificate->
dwLength <
1916 ALIGN_SIZE (WinCertificate->
dwLength)))
1930 if (PkcsCertData->Hdr.
dwLength <= sizeof (PkcsCertData->Hdr)) {
1934 AuthData = PkcsCertData->CertData;
1935 AuthDataSize = PkcsCertData->Hdr.
dwLength -
sizeof (PkcsCertData->Hdr);
1949 AuthData = WinCertUefiGuid->
CertData;
1960 if (EFI_ERROR (HashStatus)) {
1968 Action = EFI_IMAGE_EXECUTION_AUTH_SIG_FAILED;
1992 if (EFI_ERROR (DbStatus) || IsFound) {
1993 Action = EFI_IMAGE_EXECUTION_AUTH_SIG_FOUND;
1994 DEBUG ((DEBUG_INFO,
"DxeImageVerificationLib: Image is signed but %s hash of image is found in DBX.\n", mHashTypeStr));
2007 if (!EFI_ERROR (DbStatus) && IsFound) {
2010 Action = EFI_IMAGE_EXECUTION_AUTH_SIG_NOT_FOUND;
2011 DEBUG ((DEBUG_INFO,
"DxeImageVerificationLib: Image is signed but signature is not allowed by DB and %s hash of image is not found in DB/DBX.\n", mHashTypeStr));
2016 if (OffSet != SecDataDirEnd) {
2027 if ((Action == EFI_IMAGE_EXECUTION_AUTH_SIG_FAILED) || (Action == EFI_IMAGE_EXECUTION_AUTH_SIG_FOUND)) {
2033 if (SignatureList ==
NULL) {
2034 SignatureListSize = 0;
2052 AddImageExeInfo (Action, NameStr, File, SignatureList, SignatureListSize);
2053 if (NameStr !=
NULL) {
2054 DEBUG ((DEBUG_INFO,
"The image doesn't pass verification: %s\n", NameStr));
2058 if (SignatureList !=
NULL) {
2062 if (Policy == DEFER_EXECUTE_ON_SECURITY_VIOLATION) {
2063 return EFI_SECURITY_VIOLATION;
2066 return EFI_ACCESS_DENIED;
2086 UINTN ImageExeInfoTableSize;
2089 if (ImageExeInfoTable !=
NULL) {
2095 if (ImageExeInfoTable ==
NULL) {
2100 gBS->InstallConfigurationTable (&gEfiImageSecurityDatabaseGuid, (VOID *)ImageExeInfoTable);
UINTN EFIAPI Sha256GetContextSize(VOID)
UINTN EFIAPI Sha384GetContextSize(VOID)
BOOLEAN EFIAPI Sha512Final(IN OUT VOID *Sha512Context, OUT UINT8 *HashValue)
UINTN EFIAPI Sha512GetContextSize(VOID)
BOOLEAN EFIAPI Sha1Final(IN OUT VOID *Sha1Context, OUT UINT8 *HashValue)
BOOLEAN EFIAPI Sha512Init(OUT VOID *Sha512Context)
#define SHA512_DIGEST_SIZE
BOOLEAN EFIAPI Sha256Init(OUT VOID *Sha256Context)
BOOLEAN EFIAPI Pkcs7GetSigners(IN CONST UINT8 *P7Data, IN UINTN P7Length, OUT UINT8 **CertStack, OUT UINTN *StackLength, OUT UINT8 **TrustedCert, OUT UINTN *CertLength)
BOOLEAN EFIAPI AuthenticodeVerify(IN CONST UINT8 *AuthData, IN UINTN DataSize, IN CONST UINT8 *TrustedCert, IN UINTN CertSize, IN CONST UINT8 *ImageHash, IN UINTN HashSize)
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 Sha1Init(OUT VOID *Sha1Context)
BOOLEAN EFIAPI Sha256Update(IN OUT VOID *Sha256Context, IN CONST VOID *Data, IN UINTN DataSize)
VOID EFIAPI Pkcs7FreeSigners(IN UINT8 *Certs)
BOOLEAN EFIAPI ImageTimestampVerify(IN CONST UINT8 *AuthData, IN UINTN DataSize, IN CONST UINT8 *TsaCert, IN UINTN CertSize, OUT EFI_TIME *SigningTime)
UINTN EFIAPI Sha1GetContextSize(VOID)
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)
BOOLEAN EFIAPI Sha1Update(IN OUT VOID *Sha1Context, IN CONST VOID *Data, IN UINTN DataSize)
#define SHA384_DIGEST_SIZE
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
VOID EFIAPI CpuDeadLoop(VOID)
UINT32 EFIAPI WriteUnaligned32(OUT UINT32 *Buffer, IN UINT32 Value)
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)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define MEDIA_RELATIVE_OFFSET_RANGE_DP
#define MESSAGING_DEVICE_PATH
UINT8 EFIAPI DevicePathType(IN CONST VOID *Node)
UINT8 EFIAPI DevicePathSubType(IN CONST VOID *Node)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI NextDevicePathNode(IN CONST VOID *Node)
CHAR16 *EFIAPI ConvertDevicePathToText(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN BOOLEAN DisplayOnly, IN BOOLEAN AllowShortcuts)
UINTN EFIAPI GetDevicePathSize(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
BOOLEAN EFIAPI IsDevicePathEndType(IN CONST VOID *Node)
BOOLEAN HashPeImage(IN UINT32 HashAlg)
BOOLEAN IsForbiddenByDbx(IN UINT8 *AuthData, IN UINTN AuthDataSize)
EFI_STATUS IsSignatureFoundInDatabase(IN CHAR16 *VariableName, IN UINT8 *Signature, IN EFI_GUID *CertType, IN UINTN SignatureSize, OUT BOOLEAN *IsFound)
EFI_STATUS IsCertHashFoundInDbx(IN UINT8 *Certificate, IN UINTN CertSize, IN EFI_SIGNATURE_LIST *SignatureList, IN UINTN SignatureListSize, OUT EFI_TIME *RevocationTime, OUT BOOLEAN *IsFound)
EFI_STATUS EFIAPI DxeImageVerificationHandler(IN UINT32 AuthenticationStatus, IN CONST EFI_DEVICE_PATH_PROTOCOL *File OPTIONAL, IN VOID *FileBuffer, IN UINTN FileSize, IN BOOLEAN BootPolicy)
EFI_STATUS HashPeImageByType(IN UINT8 *AuthData, IN UINTN AuthDataSize)
VOID AddImageExeInfo(IN EFI_IMAGE_EXECUTION_ACTION Action, IN CHAR16 *Name OPTIONAL, IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN EFI_SIGNATURE_LIST *Signature OPTIONAL, IN UINTN SignatureSize)
UINT32 GetImageType(IN CONST EFI_DEVICE_PATH_PROTOCOL *File)
EFI_STATUS EFIAPI DxeImageVerificationLibImageRead(IN VOID *FileHandle, IN UINTN FileOffset, IN OUT UINTN *ReadSize, OUT VOID *Buffer)
BOOLEAN IsTimeZero(IN EFI_TIME *Time)
VOID EFIAPI OnReadyToBoot(IN EFI_EVENT Event, IN VOID *Context)
BOOLEAN IsValidSignatureByTimestamp(IN EFI_TIME *SigningTime, IN EFI_TIME *RevocationTime)
EFI_STATUS EFIAPI DxeImageVerificationLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
VOID EFIAPI SecureBootHook(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINTN DataSize, IN VOID *Data)
BOOLEAN PassTimestampCheck(IN UINT8 *AuthData, IN UINTN AuthDataSize, IN EFI_TIME *RevocationTime)
BOOLEAN IsAllowedByDb(IN UINT8 *AuthData, IN UINTN AuthDataSize)
UINTN GetImageExeInfoTableSize(EFI_IMAGE_EXECUTION_INFO_TABLE *ImageExeInfoTable)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateRuntimePool(IN UINTN AllocationSize)
#define EFI_SECURE_BOOT_MODE_NAME
EFI_STATUS EFIAPI HashUpdate(IN HASH_HANDLE HashHandle, IN VOID *DataToHash, IN UINTN DataToHashLen)
#define EFI_IMAGE_SECURITY_DATABASE2
#define EFI_IMAGE_SECURITY_DATABASE1
#define EFI_IMAGE_SECURITY_DATABASE
EFI_RUNTIME_SERVICES * gRT
#define RETURN_ERROR(StatusCode)
#define OFFSET_OF(TYPE, Field)
#define DEBUG(Expression)
#define PcdGet32(TokenName)
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
#define EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
#define EFI_AUTH_OPERATION_IMAGE_REQUIRED
EFI_STATUS EFIAPI RegisterSecurity2Handler(IN SECURITY2_FILE_AUTHENTICATION_HANDLER Security2Handler, IN UINT32 AuthenticationOperation)
EFI_STATUS EFIAPI EfiGetSystemConfigurationTable(IN EFI_GUID *TableGuid, OUT VOID **Table)
EFI_STATUS EFIAPI EfiCreateEventReadyToBootEx(IN EFI_TPL NotifyTpl, IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL, IN VOID *NotifyContext OPTIONAL, OUT EFI_EVENT *ReadyToBootEvent)
EFI_BLOCK_IO_MEDIA * Media
UINT32 e_lfanew
File address of new exe header.
UINT16 e_magic
Magic number.
UINT32 SignatureHeaderSize
HASH_FINAL HashFinal
Pointer to Hash Final function.
CHAR16 * Name
Name for Hash Algorithm.
HASH_UPDATE HashUpdate
Pointer to Hash Update function.
HASH_GET_CONTEXT_SIZE GetContextSize
Pointer to Hash GetContentSize function.
HASH_INIT HashInit
Pointer to Hash Init function.
PE_COFF_LOADER_READ_FILE ImageRead