TianoCore EDK2 master
Loading...
Searching...
No Matches
CryptPkcs7VerifyBase.c
Go to the documentation of this file.
1
9#include "InternalCryptLib.h"
10#include <mbedtls/pkcs7.h>
11
32BOOLEAN
33EFIAPI
35 IN CONST UINT8 *P7Data,
36 IN UINTN P7Length,
37 OUT VOID **Content,
38 OUT UINTN *ContentSize
39 )
40{
41 BOOLEAN Status;
42 UINT8 *SignedData;
43 UINTN SignedDataSize;
44 BOOLEAN Wrapped;
45 INTN Ret;
46 mbedtls_pkcs7 Pkcs7;
47 mbedtls_pkcs7_data *MbedtlsContent;
48
49 mbedtls_pkcs7_init (&Pkcs7);
50
51 //
52 // Check input parameter.
53 //
54 if ((P7Data == NULL) || (P7Length > INT_MAX) || (Content == NULL) || (ContentSize == NULL)) {
55 return FALSE;
56 }
57
58 *Content = NULL;
59 SignedData = NULL;
60
61 Status = WrapPkcs7Data (P7Data, P7Length, &Wrapped, &SignedData, &SignedDataSize);
62 if (!Status || (SignedDataSize > INT_MAX)) {
63 goto _Exit;
64 }
65
66 Status = FALSE;
67
68 Ret = mbedtls_pkcs7_parse_der (&Pkcs7, SignedData, (INT32)SignedDataSize);
69
70 //
71 // The type of Pkcs7 must be signedData
72 //
73 if (Ret != MBEDTLS_PKCS7_SIGNED_DATA) {
74 goto _Exit;
75 }
76
77 //
78 // Check for detached or attached content
79 //
80 MbedtlsContent = &(Pkcs7.signed_data.content);
81
82 if (MbedtlsContent == NULL) {
83 //
84 // No Content supplied for PKCS7 detached signedData
85 //
86 *Content = NULL;
87 *ContentSize = 0;
88 } else {
89 //
90 // Retrieve the attached content in PKCS7 signedData
91 //
92 if ((MbedtlsContent->data.len > 0) && (MbedtlsContent->data.p != NULL)) {
93 *ContentSize = MbedtlsContent->data.len;
94 *Content = AllocateZeroPool (*ContentSize);
95 if (*Content == NULL) {
96 *ContentSize = 0;
97 goto _Exit;
98 }
99
100 CopyMem (*Content, MbedtlsContent->data.p, *ContentSize);
101 }
102 }
103
104 Status = TRUE;
105
106_Exit:
107 //
108 // Release Resources
109 //
110 mbedtls_pkcs7_free (&Pkcs7);
111
112 return Status;
113}
UINT64 UINTN
INT64 INTN
BOOLEAN WrapPkcs7Data(IN CONST UINT8 *P7Data, IN UINTN P7Length, OUT BOOLEAN *WrapFlag, OUT UINT8 **WrapData, OUT UINTN *WrapDataSize)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
BOOLEAN EFIAPI Pkcs7GetAttachedContent(IN CONST UINT8 *P7Data, IN UINTN P7Length, OUT VOID **Content, OUT UINTN *ContentSize)