-
Notifications
You must be signed in to change notification settings - Fork 76
add a method to collect the DNS names from a certificate #6
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
Changes from all commits
2848b7c
a6c27b9
d98a012
c2c3461
01e2796
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,11 @@ use crate::{ | |
| cert::{Cert, EndEntityOrCa}, | ||
| der, Error, | ||
| }; | ||
| #[cfg(feature = "alloc")] | ||
| use { | ||
| alloc::vec::Vec, | ||
| dns_name::{GeneralDnsNameRef, WildcardDnsNameRef}, | ||
| }; | ||
|
|
||
| pub fn verify_cert_dns_name( | ||
| cert: &crate::EndEntityCert, | ||
|
|
@@ -238,11 +243,11 @@ enum NameIteration { | |
| Stop(Result<(), Error>), | ||
| } | ||
|
|
||
| fn iterate_names( | ||
| subject: untrusted::Input, | ||
| subject_alt_name: Option<untrusted::Input>, | ||
| fn iterate_names<'names>( | ||
| subject: untrusted::Input<'names>, | ||
| subject_alt_name: Option<untrusted::Input<'names>>, | ||
| result_if_never_stopped_early: Result<(), Error>, | ||
| f: &dyn Fn(GeneralName) -> NameIteration, | ||
| f: &dyn Fn(GeneralName<'names>) -> NameIteration, | ||
| ) -> Result<(), Error> { | ||
| match subject_alt_name { | ||
| Some(subject_alt_name) => { | ||
|
|
@@ -272,6 +277,33 @@ fn iterate_names( | |
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "alloc")] | ||
| pub fn list_cert_dns_names<'names>( | ||
| cert: &'names crate::EndEntityCert<'names>, | ||
| ) -> Result<Vec<GeneralDnsNameRef<'names>>, Error> { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How hard would it be to rewire this to return an
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it certainly could be rewritten to return |
||
| let cert = &cert.inner(); | ||
| let names = core::cell::RefCell::new(Vec::new()); | ||
|
|
||
| iterate_names(cert.subject, cert.subject_alt_name, Ok(()), &|name| { | ||
| if let GeneralName::DnsName(presented_id) = name { | ||
| let dns_name = DnsNameRef::try_from_ascii(presented_id.as_slice_less_safe()) | ||
| .map(GeneralDnsNameRef::DnsName) | ||
| .or_else(|_| { | ||
| WildcardDnsNameRef::try_from_ascii(presented_id.as_slice_less_safe()) | ||
| .map(GeneralDnsNameRef::Wildcard) | ||
| }); | ||
|
|
||
| // if the name could be converted to a DNS name, add it; otherwise, | ||
| // keep going. | ||
| if let Ok(name) = dns_name { | ||
| names.borrow_mut().push(name) | ||
| } | ||
| } | ||
| NameIteration::KeepGoing | ||
| }) | ||
| .map(|_| names.into_inner()) | ||
| } | ||
|
|
||
| // It is *not* valid to derive `Eq`, `PartialEq, etc. for this type. In | ||
| // particular, for the types of `GeneralName`s that we don't understand, we | ||
| // don't even store the value. Also, the meaning of a `GeneralName` in a name | ||
|
|
||
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.
Drive-by: This comment doesn't match the derive below?