]>
git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7VerifyBase.c
a5442bd4b456645ca0882a3c82102bb93452767c
2 Non-runtime specific implementation of PKCS#7 SignedData Verification Wrapper.
4 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "InternalCryptLib.h"
17 #include <openssl/objects.h>
18 #include <openssl/x509.h>
19 #include <openssl/x509v3.h>
20 #include <openssl/pkcs7.h>
23 Extracts the attached content from a PKCS#7 signed data if existed. The input signed
24 data could be wrapped in a ContentInfo structure.
26 If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow,
27 then return FALSE. If the P7Data is not correctly formatted, then return FALSE.
29 Caution: This function may receive untrusted input. So this function will do
30 basic check for PKCS#7 data structure.
32 @param[in] P7Data Pointer to the PKCS#7 signed data to process.
33 @param[in] P7Length Length of the PKCS#7 signed data in bytes.
34 @param[out] Content Pointer to the extracted content from the PKCS#7 signedData.
35 It's caller's responsibility to free the buffer with FreePool().
36 @param[out] ContentSize The size of the extracted content in bytes.
38 @retval TRUE The P7Data was correctly formatted for processing.
39 @retval FALSE The P7Data was not correctly formatted for processing.
44 Pkcs7GetAttachedContent (
45 IN CONST UINT8
*P7Data
,
48 OUT UINTN
*ContentSize
57 ASN1_OCTET_STRING
*OctStr
;
60 // Check input parameter.
62 if ((P7Data
== NULL
) || (P7Length
> INT_MAX
) || (Content
== NULL
) || (ContentSize
== NULL
)) {
71 Status
= WrapPkcs7Data (P7Data
, P7Length
, &Wrapped
, &SignedData
, &SignedDataSize
);
72 if (!Status
|| (SignedDataSize
> INT_MAX
)) {
79 // Decoding PKCS#7 SignedData
82 Pkcs7
= d2i_PKCS7 (NULL
, (const unsigned char **)&Temp
, (int)SignedDataSize
);
88 // The type of Pkcs7 must be signedData
90 if (!PKCS7_type_is_signed (Pkcs7
)) {
95 // Check for detached or attached content
97 if (PKCS7_get_detached (Pkcs7
)) {
99 // No Content supplied for PKCS7 detached signedData
105 // Retrieve the attached content in PKCS7 signedData
107 OctStr
= Pkcs7
->d
.sign
->contents
->d
.data
;
108 if ((OctStr
->length
> 0) && (OctStr
->data
!= NULL
)) {
109 *ContentSize
= OctStr
->length
;
110 *Content
= AllocatePool (*ContentSize
);
111 if (*Content
== NULL
) {
115 CopyMem (*Content
, OctStr
->data
, *ContentSize
);
127 OPENSSL_free (SignedData
);