pkcs7: make PKCS7#add_recipient actually useful #923
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
pkcs7: refactor error handling in PKCS7#add_data
Raise an exception right after an OpenSSL function returns an error. Checking
ERR_peek_error()
is not reliable way to see if an error has occurred or not, as OpenSSL functions do not always populate the error queue.pkcs7: make PKCS7#add_recipient actually useful
Add a simple test case that creates an enveloped-data structure without using the shorthand method, and fix two issues preventing this from working correctly.
First,
OpenSSL::PKey::PKCS7#add_recipient
currently inserts an incompletePKCS7_RECIP_INFO
object into thePKCS7
object. When duplicating an unfinalizedPKCS7_RECIP_INFO
, the internalX509
reference must also be copied, as it is later used by#add_data
to fill the rest.A similar issue with
#add_signer
was fixed in commit 20ca7a2 (pkcs7: keep private key when duplicatingPKCS7_SIGNER_INFO
, 2021-03-24).Second,
#add_data
callsPKCS7_dataFinal()
, which for enveloped-data appears to require the BIO to be flushed explicitly withBIO_flush()
. Without this, the last block of the encrypted data would be missing.