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

Add method to get all the names from a certificate #64

Open
Geal opened this issue Dec 27, 2017 · 10 comments
Open

Add method to get all the names from a certificate #64

Geal opened this issue Dec 27, 2017 · 10 comments

Comments

@Geal
Copy link

Geal commented Dec 27, 2017

Hi,
To integrate rustls in sozu, I'd need a way to get the common name and subject alternative names from a certificate, and apparently I should implement it on EndEntityCert. I opened a related issue in rustls.
If you're ok with this feature, I could work on a PR tomorrow.

@briansmith
Copy link
Owner

I'd need a way to get the common name and subject alternative names from a certificate, and apparently I should implement it on EndEntityCert

My understanding is that you need a way to extract all the domain names from the certificate, not all the names, is that right?

webpki doesn't use the subject common name for anything and in particular it doesn't try to validate it as a DNS name. I don't think it makes sense to add an API for extracting the common name considering this; imagine if the common name was something like "example.com"; if sozu exposed that to the application then the application might think the certificate is valid for "example.com" when it, in fact, isn't.

In any case, I've actually implemented this feature already in my private tree, for dNSName subjectAltNames. I expect to post it publicly here in January.

@Geal
Copy link
Author

Geal commented Dec 28, 2017 via email

@briansmith
Copy link
Owner

@Geal It seems I already implemented this: https://docs.rs/webpki/0.18.0-alpha/webpki/struct.EndEntityCert.html#method.verify_is_valid_for_at_least_one_dns_name.

I guess your use case is similar to the one I implemented that feature for: You have a server that accepts connections from clients that authenticate with a client certificate. The configuration for the server provides a way to set which clients, named by DNS name, connections are to be accepted from. You want to know which of the given names the certificate was actually valid for, so that you can construct an HTTP header that contains those names.

Note that this is slightly different than what you asked for because it doesn't return all the names for which the certificate is valid; it only returns the subset of the input names for which the certificate is valid.

@Geal
Copy link
Author

Geal commented Dec 28, 2017 via email

@briansmith
Copy link
Owner

I have a trie-like structure in which I put in advance all the names of a
certificate to look up the correct one, then do the real name check with
that certificate.

In that case, you'd need a separate feature. I think such a feature would be useful but I can't prioritize implementing it myself right now. If you submit a PR I'll review it. Check out the implementation of verify_cert_dns_name(), specifically the way it uses iterate_names().

I think the most tricky part of the PR will be documenting the new feature. In particular, it's important that we document that the feature is not designed to be used as part of certificate validation.

@Geal
Copy link
Author

Geal commented Dec 28, 2017

alright, here's the PR. While writing it, I started to think about the API. I see a very explicit intent to prevent misuse. As you said, this new method must not be used to replace proper name validation.

But on the other hand, I think there's a need for some functions to get information from certificates, getting the names, the certificate authority that issued it, the validity period, etc.

Do you think those features could live in webpki, or would they belong to another crate?

@briansmith
Copy link
Owner

I started to think about the API. I see a very explicit intent to prevent misuse. As you said, this new method must not be used to replace proper name validation.

But on the other hand, I think there's a need for some functions to get information from certificates, getting the names, the certificate authority that issued it, the validity period, etc.

Do you think those features could live in webpki, or would they belong to another crate?

I think they belong in webpki. I think the needs of clients and servers are really pretty aligned when things are done the best way so I don't think it's good to separate these functions.

I filed #67 for exposing the validity period for a cert (chain), #68 for exposing the constructed certificate chain, #70 for providing some tools for constructing an "optimum" certificate chain, and #71 for creating an entire indexing system similar to what you've already done. In particular if you'd like to collaborate on the indexing system then we could work together to implement all these things in webpki.

@akuanti
Copy link

akuanti commented Jul 5, 2018

In any case, I've actually implemented this feature already in my private tree, for dNSName subjectAltNames. I expect to post it publicly here in January.

@briansmith do you have an ETA on this?

@Geal
Copy link
Author

Geal commented Jul 13, 2018

I'm planning to finish the work on this in the next 2 weeks, as I'm polishing sozu's rustls integration

@seguidor777
Copy link

Hi all!
Is there any method in wepki to extract the common name from the cert?

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 a pull request may close this issue.

4 participants