Skip to content

Add support for verifying PKCS7 signed attributes#2264

Merged
samuel40791765 merged 3 commits intoaws:mainfrom
samuel40791765:pkcs7-sign
Mar 25, 2025
Merged

Add support for verifying PKCS7 signed attributes#2264
samuel40791765 merged 3 commits intoaws:mainfrom
samuel40791765:pkcs7-sign

Conversation

@samuel40791765
Copy link
Copy Markdown
Contributor

Issues:

Resolves CryptoAlg-2946

Description of changes:

I discovered this while trying to fix our PKCS7 implementation to use indefinite encoding. The PKCS7 file that Ruby's PKCS7 tests uses signed attributes, but PKCS7_verify bails out whenever it encounters files that have signed attributes. There are still other issues with the Ruby PKCS7 test that we'll have to fix (indefinite length ASN1), but I believe we should fix the missing support for verifying signed attributes first.
AWS-LC turns on PKCS7_NOATTR by default in PKCS7_sign, so our existing PKCS7_verify implementation can do a successful sign/verify round trip against itself. However, OpenSSL does not turn on PKCS7_NOATTR by default and signed attributes are added automatically to the PKCS7 file if no flags are set. This means that the current state of AWS-LC's PKCS7_verify would fail against files generated by the default of OpenSSL's PKCS7_sign. This PR adds support for verifying PKCS7 signed attributes to fix the misalignment.

Call-outs:

N/A

Testing:

  1. Test file from Ruby. The intention is to build upon the test to fix the ASN1 indefinite length issues later on.
  2. Test file generated by OpenSSL. Our PKCS7_sign does not support signed attributes, so we can only test against generated files by OpenSSL.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

@samuel40791765 samuel40791765 requested a review from a team as a code owner March 12, 2025 00:14
EXPECT_FALSE(p7.get()->d.sign->contents->d.data);
}

TEST(PKCS7Test, PKCS7SignedAttributes) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could these PKCS7 test values also be added as seeds in our fuzz corpus?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point that we could consider doing. I believe we'll be redoing some of our PKCS7 ASN1 parsing soon to fix the indefinite ber issues we've been having.
We can add these two files along with any new test files that come up to the corpus in a PR once both are completed.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 17, 2025

Codecov Report

Attention: Patch coverage is 72.22222% with 20 lines in your changes missing coverage. Please review.

Project coverage is 79.03%. Comparing base (05d42aa) to head (b8ebc13).
Report is 18 commits behind head on main.

Files with missing lines Patch % Lines
crypto/pkcs7/pkcs7.c 62.26% 20 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2264      +/-   ##
==========================================
+ Coverage   79.01%   79.03%   +0.01%     
==========================================
  Files         612      614       +2     
  Lines      106589   106991     +402     
  Branches    15083    15155      +72     
==========================================
+ Hits        84225    84561     +336     
- Misses      21711    21775      +64     
- Partials      653      655       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@samuel40791765 samuel40791765 merged commit ea052e5 into aws:main Mar 25, 2025
104 of 108 checks passed
@samuel40791765 samuel40791765 deleted the pkcs7-sign branch March 25, 2025 20:58
@skmcgrail skmcgrail mentioned this pull request Mar 28, 2025
skmcgrail added a commit that referenced this pull request Mar 28, 2025
## What's Changed
* Revert "Allow constructed strings in BER parsing (#2015)" by
@samuel40791765 in #2278
* Add the rehash utility to the openssl CLI tool by @smittals2 in
#2258
* Documentation on service indicator by @justsmth in
#2281
* Update patches in Ruby CI by @samuel40791765 in
#2233
* Reject DSA trailing garbage in EVP layer, add test cases by @skmcgrail
in #2289
* Add support for verifying PKCS7 signed attributes by @samuel40791765
in #2264
* Add support for more SSL BIO functions by @samuel40791765 in
#2273
* Wire-up rust-openssl into GitHub CI (for the time being) by @skmcgrail
in #2291
* Adding detection of out-of-bound pre-bound memory read to AES-XTS
tests. by @nebeid in #2286
* AES: Add function pointer trampoline to avoid delocator issue by
@hanno-becker in #2294
* Bump mysql CI to 9.2.0 by @samuel40791765 in
#2161
* Cherrypick hardening DSA param checks from BoringSSL by @smittals2 in
#2293

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and the ISC license.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants