10#include "InternalCryptLib.h"
11#include <mbedtls/pkcs7.h>
17 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x01, 0x04
52 CONST UINT8 *OrigAuthData;
53 UINT8 *SpcIndirectDataContent;
56 CONST UINT8 *SpcIndirectDataOid;
62 OrigAuthData = AuthData;
67 if ((AuthData ==
NULL) || (TrustedCert ==
NULL) || (ImageHash ==
NULL)) {
71 if ((DataSize > INT_MAX) || (CertSize > INT_MAX) || (HashSize > INT_MAX)) {
75 if (DataSize <= HashSize) {
79 Ptr = (UINT8 *)(
UINTN)AuthData;
80 Len = (UINT32)DataSize;
84 if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
89 if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_OID) != 0) {
95 if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC) != 0) {
101 if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
106 if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_INTEGER) != 0) {
112 if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET) != 0) {
119 if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE) != 0) {
125 if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_OID) != 0) {
131 SpcIndirectDataOid = Ptr;
132 if ((ObjLen !=
sizeof (mSpcIndirectOidValue)) ||
135 mSpcIndirectOidValue,
136 sizeof (mSpcIndirectOidValue)
147 if (mbedtls_asn1_get_tag (&Ptr, End, &ObjLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC) != 0) {
151 SpcIndirectDataContent = Ptr;
156 Asn1Byte = *(SpcIndirectDataContent + 1);
158 if ((Asn1Byte & 0x80) == 0) {
162 ContentSize = (
UINTN)(Asn1Byte & 0x7F);
166 SpcIndirectDataContent += 2;
167 }
else if ((Asn1Byte & 0x81) == 0x81) {
171 ContentSize = (
UINTN)(*(UINT8 *)(SpcIndirectDataContent + 2));
175 SpcIndirectDataContent += 3;
176 }
else if ((Asn1Byte & 0x82) == 0x82) {
180 ContentSize = (
UINTN)(*(UINT8 *)(SpcIndirectDataContent + 2));
181 ContentSize = (ContentSize << 8) + (
UINTN)(*(UINT8 *)(SpcIndirectDataContent + 3));
185 SpcIndirectDataContent += 4;
195 if (ContentSize < HashSize) {
199 if (
CompareMem (SpcIndirectDataContent + ContentSize - HashSize, ImageHash, HashSize) != 0) {
209 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)