-
Notifications
You must be signed in to change notification settings - Fork 52
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
Fix name constraints check #7
Changes from all commits
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 |
---|---|---|
|
@@ -63,10 +63,7 @@ pub fn check_name_constraints( | |
if !inner.peek(subtrees_tag.into()) { | ||
return Ok(None); | ||
} | ||
let subtrees = der::nested(inner, subtrees_tag, Error::BadDER, |tagged| { | ||
der::expect_tag_and_get_value(tagged, der::Tag::Sequence) | ||
})?; | ||
Ok(Some(subtrees)) | ||
der::expect_tag_and_get_value(inner, subtrees_tag).map(Some) | ||
} | ||
|
||
let permitted_subtrees = parse_subtrees(input, der::Tag::ContextSpecificConstructed0)?; | ||
|
@@ -160,6 +157,10 @@ fn check_presented_id_conforms_to_constraints_in_subtree( | |
dns_name::presented_id_matches_constraint(name, base).ok_or(Error::BadDER) | ||
} | ||
|
||
(GeneralName::DirectoryName(name), GeneralName::DnsName(base)) => { | ||
common_name(name).map(|cn| cn == base) | ||
} | ||
|
||
(GeneralName::DirectoryName(name), GeneralName::DirectoryName(base)) => Ok( | ||
presented_directory_name_matches_constraint(name, base, subtrees), | ||
), | ||
|
@@ -319,3 +320,18 @@ fn general_name<'a>(input: &mut untrusted::Reader<'a>) -> Result<GeneralName<'a> | |
}; | ||
Ok(name) | ||
} | ||
|
||
static COMMON_NAME: untrusted::Input = untrusted::Input::from(&[85, 4, 3]); | ||
|
||
fn common_name(input: untrusted::Input) -> Result<untrusted::Input, Error> { | ||
let inner = &mut untrusted::Reader::new(input); | ||
der::nested(inner, der::Tag::Set, Error::BadDER, |tagged| { | ||
der::nested(tagged, der::Tag::Sequence, Error::BadDER, |tagged| { | ||
let value = der::expect_tag_and_get_value(tagged, der::Tag::OID)?; | ||
if value != COMMON_NAME { | ||
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. This goes wrong if the first AttributeTypeAndValue in the Name has a different OID, and also if there is no commonName in the Subject. I have some test cases coming for this. |
||
return Err(Error::BadDER); | ||
} | ||
der::expect_tag_and_get_value(tagged, der::Tag::UTF8String) | ||
}) | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,7 @@ pub fn build_chain( | |
|
||
loop_while_non_fatal_error(intermediate_certs, |cert_der| { | ||
let potential_issuer = | ||
cert::parse_cert(untrusted::Input::from(*cert_der), EndEntityOrCa::Ca(cert))?; | ||
cert::parse_cert(untrusted::Input::from(cert_der), EndEntityOrCa::Ca(cert))?; | ||
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. FYI: triggered |
||
|
||
if potential_issuer.subject != cert.issuer { | ||
return Err(Error::UnknownIssuer); | ||
|
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.
isn't
base
here a constraint rather than a name? ie it should match if it is equal (as currently) but also match (say) if the name is "www.foo.com" and the constraint allows ".foo.com"?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 my conclusion on this is: it's an excellent start, and fixes web-platform-tests's use of name constraints to reduce the strength of their testing CA. but for me it's underlining a big testing debt here. i will look at that in the coming days; especially and also in the effort to land briansmith/webpki#131