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

Nice getter for CRLDistributionPoints? #12234

Open
OlegAndrianov opened this issue Jan 4, 2025 · 11 comments
Open

Nice getter for CRLDistributionPoints? #12234

OlegAndrianov opened this issue Jan 4, 2025 · 11 comments
Labels
waiting-on-reporter Issue is waiting on a reply from the reporter. It will be automatically cloesd if there is no reply.

Comments

@OlegAndrianov
Copy link

Hi, it appears there is no good and easy way to extract a CDP list from a certificate object (or it is not very well documented).
Would love to have this added to the Certificate Object or at least to the CRLDistributionPoints extention object.
This way i will be able to get a list of URIs to work with -get the CRLs, check connections, etc.
(Same goes for OCSP)

@alex
Copy link
Member

alex commented Jan 4, 2025

Given a certificate, you can get the CRLDP extension with https://cryptography.io/en/latest/x509/reference/#cryptography.x509.Extensions.get_extension_for_class

Then you'll have a https://cryptography.io/en/latest/x509/reference/#cryptography.x509.CRLDistributionPoints and you can access whatever attributes you need.

@alex alex added the waiting-on-reporter Issue is waiting on a reply from the reporter. It will be automatically cloesd if there is no reply. label Jan 4, 2025
Copy link

github-actions bot commented Jan 8, 2025

This issue has been waiting for a reporter response for 3 days. It will be auto-closed if no activity occurs in the next 5 days.

@github-actions github-actions bot added the Stale label Jan 8, 2025
@OlegAndrianov
Copy link
Author

Alex, that is my issue, the object as far as i see can only return me oid field, that i do not need, and i need a list of distribution points. Can you advise how can i get them?

@reaperhulk
Copy link
Member

It is an iterable so you can iterate over it to get distribution points.

@OlegAndrianov
Copy link
Author

OlegAndrianov commented Jan 8, 2025

Are you sure?

   print (len(cdp))
           ^^^^^^^^
TypeError: object of type 'Extension' has no len()
    print (cdp[0])
               ^^^
TypeError: 'Extension' object is not subscriptable
    print (next(cdp))
           ^^^^^^^^^
TypeError: 'Extension' object is not an iterator
    print (list(cdp))
           ^^^^^^^^^
TypeError: 'Extension' object is not iterable

@alex
Copy link
Member

alex commented Jan 8, 2025 via email

@github-actions github-actions bot removed the Stale label Jan 9, 2025
@OlegAndrianov
Copy link
Author

Oh, that value attribute was not int he documentation, so that confused me,
Ok, so it appears to get a CRL URLs i need to do:

    for ext in cert.extensions:
        if ext.oid.dotted_string == "2.5.29.31":
            cdps = ext.value  # iterable of distribution points
            break
    if cdps:  # if exists cause certs might not have it at all.
        for dp in cdps:  # cdps is a list
            for name in dp.full_name:  # because it is also a list 
                crlnames.append(url)

So i am back to my original question:
can we have a nice getter to get a list of all URLs right from the extension object (even better for certificate object).
I guess we can not because it is not always URLs, right? it almost feels like a supporting function that will extract ONLY URLs, will be helpfull.

@alex
Copy link
Member

alex commented Jan 9, 2025

You can simplify this code a bit with cert.extensions.get_extension_for_class(x509.CRLDistributionPoints).

But yes, your intuition is basically right: there's no guarantee that a CRL DP will have any particular structure, which means writing utilities to handle one use case need lots of different behaviors (what should happen if not all elements are URLs? Exception? Silently ignore? Does it need to handle relative names? Filter for different reasons?)

For that reason, we generally prefer offering APIs with full generality, and then encourage users to write and publish their utilities that cover exactly their case cases.

@OlegAndrianov
Copy link
Author

OlegAndrianov commented Jan 9, 2025

Yeah, but i wish the .value thing was better documented. Autocomplete offers only .oid as possible method for extension.

@alex
Copy link
Member

alex commented Jan 9, 2025 via email

@OlegAndrianov
Copy link
Author

Yes, I would love to help, but I do not feel competent enough to do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-on-reporter Issue is waiting on a reply from the reporter. It will be automatically cloesd if there is no reply.
Development

No branches or pull requests

3 participants