add a method to collect the DNS names from a certificate#65
add a method to collect the DNS names from a certificate#65Geal wants to merge 1 commit intobriansmith:masterfrom
Conversation
briansmith
left a comment
There was a problem hiding this comment.
Looks pretty good.
In addition to this test, we should also have the following test edge cases:
- There are no DNS names in the cert, but the subject common name looks like a DNS name ("CN=example.com"). This should return an empty result.
- There are multiple subjectAltNames, and the last one is an invalid DNS name in subjectAltNames. You can create one of these certificates by starting with a valid certificate and modifying it in a hex editor or similar, e.g. replace s/./:/ in "example.com".
src/name.rs
Outdated
| } | ||
|
|
||
| #[cfg(feature = "std")] | ||
| impl std::string::ToString for DNSName { |
There was a problem hiding this comment.
I think this might make sense as Into<String> but otherwise there's already another way of doing this, right? x.as_ref().into().into(); for x: DNSName. So I think we should avoid adding this.
In particular, one of my overall goals is to encourage people to use stronger types than String and str for values and so I try to minimize the convenience features for getting those types from stronger types.
| pub fn list_cert_dns_names<'names>(cert: &super::EndEntityCert<'names>) | ||
| -> Result<Vec<DNSName>, Error> { | ||
| let cert = &cert.inner; | ||
| let names = std::cell::RefCell::new(Vec::new()); |
There was a problem hiding this comment.
Why not let mut names = Vec::new()? I don't think we should need RefCell here.
There was a problem hiding this comment.
I thought so too, but I get the following error when I do it: error[E0387]: cannot borrow data mutably in a captured outer variable in an Fn closure
tests/integration.rs
Outdated
| let cert = webpki::EndEntityCert::from(ee_input) | ||
| .expect("should parse netflix end entity certificate correctly"); | ||
|
|
||
| let mut expected_names = std::collections::HashSet::new(); |
There was a problem hiding this comment.
NIT:
You can write this as:
let expected_names = {
const EXPECTED_NAMES: &'static [&'static str] = &[
"account.netflix.com",
....
"www.netflix.com",
];
HashSet::from_iter(EXPECTED_NAMES.iter())
};
src/webpki.rs
Outdated
| /// Requires the `std` default feature; i.e. this isn't available in | ||
| /// `#![no_std]` configurations. | ||
| #[cfg(feature = "std")] | ||
| pub fn list_dns_names(&self) -> Result<std::vec::Vec<DNSName>, Error> { |
There was a problem hiding this comment.
I think this should be called dns_names() instead of list_dns_names().
tests/integration.rs
Outdated
| let names: std::collections::HashSet<String> = dns_names.drain(..).map(|name| { | ||
| let n: webpki::DNSName = name.into(); | ||
| n.to_string() | ||
| }).collect(); |
There was a problem hiding this comment.
// Ensure that converting the list to a set doesn't throw away
// any duplicates that aren't supposed to be there
assert_eq!(actual_names.len(), expected_names.len());
let actual_names = HashSet::from_iter(actual_names.iter()
.map(|dns_name| dns_name.as_ref().into())) // Maybe `into::<&str>` for clarity.
I will look into it now. |
e7a03ad to
baa2fec
Compare
|
I'll add more integration tests as you suggested, then it should be good to go :) |
|
the new tests are there, and the build failures are apparently unrelated to this PR (*ring* compilation failures on appveyor, and the beta toolchain not installed for the 2 xcode builds in travis). |
|
hello, friendly ping on this :) |
|
The build failures seem a little off on this. For AppVeyor, I tried compiling his branch on 1.19.0 and got different errors. For travis-ci, the only build failure was on Which seems to be a failure of the build system, not the code, so it seems like this branch should be ready to merge/final review. |
|
@Geal I don't know why I didn't comment on this here, but please see #66. At a minimum, we should have a test that demonstrates what happens when there is only a wildcard |
|
The ideal state of wildcard support is hinted at in #66: Distinguish wildcard and non-wildcard entries with distinct enum variants of a new type. I would be willing to defer that ideal wildcard support to another PR but we at least need to decide to do when this function encounters a wildcard entry and we need the tests. It's probably less work to solve it all at once properly. WDYT? |
|
What should be expected when there are both wildcard and non wildcard? Can
the wildcard match the non wildcard ? For sozu I will use the wildcard
entries as well.
I can go over the code next week
…On Fri, Sep 28, 2018, 04:57 Brian Smith ***@***.***> wrote:
The ideal state of wildcard support is hinted at in #66
<https://github.com/briansmith/webpki/issues/66>: Distinguish wildcard
and non-wildcard entries with distinct enum variants of a new type. I would
be willing to defer that ideal wildcard support to another PR but we at
least need to decide to do when this function encounters a wildcard entry
and we need the tests. It's probably less work to solve it all at once
properly. WDYT?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#65 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAHSAHm5h_1E6EEg-QiayyTj6ULEFIuEks5ufZAWgaJpZM4ROtX1>
.
|
|
Thanks for contributing this! This seems to have been subsumed by #91 so I'm optimistically closing this in favor of that one. |
Fix #64
I am not too happy about it yet, I'd like to remove the
ToStringimplementation forDNSName, since there's aInto<&str>forDNSNameRef.Unfortunately, I have not been able to make the function return a vector of
DNSNameRefyet.For reference, the code I'm currently trying to build is:
But there's a conflict between the lifetime of
name(created initerate_namesand passed to the closure) and the lifetime of theDNSNameRefreturned as result.