17#include "InternalCryptLib.h"
19#include <openssl/objects.h>
20#include <openssl/x509.h>
21#include <openssl/pkcs7.h>
27 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x04
70 CONST UINT8 *OrigAuthData;
71 UINT8 *SpcIndirectDataContent;
74 CONST UINT8 *SpcIndirectDataOid;
79 if ((AuthData ==
NULL) || (TrustedCert ==
NULL) || (ImageHash ==
NULL)) {
83 if ((DataSize > INT_MAX) || (CertSize > INT_MAX) || (HashSize > INT_MAX)) {
89 OrigAuthData = AuthData;
95 Pkcs7 = d2i_PKCS7 (
NULL, &Temp, (
int)DataSize);
103 if (!PKCS7_type_is_signed (Pkcs7) || PKCS7_get_detached (Pkcs7)) {
112 SpcIndirectDataOid = OBJ_get0_data (Pkcs7->d.sign->contents->type);
113 if ((OBJ_length (Pkcs7->d.sign->contents->type) != sizeof (mSpcIndirectOidValue)) ||
116 mSpcIndirectOidValue,
117 sizeof (mSpcIndirectOidValue)
126 SpcIndirectDataContent = (UINT8 *)(Pkcs7->d.sign->contents->d.other->value.asn1_string->data);
131 Asn1Byte = *(SpcIndirectDataContent + 1);
133 if ((Asn1Byte & 0x80) == 0) {
137 ContentSize = (
UINTN)(Asn1Byte & 0x7F);
141 SpcIndirectDataContent += 2;
142 }
else if ((Asn1Byte & 0x81) == 0x81) {
146 ContentSize = (
UINTN)(*(UINT8 *)(SpcIndirectDataContent + 2));
150 SpcIndirectDataContent += 3;
151 }
else if ((Asn1Byte & 0x82) == 0x82) {
155 ContentSize = (
UINTN)(*(UINT8 *)(SpcIndirectDataContent + 2));
156 ContentSize = (ContentSize << 8) + (
UINTN)(*(UINT8 *)(SpcIndirectDataContent + 3));
160 SpcIndirectDataContent += 4;
170 if (
CompareMem (SpcIndirectDataContent + ContentSize - HashSize, ImageHash, HashSize) != 0) {
180 Status = (BOOLEAN)
Pkcs7Verify (OrigAuthData, DataSize, TrustedCert, CertSize, SpcIndirectDataContent, ContentSize);
BOOLEAN EFIAPI Pkcs7Verify(IN CONST UINT8 *P7Data, IN UINTN P7Length, IN CONST UINT8 *TrustedCert, IN UINTN CertLength, IN CONST UINT8 *InData, IN UINTN DataLength)
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define GLOBAL_REMOVE_IF_UNREFERENCED
BOOLEAN EFIAPI AuthenticodeVerify(IN CONST UINT8 *AuthData, IN UINTN DataSize, IN CONST UINT8 *TrustedCert, IN UINTN CertSize, IN CONST UINT8 *ImageHash, IN UINTN HashSize)