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: ensure X509 extensions are hashed & cached, before deciding a cert is CA or EE #88

Merged
merged 1 commit into from
Jan 29, 2023

Conversation

job
Copy link
Contributor

@job job commented Jan 21, 2023

If X509_check_ca() fails to cache X509v3 extension values, the return value may be incorrect, leading to erroneously assuming a given certificate is a CA or EE cert (while in reality it is the other, or neither).

This failure mode can arise because X509_check_ca() doesn't verify whether libcrypto's (void)x509v3_cache_extensions(x) flipped the EXFLAG_INVALID flag in x->ex_flags. Unfortunately, X509_check_ca() doesn't have a return code to indicate an error, so this can't be fixed in libcrypto - the API is broken.

The workaround is to call X509_check_purpose() with a purpose argument of -1, before calling X509_check_ca(), this ensures the X509v3 extensions are cached. Since X509_check_purpose() does have a return code to indicate errors, we can use that to supplement X509_check_ca()'s shortcomings.

OpenBSD's rpki-client also uses the above approach.

Compare https://github.com/openssl/openssl/blob/2bcf8e69bd92e33d84c48e7d108d3d46b22f8a6d/crypto/x509v3/v3_purp.c#L84-L86 to https://github.com/openssl/openssl/blob/2bcf8e69bd92e33d84c48e7d108d3d46b22f8a6d/crypto/x509v3/v3_purp.c#L619-L620 the latter is lacking error checking.

… CA or EE

If X509_check_ca() fails to cache X509v3 extension values, the return
value may be incorrect, leading to erroneously assuming a given certificate
is a CA or EE cert (while in reality it is the other, or neither).

This failure mode can arise because X509_check_ca() doesn't verify
whether libcrypto's (void)x509v3_cache_extensions(x) flipped the EXFLAG_INVALID
flag in x->ex_flags. Unfortunately, X509_check_ca() doesn't have a return code
to indicate an error, so this can't be fixed in libcrypto - the API is broken.

The workaround is to call X509_check_purpose(3) with a purpose argument of -1,
before calling X509_check_ca(), this ensures the X509v3 extensions are cached.
Since X509_check_purpose() does have a return code to indicate errors, we can
use that to supplement X509_check_ca()'s shortcomings.

OpenBSD's rpki-client also uses the above approach.
@job job changed the title Ensure X509 extensions are hashed & cached, before deciding a cert is CA or EE bugfix: ensure X509 extensions are hashed & cached, before deciding a cert is CA or EE Jan 27, 2023
@ydahhrk ydahhrk merged commit 178cbd7 into NICMx:main Jan 29, 2023
@ydahhrk
Copy link
Member

ydahhrk commented Jan 29, 2023

Thank you!

@ydahhrk ydahhrk temporarily deployed to github-pages January 29, 2023 00:12 — with GitHub Pages Inactive
@job job deleted the main branch January 29, 2023 07:58
@ydahhrk ydahhrk added this to the 1.5.4 milestone Feb 7, 2023
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