CryptoPkg: Add Pkcs7 related functions based on Mbedtls
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4177 Because the current Mbedlts pkcs7 library doesn't support authenticatedAttributes and only support 0 or 1 certificates in Signed data, the patch implement Pkcs7 by low Mbedtls Api. And the implementation has pass unit_tes and integration test. Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Yi Li <yi1.li@intel.com> Signed-off-by: Wenxing Hou <wenxing.hou@intel.com> Reviewed-by: Yi Li <yi1.li@intel.com> Acked-by: Jiewen Yao <Jiewen.yao@intel.com>
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
RFC 2315 - PKCS #7: Cryptographic Message Syntax Version 1.5
|
||||
|
||||
Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2023-2024, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
@@ -31,10 +31,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
#define MBEDTLS_OID_PKCS7_DIGESTED_DATA MBEDTLS_OID_PKCS7 "\x05"
|
||||
#define MBEDTLS_OID_PKCS7_ENCRYPTED_DATA MBEDTLS_OID_PKCS7 "\x06"
|
||||
|
||||
typedef mbedtls_asn1_buf MBEDTLSPKCS7BUF;
|
||||
typedef mbedtls_asn1_named_data MBEDTLSPKCS7NAME;
|
||||
typedef mbedtls_asn1_sequence MBEDTLSPKCS7SEQUENCE;
|
||||
|
||||
///
|
||||
/// PKCS7 SignerInfo type
|
||||
/// https://tools.ietf.org/html/rfc2315#section-9.2
|
||||
@@ -48,8 +44,8 @@ typedef struct MbedtlsPkcs7SignerInfo {
|
||||
mbedtls_x509_buf SigAlgIdentifier;
|
||||
mbedtls_x509_buf AuthAttr;
|
||||
mbedtls_x509_buf Sig;
|
||||
struct MBEDTLSPKCS7SIGNERINFO *Next;
|
||||
} MBEDTLSPKCS7SIGNERINFO;
|
||||
struct MbedtlsPkcs7SignerInfo *Next;
|
||||
} MbedtlsPkcs7SignerInfo;
|
||||
|
||||
///
|
||||
/// PKCS7 signed data attached data format
|
||||
@@ -57,7 +53,7 @@ typedef struct MbedtlsPkcs7SignerInfo {
|
||||
typedef struct MbedtlsPkcs7Data {
|
||||
mbedtls_asn1_buf Oid;
|
||||
mbedtls_asn1_buf Data;
|
||||
} MBEDTLSPKCS7DATA;
|
||||
} MbedtlsPkcs7Data;
|
||||
|
||||
///
|
||||
/// Signed Data
|
||||
@@ -66,18 +62,27 @@ typedef struct MbedtlsPkcs7Data {
|
||||
typedef struct MbedtlsPkcs7SignedData {
|
||||
INT32 Version;
|
||||
mbedtls_asn1_buf DigestAlgorithms;
|
||||
struct MBEDTLSPKCS7DATA ContentInfo;
|
||||
struct MbedtlsPkcs7Data ContentInfo;
|
||||
mbedtls_x509_crt Certificates;
|
||||
mbedtls_x509_crl Crls;
|
||||
struct MbedtlsPkcs7SignerInfo SignerInfos;
|
||||
} MBEDTLSPKCS7SIGNEDDATA;
|
||||
} MbedtlsPkcs7SignedData;
|
||||
|
||||
///
|
||||
/// PKCS7 struct, only support SignedData
|
||||
///
|
||||
typedef struct MbedtlsPkcs7 {
|
||||
mbedtls_asn1_buf ContentTypeOid;
|
||||
struct MBEDTLSPKCS7SIGNEDDATA SignedData;
|
||||
} MBEDTLSPKCS7;
|
||||
struct MbedtlsPkcs7SignedData SignedData;
|
||||
} MbedtlsPkcs7;
|
||||
|
||||
#define EDKII_ASN1_CHK_ADD(g, f) \
|
||||
do \
|
||||
{ \
|
||||
if( ( Ret = (f) ) < 0 ) \
|
||||
return( Ret ); \
|
||||
else \
|
||||
(g) += Ret; \
|
||||
} while( 0 )
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user