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

Support for getting ASN.1 value for parsed extensions #5002

Closed
felixfontein opened this issue Sep 15, 2019 · 3 comments
Closed

Support for getting ASN.1 value for parsed extensions #5002

felixfontein opened this issue Sep 15, 2019 · 3 comments

Comments

@felixfontein
Copy link
Contributor

When parsing a certificate or CSR, it would be nice to be able to get the ASN.1 value for all extensions in a simple way without having to essentially re-create the certificate parsing code (i.e. iterating over the extensions by using obj._backend and obj._x509 and FFI).

This data is available when reading certificates or CSRs, it is currently only stored for UnrecognizedExtensions. So storing it, and adding a property (maybe called asn1_value), which is either None (if ASN.1 value is not available) or the ASN.1 value itself, should be no problem.

I'd like the use this as follows:

  1. For code which dumps all extensions in a uniform way (i.e. as OID, critical flag, ASN.1 encoding tuples);
  2. For code which deals with extensions currently not supported by cryptography, but potentially later.

Let me expand on 2): say I want to add a certain extension using cryptography right now. For that, I can add a UnrecognizedExtension with the correct content. But if I want to check whether this extension is already there with the correct content, I have to assume that it will come as a UnrecognizedExtension. If cryptography ever supports this extension type directly, my code for detecting whether the correct content is there will stop working.

Would adding this to cryptography be acceptable? (I can create a PR for this if wanted.)

@reaperhulk
Copy link
Member

I'm interested in how you would implement this. I'm not opposed to this conceptually, but I think our willingness to accept a patch would be predicated on whether we can build a sane API for this.

@felixfontein
Copy link
Contributor Author

I created a WIP for this (#5025). In it, every extension type gets a new property asn1value, which can be None or a bytes string. (I've not added this property to __eq__ and __ne__ since that would break a lot of things.)

@alex
Copy link
Member

alex commented Dec 2, 2020

@reaperhulk and I discussed this a bit. One of the things that's on our roadmap for 2021 is to move our X.509 extension parsing away from using OpenSSL, and towards our own DER parser (see #5357). We think that's going to have profound implications for the API here, so we're not making any hard decisions until that happens.

@reaperhulk reaperhulk added this to the Thirty Sixth Release milestone Nov 5, 2021
@alex alex closed this as completed Nov 12, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants