-
Notifications
You must be signed in to change notification settings - Fork 166
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 a method to collect the DNS names from a certificate #65
Conversation
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.
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
@@ -61,6 +64,13 @@ impl<'a> From<DNSNameRef<'a>> for DNSName { | |||
} | |||
} | |||
|
|||
#[cfg(feature = "std")] | |||
impl std::string::ToString for DNSName { |
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.
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.
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.
I removed it
src/name.rs
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not let mut names = Vec::new()
? I don't think we should need RefCell
here.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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())
};
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.
done
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be called dns_names()
instead of list_dns_names()
.
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.
done
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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.
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.
added
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. |
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
<#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
ToString
implementation forDNSName
, since there's aInto<&str>
forDNSNameRef
.Unfortunately, I have not been able to make the function return a vector of
DNSNameRef
yet.For reference, the code I'm currently trying to build is:
But there's a conflict between the lifetime of
name
(created initerate_names
and passed to the closure) and the lifetime of theDNSNameRef
returned as result.