-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
openssl_pkcs12: Add idempotency checks #54633
Conversation
a43b1fe
to
910f4bb
Compare
if (pkcs12_other_certificates is not None) and (self.ca_certificates is not None): | ||
expected_ca_certs = [crypto.dump_certificate(crypto.FILETYPE_PEM, | ||
ca_cert) for ca_cert in self.pkcs12.get_ca_certificates()] | ||
expected_ca_certs.append(crypto.dump_certificate(crypto.FILETYPE_PEM, self.pkcs12.get_certificate())) |
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.
Why do you include the current certificate in the set of CA certs?
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.
Same reason as above
elif bool(pkcs12_other_certificates) != bool(self.ca_certificates): | ||
return False | ||
|
||
if not pkcs12_other_certificates: |
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.
What is this if
for?
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.
It appears that if the pkcs12 file has additional certs, the get_friendlyname
method ( from parse
) returns None, making this fail unnecessarily. That said, I guess I could/should change this to be
not pkcs12_other_certificates and not pkcs12_friendly_name
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.
Hmm, that's even more strange. I'd say outright terrible :)
I've looked at the pyOpenSSL implementation of encoding and decoding PKCS12 files, it is essentially calling the OpenSSL functions from the other comment. The friendly name comes from the main cert extracted from the PKCS12 file, i.e. when the order is f**ked up, I would expect friendly_name
to also be wrong.
Also, you need a changelog fragment :) |
YES :D
|
Also decoupled the 'parse' and 'generate' function from the file write as they are now used in different places that do not need the file to be written to disk.
Also adds a new test for pkcs12 files with multiple certificates
ca_certificates is left as an alias to other_certificates; friendlyname depends on private key, so it will be ignored while checking for idempotency if the pkey is not set; idempotency check only checks for correct certs in the stack
b171709
to
c45f8d5
Compare
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.
shipit
(sorry for using wrong account...)
Thanks all! |
SUMMARY
Adds idempotency checks to the openssl_pkcs12 module and related tests.
Also decoupled
parse
andgenerate
from the file write, as they are now used for multiple stuff that don't require the file to be written to disk.Fixes #53221
ISSUE TYPE
COMPONENT NAME
openssl_pkcs12