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

Bugfix: Remove assert from Certificate.from_p12 #274

Merged
merged 2 commits into from
Oct 19, 2022

Conversation

priitlatt
Copy link
Contributor

@priitlatt priitlatt commented Oct 19, 2022

PKCS#12 containers can be valid even if they do not contain any certificate entries in them. Furthermore, cryptography's built-in pkcs12.load_key_and_certificates, which is used by Certificate.from_p12, has a return type Optional[x509.Certificate] for the returned certificate.

The factory method however expected that the given PKCS#12 container always contains the certificate, which is a false assumption, and did a mere assert x509_certificate is not None. This can lead to unexpected results:

  • in production mode assertions are ignored altogether and a snowball effect could arise with issues deeper down the line,
  • unexpected AssertionError is thrown in case assertions are enabled.

To overcome this, check that the certificate acquired from the container is usable, and raise a descriptive ValueError otherwise.

@priitlatt priitlatt marked this pull request as ready for review October 19, 2022 10:11
@priitlatt priitlatt added the bug Something isn't working label Oct 19, 2022
@priitlatt priitlatt merged commit 4c2ed19 into master Oct 19, 2022
@priitlatt priitlatt deleted the bugfix/certificate-from-pkcs12 branch October 19, 2022 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants