-
Notifications
You must be signed in to change notification settings - Fork 120
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
Implement PKCS7_encrypt and PKC7_decrypt #1996
Implement PKCS7_encrypt and PKC7_decrypt #1996
Conversation
bb8b407
to
bd4e275
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1996 +/- ##
==========================================
+ Coverage 78.89% 78.91% +0.01%
==========================================
Files 595 594 -1
Lines 102451 102679 +228
Branches 14525 14578 +53
==========================================
+ Hits 80832 81032 +200
- Misses 20969 20996 +27
- Partials 650 651 +1 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
35e3b23
to
dab3473
Compare
86d8fc1
to
bdbaee1
Compare
0ad14ef
to
7dd3176
Compare
Interesting...
I suspect this is due to a different flavor of the same MMA defense edge case accounted for on L1812 of the test -- random occurrence of valid PKCS#7 ciphertext padding (note that this is about padding for symmetrically encrypted content, not the asymmetric key encryption attacked by MMA). Originally, we accounted for one byte of randomly valid padding (i.e. |
for (size_t i = 0; i < sk_X509_num(certs); i++) { | ||
x509 = sk_X509_value(certs, i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OpenSSL's documentation makes the following statement:
Only RSA keys are supported in PKCS#7 and envelopedData so the recipient certificates supplied to this function must all contain RSA public keys, though they do not have to be signed using the RSA algorithm.
Does that apply to our implementation as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Of all the EVP_PKEY_METHODS
s, RSA is the only one where encrypt/decrypt apply. KEMs are similar, but they have distinct encaps/decaps functions and don't define encrypt/decrypt.
crypto/pkcs7/pkcs7.c
Outdated
if (!pkcs7_decrypt_rinfo(&tmp_cek, ri, pkey)) { | ||
goto err; | ||
} | ||
// Set |cek| to the first successful decryption and keep going |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious, OpenSSL seems not to be doing that, isn't that a behavioral difference between the two libraries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, they use the last successfully decrypted key not the first. we should probably conform to OpenSSL's behavior.
but it looks like they might have a memory leak in that case. we'll avoid that.
ceb702c
to
f5d92c9
Compare
// BIO_get_cipher_status returns 1 if the cipher is in a healthy state or 0 | ||
// otherwise. Unhealthy state could indicate decryption failure or other | ||
// abnormalities. Data read from an unhealthy cipher should not be considered | ||
// authentic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit just in case we misuse this in the future, but we can include this in the next PR.
// BIO_get_cipher_status returns 1 if the cipher is in a healthy state or 0 | |
// otherwise. Unhealthy state could indicate decryption failure or other | |
// abnormalities. Data read from an unhealthy cipher should not be considered | |
// authentic. | |
// BIO_get_cipher_status returns 1 if the cipher is in a healthy state or 0 | |
// otherwise. A negative value could be returned if |b| is in an uninitialized | |
// state. Unhealthy state could indicate decryption failure or other | |
// abnormalities. Data read from an unhealthy cipher should not be considered | |
// authentic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks. will incorporate in next PR.
Issues:
Addresses CryptoAlg-2494
Description of changes:
This PR adds 2 new functions to encrypt/decrypt BIO contents into/out of "enveloped"-type PKCS7 objects.
Call-outs:
Like OpenSSL, this implementation of
PKCS7_decrypt
contains mitigations against the "Million Message Attack" (MMA) as prescribed in RFC 3218. A more detailed description is given in source comments.Testing:
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.