Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for PKCS12_set_mac #2128

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

samuel40791765
Copy link
Contributor

Issues:

Addresses CryptoAlg-2821

Description of changes:

Ruby has added a binding for an additional function called PKCS12_set_mac in it's master branch: ruby/ruby@c79b435 This was discovered prior to the PR for Ruby's CI integration with the master branch being merged: #2071

OpenSSL's implementation of the function directly sets a designated mac field within the PKCS12 structure. Our PKCS12 structure is folded into a string of bytes along with its length and there aren't any available fields for us to directly set. This means that AWS-LC's implementation of PKCS12_set_mac has to parse the proper contents from PKCS12 and rerun the key and mac generation with the new parameters provided.

Call-outs:

  1. The parsing logic is similar to PKCS12_get_key_and_certs, but the logic can't be shared. This is because we need to maintain pointers to certain parts of the CBS parsers in PKCS12_set_mac, so that we can properly rewrite the contents later.
  2. I've abstracted the key and mac generation in PKCS12_create and PKCS12_set_mac to a single function called pkcs12_gen_and_write_mac.
  3. OpenSSL 3.0 uses SHA-256 as the default hash, yet OpenSSL 1.1.1 uses SHA1. TODO: Make a decision

Testing:

New Tests

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.

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 83.33333% with 19 lines in your changes missing coverage. Please review.

Project coverage is 78.95%. Comparing base (4243a79) to head (dec648e).
Report is 30 commits behind head on main.

Files with missing lines Patch % Lines
crypto/pkcs8/pkcs8_x509.c 76.31% 18 Missing ⚠️
crypto/pkcs8/pkcs12_test.cc 97.36% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2128      +/-   ##
==========================================
+ Coverage   78.75%   78.95%   +0.19%     
==========================================
  Files         598      610      +12     
  Lines      103650   105364    +1714     
  Branches    14720    14913     +193     
==========================================
+ Hits        81633    83189    +1556     
- Misses      21365    21524     +159     
+ Partials      652      651       -1     

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

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.

2 participants