-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
fix: extension critical definition to default false #21230
fix: extension critical definition to default false #21230
Conversation
Signed-off-by: Jonathan M. Wilbur <jonathan@wilbur.space>
If the aim is to change the in-memory representation of the Although, to handle -1 correctly, you can just use the |
@davidben, i think the issue is that the field has a default, and it's not being set to that default. |
I don't think that's quite right. OpenSSL's openssl/crypto/asn1/tasn_enc.c Line 573 in 7f4cc3b
openssl/crypto/asn1/tasn_new.c Line 293 in 7f4cc3b
(When tasn_dec.c sees an omitted value, it uses the tasn_new.c default. The ASN1_BOOLEAN variants smuggle their defaults into it->size .)
If you're trying to represent a DEFAULT FALSE boolean, while Line 234 in 7f4cc3b
Line 200 in 7f4cc3b
Switching to After this PR, the two cases are not distinguished in memory. They're both represented as zero. So if you parse an extension with explicit FALSE and then re-encode it, it will be fixed to the correct omitted FALSE. Not unreasonable behavior, but it is a behavior change. Something to keep in mind. (Also keep in mind, when testing this, that |
It sounded like you were on to something @davidben , and I may still need to change those getters and setters, but as far as the encoding goes, it does not look like it ever encoded it incorrectly. Here is a decoding that I produced from a self-signed certificate:
You can see that only the For thoroughness here were my steps for reproduction, in case you can find something wrong I did here:
|
The ASN.1 code is a real nightmare to navigate, honestly, so I could not confirm this, but I would expect |
The getter definitely does not need to change to accommodate this: Lines 234 to 241 in 7f4cc3b
The setter might or might not. I just changed the Lines 200 to 206 in 7f4cc3b
(Out of fairness, maybe the code I used with that command bypasses the setter. I am not sure.) |
Dropping my approve until @davidben's comments are addressed.
Dismissing review based on @davidben's comments
Agreed that you can leave the getter alone, just the setter. Though ideally -1 will be impossible once you've fixed the setter, so it's moot whether you do anything with the getter. Regarding encoding, I believe this change will indeed encode things correctly. That's not what I was saying. I was saying the PR change the behavior of this code:
Before, the output was:
After, the output is:
To be clear, I don't personally think the behavior change is wrong, per se. OpenSSL already doesn't round-trip encodings in general (though it does cache TBSCertificate encodings), and the new encoding is correct for DER. (Though really the parser should just reject |
This PR is in a state where it requires action by @openssl/otc but the last update was 30 days ago |
This PR is in a state where it requires action by @openssl/otc but the last update was 61 days ago |
Is there something else I need to do to get this PR accepted? |
I don't think this PR is ready to merge. The setter still hasn't been updated as discussed above. While it works to leave it alone, it rather defeats the point of this CL because it means -1 is still a possible state for |
Yeah, along with it, the existing places which read the value directly could be updated to avoid the |
@tmshort @paulidale @davidben Have your concerns been addressed? |
@tmshort I believe this is awaiting your review. |
This PR is in a state where it requires action by @openssl/committers but the last update was 30 days ago |
This PR is in a state where it requires action by @openssl/committers but the last update was 61 days ago |
This PR is in a state where it requires action by @openssl/committers but the last update was 92 days ago |
This PR is in a state where it requires action by @openssl/committers but the last update was 123 days ago |
ping @openssl/committers for second review |
@@ -201,7 +203,7 @@ int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit) | |||
{ | |||
if (ex == NULL) | |||
return 0; | |||
ex->critical = (crit) ? 0xFF : -1; | |||
ex->critical = (crit) ? 0xFF : 0; |
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.
Is X509_EXTENSION
a private structure? If not, it seems that this is a change to the API semantics, in which case is it appropriate to backport to earlier branches?
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 is a private structure. It is declared in x509_local.h
.
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.
On the other hand this can be seen as refactoring as it should have no public API impact. So I would be OK applying this to the master branch only.
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.
LGTM, as only going to master
now
This pull request is ready to merge |
Squashed and merged to the master branch, finally! Thank you for your contribution. |
Signed-off-by: Jonathan M. Wilbur <jonathan@wilbur.space> Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from #21230)
Signed-off-by: Jonathan M. Wilbur <jonathan@wilbur.space> Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from openssl#21230)
If the
critical
field is missing from an X.509v3 extension (which it should be ifcritical
isFALSE
), the value ofcritical
in theX509_EXTENSION
struct will be-1
, which evaluates to truthy! I know there is a function for getting the criticality of this field properly, but I made the mistake of not using it. This PR could fix this problem for other developers.This PR simply makes a missing
critical
component set thecritical
field in theX509_EXTENSION
to0
instead of-1
.For reference, the definition of
Extension
from ITU Recommendation X.509 (2019) is: