From 7c33b0cac6801daa74c4ad258df51f26b4c67b41 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Fri, 10 Mar 2023 15:07:15 +0000 Subject: [PATCH 01/12] Remove pre-production warnings Signed-off-by: Dave Rodgman --- include/mbedtls/mbedtls_config.h | 6 +----- include/mbedtls/pkcs7.h | 7 +------ 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/include/mbedtls/mbedtls_config.h b/include/mbedtls/mbedtls_config.h index 7daba37400..63649f42ec 100644 --- a/include/mbedtls/mbedtls_config.h +++ b/include/mbedtls/mbedtls_config.h @@ -2862,10 +2862,6 @@ /** * \def MBEDTLS_PKCS7_C * - * This feature is a work in progress and not ready for production. Testing and - * validation is incomplete, and handling of malformed inputs may not be robust. - * The API may change. - * * Enable PKCS7 core for using PKCS7 formatted signatures. * RFC Link - https://tools.ietf.org/html/rfc2315 * @@ -2877,7 +2873,7 @@ * * This module is required for the PKCS7 parsing modules. */ -//#define MBEDTLS_PKCS7_C +#define MBEDTLS_PKCS7_C /** * \def MBEDTLS_PKCS12_C diff --git a/include/mbedtls/pkcs7.h b/include/mbedtls/pkcs7.h index 126eac4228..7f2aa9e9e5 100644 --- a/include/mbedtls/pkcs7.h +++ b/include/mbedtls/pkcs7.h @@ -22,12 +22,7 @@ */ /** - * This feature is a work in progress and not ready for production. The API may - * change. Furthermore, please note that the implementation has only been - * validated with well-formed inputs, not yet with untrusted inputs (which is - * almost always the case in practice). - * - * Note: For the time being, this implementation of the PKCS7 cryptographic + * Note: For the time being, this implementation of the PKCS #7 cryptographic * message syntax is a partial implementation of RFC 2315. * Differences include: * - The RFC specifies 6 different content types. The only type currently From d12b592bc1e0c019917d5cc6d6e58754a2f20e3d Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Fri, 10 Mar 2023 15:07:21 +0000 Subject: [PATCH 02/12] Changelog Signed-off-by: Dave Rodgman --- ChangeLog.d/pkcs7-parser.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 ChangeLog.d/pkcs7-parser.txt diff --git a/ChangeLog.d/pkcs7-parser.txt b/ChangeLog.d/pkcs7-parser.txt new file mode 100644 index 0000000000..a988e95859 --- /dev/null +++ b/ChangeLog.d/pkcs7-parser.txt @@ -0,0 +1,15 @@ +Features + * Added partial support for parsing the PKCS #7 cryptographic message + syntax, as defined in RFC 2315. Currently, support is limited to the + following: + - Only the signed data content type, version 1 is supported. + - Only DER encoding is supported. + - Only a single digest algorithm per message is supported. + - Only 0 or 1 certificates are supported per message, which must be in + X.509 format. + - There is no support for certificate-revocation lists. + - The authenticated and unauthenticated attribute fields of SignerInfo + must be empty. + Many thanks to Daniel Axtens, Nayna Jain, and Nick Child from IBM for + contributing this feature. Thanks to Demi-Marie Obenour for contributing + various improvements, tests and bug-fixes. From 3fe2abf306d2d2a50af22ba4ac96649be800c278 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Fri, 10 Mar 2023 17:05:54 +0000 Subject: [PATCH 03/12] Apply suggestions from code review Co-authored-by: Tom Cosgrove Signed-off-by: Dave Rodgman --- ChangeLog.d/pkcs7-parser.txt | 10 +++++----- include/mbedtls/mbedtls_config.h | 2 +- include/mbedtls/pkcs7.h | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ChangeLog.d/pkcs7-parser.txt b/ChangeLog.d/pkcs7-parser.txt index a988e95859..ac477b1f00 100644 --- a/ChangeLog.d/pkcs7-parser.txt +++ b/ChangeLog.d/pkcs7-parser.txt @@ -1,15 +1,15 @@ Features - * Added partial support for parsing the PKCS #7 cryptographic message - syntax, as defined in RFC 2315. Currently, support is limited to the + * Added partial support for parsing the PKCS #7 Cryptographic Message + Syntax, as defined in RFC 2315. Currently, support is limited to the following: - - Only the signed data content type, version 1 is supported. + - Only the signed-data content type, version 1 is supported. - Only DER encoding is supported. - Only a single digest algorithm per message is supported. - Only 0 or 1 certificates are supported per message, which must be in X.509 format. - - There is no support for certificate-revocation lists. + - There is no support for certificate revocation lists. - The authenticated and unauthenticated attribute fields of SignerInfo must be empty. Many thanks to Daniel Axtens, Nayna Jain, and Nick Child from IBM for contributing this feature. Thanks to Demi-Marie Obenour for contributing - various improvements, tests and bug-fixes. + various improvements, tests and bug fixes. diff --git a/include/mbedtls/mbedtls_config.h b/include/mbedtls/mbedtls_config.h index 63649f42ec..ffc216eb98 100644 --- a/include/mbedtls/mbedtls_config.h +++ b/include/mbedtls/mbedtls_config.h @@ -2862,7 +2862,7 @@ /** * \def MBEDTLS_PKCS7_C * - * Enable PKCS7 core for using PKCS7 formatted signatures. + * Enable PKCS #7 core for using PKCS #7-formatted signatures. * RFC Link - https://tools.ietf.org/html/rfc2315 * * Module: library/pkcs7.c diff --git a/include/mbedtls/pkcs7.h b/include/mbedtls/pkcs7.h index 7f2aa9e9e5..cf1555cfd0 100644 --- a/include/mbedtls/pkcs7.h +++ b/include/mbedtls/pkcs7.h @@ -22,8 +22,8 @@ */ /** - * Note: For the time being, this implementation of the PKCS #7 cryptographic - * message syntax is a partial implementation of RFC 2315. + * Note: For the time being, this implementation of the PKCS #7 Cryptographic + * Message Syntax is a partial implementation of RFC 2315. * Differences include: * - The RFC specifies 6 different content types. The only type currently * supported in Mbed TLS is the signed data content type. From 957cc36be984c9c18d46542cd8229b90900a02dc Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Fri, 10 Mar 2023 17:14:52 +0000 Subject: [PATCH 04/12] Improve wording; use PKCS #7 not PKCS7 Signed-off-by: Dave Rodgman --- ChangeLog.d/pkcs7-parser.txt | 6 ++-- include/mbedtls/pkcs7.h | 62 ++++++++++++++++++------------------ 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/ChangeLog.d/pkcs7-parser.txt b/ChangeLog.d/pkcs7-parser.txt index ac477b1f00..b60d187e85 100644 --- a/ChangeLog.d/pkcs7-parser.txt +++ b/ChangeLog.d/pkcs7-parser.txt @@ -5,11 +5,11 @@ Features - Only the signed-data content type, version 1 is supported. - Only DER encoding is supported. - Only a single digest algorithm per message is supported. - - Only 0 or 1 certificates are supported per message, which must be in - X.509 format. + - Certificates must be in X.509 format. A message must have either 0 + or 1 certificates. - There is no support for certificate revocation lists. - The authenticated and unauthenticated attribute fields of SignerInfo must be empty. Many thanks to Daniel Axtens, Nayna Jain, and Nick Child from IBM for - contributing this feature. Thanks to Demi-Marie Obenour for contributing + contributing this feature, and to Demi-Marie Obenour for contributing various improvements, tests and bug fixes. diff --git a/include/mbedtls/pkcs7.h b/include/mbedtls/pkcs7.h index cf1555cfd0..8e4bd4841c 100644 --- a/include/mbedtls/pkcs7.h +++ b/include/mbedtls/pkcs7.h @@ -1,7 +1,7 @@ /** * \file pkcs7.h * - * \brief PKCS7 generic defines and structures + * \brief PKCS #7 generic defines and structures * https://tools.ietf.org/html/rfc2315 */ /* @@ -22,12 +22,12 @@ */ /** - * Note: For the time being, this implementation of the PKCS #7 Cryptographic - * Message Syntax is a partial implementation of RFC 2315. - * Differences include: + * Note: For the time being, this implementation of the PKCS #7 cryptographic + * message syntax is a partial implementation of RFC 2315. + * Differences include:# * - The RFC specifies 6 different content types. The only type currently * supported in Mbed TLS is the signed data content type. - * - The only supported PKCS7 Signed Data syntax version is version 1 + * - The only supported PKCS #7 Signed Data syntax version is version 1 * - The RFC specifies support for BER. This implementation is limited to * DER only. * - The RFC specifies that multiple digest algorithms can be specified @@ -57,13 +57,13 @@ #include "mbedtls/x509_crt.h" /** - * \name PKCS7 Module Error codes + * \name PKCS #7 Module Error codes * \{ */ #define MBEDTLS_ERR_PKCS7_INVALID_FORMAT -0x5300 /**< The format is invalid, e.g. different type expected. */ #define MBEDTLS_ERR_PKCS7_FEATURE_UNAVAILABLE -0x5380 /**< Unavailable feature, e.g. anything other than signed data. */ -#define MBEDTLS_ERR_PKCS7_INVALID_VERSION -0x5400 /**< The PKCS7 version element is invalid or cannot be parsed. */ -#define MBEDTLS_ERR_PKCS7_INVALID_CONTENT_INFO -0x5480 /**< The PKCS7 content info is invalid or cannot be parsed. */ +#define MBEDTLS_ERR_PKCS7_INVALID_VERSION -0x5400 /**< The PKCS #7 version element is invalid or cannot be parsed. */ +#define MBEDTLS_ERR_PKCS7_INVALID_CONTENT_INFO -0x5480 /**< The PKCS #7 content info is invalid or cannot be parsed. */ #define MBEDTLS_ERR_PKCS7_INVALID_ALG -0x5500 /**< The algorithm tag or value is invalid or cannot be parsed. */ #define MBEDTLS_ERR_PKCS7_INVALID_CERT -0x5580 /**< The certificate tag or value is invalid or cannot be parsed. */ #define MBEDTLS_ERR_PKCS7_INVALID_SIGNATURE -0x5600 /**< Error parsing the signature */ @@ -71,11 +71,11 @@ #define MBEDTLS_ERR_PKCS7_BAD_INPUT_DATA -0x5700 /**< Input invalid. */ #define MBEDTLS_ERR_PKCS7_ALLOC_FAILED -0x5780 /**< Allocation of memory failed. */ #define MBEDTLS_ERR_PKCS7_VERIFY_FAIL -0x5800 /**< Verification Failed */ -#define MBEDTLS_ERR_PKCS7_CERT_DATE_INVALID -0x5880 /**< The PKCS7 date issued/expired dates are invalid */ +#define MBEDTLS_ERR_PKCS7_CERT_DATE_INVALID -0x5880 /**< The PKCS #7 date issued/expired dates are invalid */ /* \} name */ /** - * \name PKCS7 Supported Version + * \name PKCS #7 Supported Version * \{ */ #define MBEDTLS_PKCS7_SUPPORTED_VERSION 0x01 @@ -86,12 +86,12 @@ extern "C" { #endif /** - * Type-length-value structure that allows for ASN1 using DER. + * Type-length-value structure that allows for ASN.1 using DER. */ typedef mbedtls_asn1_buf mbedtls_pkcs7_buf; /** - * Container for ASN1 named information objects. + * Container for ASN.1 named information objects. * It allows for Relative Distinguished Names (e.g. cn=localhost,ou=code,etc.). */ typedef mbedtls_asn1_named_data mbedtls_pkcs7_name; @@ -102,7 +102,7 @@ typedef mbedtls_asn1_named_data mbedtls_pkcs7_name; typedef mbedtls_asn1_sequence mbedtls_pkcs7_sequence; /** - * PKCS7 types + * PKCS #7 types */ typedef enum { MBEDTLS_PKCS7_NONE=0, @@ -116,7 +116,7 @@ typedef enum { mbedtls_pkcs7_type; /** - * Structure holding PKCS7 signer info + * Structure holding PKCS #7 signer info */ typedef struct mbedtls_pkcs7_signer_info { int MBEDTLS_PRIVATE(version); @@ -146,7 +146,7 @@ typedef struct mbedtls_pkcs7_signed_data { mbedtls_pkcs7_signed_data; /** - * Structure holding PKCS7 structure, only signed data for now + * Structure holding PKCS #7 structure, only signed data for now */ typedef struct mbedtls_pkcs7 { mbedtls_pkcs7_buf MBEDTLS_PRIVATE(raw); @@ -155,21 +155,21 @@ typedef struct mbedtls_pkcs7 { mbedtls_pkcs7; /** - * \brief Initialize pkcs7 structure. + * \brief Initialize mbedtls_pkcs7 structure. * - * \param pkcs7 pkcs7 structure. + * \param pkcs7 mbedtls_pkcs7 structure. */ void mbedtls_pkcs7_init(mbedtls_pkcs7 *pkcs7); /** - * \brief Parse a single DER formatted pkcs7 detached signature. + * \brief Parse a single DER formatted PKCS #7 detached signature. * - * \param pkcs7 The pkcs7 structure to be filled by parser for the output. - * \param buf The buffer holding only the DER encoded pkcs7. + * \param pkcs7 The mbedtls_pkcs7 structure to be filled by the parser. + * \param buf The buffer holding only the DER encoded PKCS #7 content. * \param buflen The size in bytes of \p buf. The size must be exactly the - * length of the DER encoded pkcs7. + * length of the DER encoded PKCS #7 content. * - * \note This function makes an internal copy of the PKCS7 buffer + * \note This function makes an internal copy of the PKCS #7 buffer * \p buf. In particular, \p buf may be destroyed or reused * after this call returns. * \note Signatures with internal data are not supported. @@ -181,7 +181,7 @@ int mbedtls_pkcs7_parse_der(mbedtls_pkcs7 *pkcs7, const unsigned char *buf, const size_t buflen); /** - * \brief Verification of PKCS7 signature against a caller-supplied + * \brief Verification of PKCS #7 signature against a caller-supplied * certificate. * * For each signer in the PKCS structure, this function computes @@ -192,10 +192,10 @@ int mbedtls_pkcs7_parse_der(mbedtls_pkcs7 *pkcs7, const unsigned char *buf, * matches. * * This function does not use the certificates held within the - * PKCS7 structure itself, and does not check that the + * PKCS #7 structure itself, and does not check that the * certificate is signed by a trusted certification authority. * - * \param pkcs7 PKCS7 structure containing signature. + * \param pkcs7 mbedtls_pkcs7 structure containing signature. * \param cert Certificate containing key to verify signature. * \param data Plain data on which signature has to be verified. * \param datalen Length of the data. @@ -211,7 +211,7 @@ int mbedtls_pkcs7_signed_data_verify(mbedtls_pkcs7 *pkcs7, size_t datalen); /** - * \brief Verification of PKCS7 signature against a caller-supplied + * \brief Verification of PKCS #7 signature against a caller-supplied * certificate. * * For each signer in the PKCS structure, this function @@ -221,10 +221,10 @@ int mbedtls_pkcs7_signed_data_verify(mbedtls_pkcs7 *pkcs7, * signature is good. * * This function does not use the certificates held within the - * PKCS7 structure itself, and does not check that the + * PKCS #7 structure itself, and does not check that the * certificate is signed by a trusted certification authority. * - * \param pkcs7 PKCS7 structure containing signature. + * \param pkcs7 PKCS #7 structure containing signature. * \param cert Certificate containing key to verify signature. * \param hash Hash of the plain data on which signature has to be verified. * \param hashlen Length of the hash. @@ -239,10 +239,10 @@ int mbedtls_pkcs7_signed_hash_verify(mbedtls_pkcs7 *pkcs7, const unsigned char *hash, size_t hashlen); /** - * \brief Unallocate all PKCS7 data and zeroize the memory. - * It doesn't free pkcs7 itself. It should be done by the caller. + * \brief Unallocate all PKCS #7 data and zeroize the memory. + * It doesn't free \p pkcs7 itself. This should be done by the caller. * - * \param pkcs7 PKCS7 structure to free. + * \param pkcs7 mbedtls_pkcs7 structure to free. */ void mbedtls_pkcs7_free(mbedtls_pkcs7 *pkcs7); From 25b2dfa6dadcae669d7ea0c78e90ae8e340981d3 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Sat, 11 Mar 2023 13:00:41 +0000 Subject: [PATCH 05/12] Fix comment typo Signed-off-by: Dave Rodgman --- include/mbedtls/pkcs7.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mbedtls/pkcs7.h b/include/mbedtls/pkcs7.h index 8e4bd4841c..10a6322baa 100644 --- a/include/mbedtls/pkcs7.h +++ b/include/mbedtls/pkcs7.h @@ -24,7 +24,7 @@ /** * Note: For the time being, this implementation of the PKCS #7 cryptographic * message syntax is a partial implementation of RFC 2315. - * Differences include:# + * Differences include: * - The RFC specifies 6 different content types. The only type currently * supported in Mbed TLS is the signed data content type. * - The only supported PKCS #7 Signed Data syntax version is version 1 From 4fa8590b628d4bbfcaa1e2a77f412acab66623c9 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Sun, 12 Mar 2023 09:34:08 +0000 Subject: [PATCH 06/12] Fix test dependency Signed-off-by: Dave Rodgman --- tests/suites/test_suite_pkcs7.data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/suites/test_suite_pkcs7.data b/tests/suites/test_suite_pkcs7.data index 89c223dcbf..d7efcc4d8c 100644 --- a/tests/suites/test_suite_pkcs7.data +++ b/tests/suites/test_suite_pkcs7.data @@ -23,7 +23,7 @@ depends_on:MBEDTLS_SHA256_C:MBEDTLS_RSA_C pkcs7_parse:"data_files/pkcs7_data_signed_badcert.der":MBEDTLS_ERR_PKCS7_INVALID_CERT PKCS7 Signed Data Parse Fail with disabled alg #5.1 -depends_on:MBEDTLS_RSA_C:!MBEDTLS_SHA512_C +depends_on:MBEDTLS_RSA_C:!MBEDTLS_HAS_ALG_SHA_512_VIA_LOWLEVEL_OR_PSA pkcs7_parse:"data_files/pkcs7_data_cert_signed_sha512.der":MBEDTLS_ERR_PKCS7_INVALID_ALG PKCS7 Parse Fail with Inlined Content Info #5.2 From 651fb529f94d2787556c63dab08c9a859bf1e8dc Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Sun, 12 Mar 2023 10:00:44 +0000 Subject: [PATCH 07/12] Make pkcs7_parse test not depend on MBEDTLS_RSA_C Signed-off-by: Dave Rodgman --- tests/suites/test_suite_pkcs7.data | 14 +++++++------- tests/suites/test_suite_pkcs7.function | 3 ++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/suites/test_suite_pkcs7.data b/tests/suites/test_suite_pkcs7.data index d7efcc4d8c..9a3d4560e9 100644 --- a/tests/suites/test_suite_pkcs7.data +++ b/tests/suites/test_suite_pkcs7.data @@ -71,7 +71,7 @@ depends_on:MBEDTLS_SHA1_C:MBEDTLS_SHA256_C pkcs7_verify:"data_files/pkcs7_zerolendata_detached.der":"data_files/pkcs7-rsa-sha256-1.der":"data_files/pkcs7_zerolendata.bin":0:0 PKCS7 Signed Data Verification Fail zero-len data -depends_on:MBEDTLS_SHA1_C:MBEDTLS_SHA256_C +depends_on:MBEDTLS_SHA1_C:MBEDTLS_SHA256_C:MBEDTLS_RSA_C pkcs7_verify:"data_files/pkcs7_zerolendata_detached.der":"data_files/pkcs7-rsa-sha256-2.der":"data_files/pkcs7_zerolendata.bin":0:MBEDTLS_ERR_RSA_VERIFY_FAILED PKCS7 Signed Data Verification Pass SHA256 #9 @@ -91,19 +91,19 @@ depends_on:MBEDTLS_SHA512_C:MBEDTLS_SHA256_C pkcs7_verify:"data_files/pkcs7_data_cert_signed_sha512.der":"data_files/pkcs7-rsa-sha256-1.der":"data_files/pkcs7_data.bin":0:0 PKCS7 Signed Data Verification Fail because of different certificate #12 -depends_on:MBEDTLS_SHA256_C +depends_on:MBEDTLS_SHA256_C:MBEDTLS_RSA_C pkcs7_verify:"data_files/pkcs7_data_cert_signed_sha256.der":"data_files/pkcs7-rsa-sha256-2.der":"data_files/pkcs7_data.bin":0:MBEDTLS_ERR_RSA_VERIFY_FAILED PKCS7 Signed Data Verification Fail because of different data hash #13 -depends_on:MBEDTLS_SHA256_C +depends_on:MBEDTLS_SHA256_C:MBEDTLS_RSA_C pkcs7_verify:"data_files/pkcs7_data_cert_signed_sha256.der":"data_files/pkcs7-rsa-sha256-1.der":"data_files/pkcs7_data_1.bin":0:MBEDTLS_ERR_RSA_VERIFY_FAILED PKCS7 Signed Data Parse Failure Corrupt signerInfo.issuer #15.1 -depends_on:MBEDTLS_SHA256_C +depends_on:MBEDTLS_SHA256_C:MBEDTLS_RSA_C pkcs7_parse:"data_files/pkcs7_signerInfo_issuer_invalid_size.der":MBEDTLS_ERR_PKCS7_INVALID_SIGNER_INFO PKCS7 Signed Data Parse Failure Corrupt signerInfo.serial #15.2 -depends_on:MBEDTLS_SHA256_C +depends_on:MBEDTLS_SHA256_C:MBEDTLS_RSA_C pkcs7_parse:"data_files/pkcs7_signerInfo_serial_invalid_size.der":MBEDTLS_ERR_PKCS7_INVALID_SIGNER_INFO PKCS7 Signed Data Parse Fail Corrupt signerInfos[2] (6213931373035520) @@ -143,11 +143,11 @@ depends_on:MBEDTLS_SHA256_C:MBEDTLS_HAVE_TIME_DATE pkcs7_verify:"data_files/pkcs7_data_cert_signed_sha256.der":"data_files/pkcs7-rsa-expired.crt":"data_files/pkcs7_data.bin":0:MBEDTLS_ERR_PKCS7_CERT_DATE_INVALID PKCS7 Signed Data Verify Fail Expired Cert #19 no DATE_TIME 1 -depends_on:MBEDTLS_SHA256_C:!MBEDTLS_HAVE_TIME_DATE +depends_on:MBEDTLS_SHA256_C:!MBEDTLS_HAVE_TIME_DATE:MBEDTLS_RSA_C pkcs7_verify:"data_files/pkcs7_data_cert_signed_sha256.der":"data_files/pkcs7-rsa-expired.crt":"data_files/pkcs7_data.bin":0:MBEDTLS_ERR_RSA_VERIFY_FAILED PKCS7 Signed Data Verify Fail Expired Cert #19 no TIME_DATE 2 -depends_on:MBEDTLS_SHA256_C:!MBEDTLS_HAVE_TIME_DATE +depends_on:MBEDTLS_SHA256_C:!MBEDTLS_HAVE_TIME_DATE:MBEDTLS_RSA_C pkcs7_verify:"data_files/pkcs7_data_rsa_expired.der":"data_files/pkcs7-rsa-expired.crt":"data_files/pkcs7_data_1.bin":0:MBEDTLS_ERR_RSA_VERIFY_FAILED PKCS7 Parse Failure Invalid ASN1: Add null byte to start #20.0 diff --git a/tests/suites/test_suite_pkcs7.function b/tests/suites/test_suite_pkcs7.function index 91fe47b897..cc032ac12f 100644 --- a/tests/suites/test_suite_pkcs7.function +++ b/tests/suites/test_suite_pkcs7.function @@ -7,10 +7,11 @@ #include "mbedtls/oid.h" #include "sys/types.h" #include "sys/stat.h" +#include "mbedtls/rsa.h" /* END_HEADER */ /* BEGIN_DEPENDENCIES - * depends_on:MBEDTLS_PKCS7_C:MBEDTLS_RSA_C + * depends_on:MBEDTLS_PKCS7_C * END_DEPENDENCIES */ /* BEGIN_SUITE_HELPERS */ From 45bed94406a75226bc6a4142217d2cf111adfcab Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Sun, 12 Mar 2023 10:01:02 +0000 Subject: [PATCH 08/12] Add parse failure test when MBEDTLS_RSA_C not set Signed-off-by: Dave Rodgman --- tests/suites/test_suite_pkcs7.data | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/suites/test_suite_pkcs7.data b/tests/suites/test_suite_pkcs7.data index 9a3d4560e9..4ffc31e76a 100644 --- a/tests/suites/test_suite_pkcs7.data +++ b/tests/suites/test_suite_pkcs7.data @@ -30,6 +30,10 @@ PKCS7 Parse Fail with Inlined Content Info #5.2 depends_on:MBEDTLS_SHA256_C:MBEDTLS_RSA_C pkcs7_parse:"data_files/pkcs7_data_with_signature.der":MBEDTLS_ERR_PKCS7_FEATURE_UNAVAILABLE +PKCS7 Signed Data Parse Fail with no RSA #5.3 +depends_on:MBEDTLS_SHA256_C:!MBEDTLS_RSA_C +pkcs7_parse:"data_files/pkcs7_data_cert_signed_sha256.der":MBEDTLS_ERR_PKCS7_INVALID_CERT + PKCS7 Signed Data Parse Fail with corrupted signer info #6 depends_on:MBEDTLS_SHA256_C:MBEDTLS_RSA_C pkcs7_parse:"data_files/pkcs7_data_signed_badsigner.der":MBEDTLS_ERROR_ADD(MBEDTLS_ERR_PKCS7_INVALID_SIGNER_INFO,MBEDTLS_ERR_ASN1_UNEXPECTED_TAG) From 8e528ece74e580cc40830bfc9cbb446e72b9618a Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Sun, 12 Mar 2023 13:30:56 +0000 Subject: [PATCH 09/12] Disable test under MBEDTLS_MEMORY_BUFFER_ALLOC_C This test allocates too much memory to work when the alternative memory allocator is used. Signed-off-by: Dave Rodgman --- tests/suites/test_suite_pkcs7.data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/suites/test_suite_pkcs7.data b/tests/suites/test_suite_pkcs7.data index 4ffc31e76a..13fcaa6bd9 100644 --- a/tests/suites/test_suite_pkcs7.data +++ b/tests/suites/test_suite_pkcs7.data @@ -127,7 +127,7 @@ depends_on:MBEDTLS_SHA256_C pkcs7_verify:"data_files/pkcs7_data_multiple_signed.der":"data_files/pkcs7-rsa-sha256-1.crt data_files/pkcs7-rsa-sha256-2.crt":"data_files/pkcs7_data.bin":0:0 PKCS7 Signed Data Verify with multiple(3) signers #16.1 -depends_on:MBEDTLS_SHA256_C +depends_on:MBEDTLS_SHA256_C:!MBEDTLS_MEMORY_BUFFER_ALLOC_C pkcs7_verify:"data_files/pkcs7_data_3_signed.der":"data_files/pkcs7-rsa-sha256-1.crt data_files/pkcs7-rsa-sha256-2.crt data_files/pkcs7-rsa-sha256-3.crt":"data_files/pkcs7_data.bin":0:0 PKCS7 Signed Data Hash Verify with multiple signers #17 From efbc5f7322a9773dccb7ac76abe0bf06e12363c6 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Mon, 13 Mar 2023 12:15:49 +0000 Subject: [PATCH 10/12] Update wording in comments Signed-off-by: Dave Rodgman --- include/mbedtls/mbedtls_config.h | 2 +- include/mbedtls/pkcs7.h | 8 ++++---- library/pkcs7.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/mbedtls/mbedtls_config.h b/include/mbedtls/mbedtls_config.h index ffc216eb98..67e286d201 100644 --- a/include/mbedtls/mbedtls_config.h +++ b/include/mbedtls/mbedtls_config.h @@ -2871,7 +2871,7 @@ * MBEDTLS_X509_CRT_PARSE_C MBEDTLS_X509_CRL_PARSE_C, * MBEDTLS_BIGNUM_C, MBEDTLS_MD_C * - * This module is required for the PKCS7 parsing modules. + * This module is required for the PKCS #7 parsing modules. */ #define MBEDTLS_PKCS7_C diff --git a/include/mbedtls/pkcs7.h b/include/mbedtls/pkcs7.h index 10a6322baa..39f9b04ecd 100644 --- a/include/mbedtls/pkcs7.h +++ b/include/mbedtls/pkcs7.h @@ -32,12 +32,12 @@ * DER only. * - The RFC specifies that multiple digest algorithms can be specified * in the Signed Data type. Only one digest algorithm is supported in Mbed TLS. - * - The RFC specifies the Signed Data type can contain multiple X509 or PKCS6 + * - The RFC specifies the Signed Data type can contain multiple X.509 or PKCS #6 * certificates. In Mbed TLS, this list can only contain 0 or 1 certificates - * and they must be in X509 format. + * and they must be in X.509 format. * - The RFC specifies the Signed Data type can contain - * certificate-revocation lists (crls). This implementation has no support - * for crls so it is assumed to be an empty list. + * certificate-revocation lists (CRLs). This implementation has no support + * for CRLs so it is assumed to be an empty list. * - The RFC allows for SignerInfo structure to optionally contain * unauthenticatedAttributes and authenticatedAttributes. In Mbed TLS it is * assumed these fields are empty. diff --git a/library/pkcs7.c b/library/pkcs7.c index d4059d7458..cf05afd2c9 100644 --- a/library/pkcs7.c +++ b/library/pkcs7.c @@ -42,7 +42,7 @@ #endif /** - * Initializes the pkcs7 structure. + * Initializes the mbedtls_pkcs7 structure. */ void mbedtls_pkcs7_init(mbedtls_pkcs7 *pkcs7) { From bcc92d4f03607d81e2b61c1a37226f98eecb2001 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Tue, 14 Mar 2023 07:13:44 +0000 Subject: [PATCH 11/12] Update include/mbedtls/pkcs7.h Co-authored-by: Xiaokang Qian <53458466+xkqian@users.noreply.github.com> Signed-off-by: Dave Rodgman --- include/mbedtls/pkcs7.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mbedtls/pkcs7.h b/include/mbedtls/pkcs7.h index 39f9b04ecd..b6744cee2e 100644 --- a/include/mbedtls/pkcs7.h +++ b/include/mbedtls/pkcs7.h @@ -26,7 +26,7 @@ * message syntax is a partial implementation of RFC 2315. * Differences include: * - The RFC specifies 6 different content types. The only type currently - * supported in Mbed TLS is the signed data content type. + * supported in Mbed TLS is the signed-data content type. * - The only supported PKCS #7 Signed Data syntax version is version 1 * - The RFC specifies support for BER. This implementation is limited to * DER only. From cdaaef52f411c8e83669f9c7c5d4a0a849ab1de9 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Tue, 14 Mar 2023 07:13:50 +0000 Subject: [PATCH 12/12] Update include/mbedtls/pkcs7.h Co-authored-by: Xiaokang Qian <53458466+xkqian@users.noreply.github.com> Signed-off-by: Dave Rodgman --- include/mbedtls/pkcs7.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mbedtls/pkcs7.h b/include/mbedtls/pkcs7.h index b6744cee2e..1231e34024 100644 --- a/include/mbedtls/pkcs7.h +++ b/include/mbedtls/pkcs7.h @@ -32,7 +32,7 @@ * DER only. * - The RFC specifies that multiple digest algorithms can be specified * in the Signed Data type. Only one digest algorithm is supported in Mbed TLS. - * - The RFC specifies the Signed Data type can contain multiple X.509 or PKCS #6 + * - The RFC specifies the Signed Data type can contain multiple X.509 or PKCS #6 extended * certificates. In Mbed TLS, this list can only contain 0 or 1 certificates * and they must be in X.509 format. * - The RFC specifies the Signed Data type can contain