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

Permit trusted self-signed certificates #170

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ include = [

"tests/dns_name_tests.rs",
"tests/integration.rs",
"tests/misc/selfsigned.der",
"tests/misc/serial_neg.der",
"tests/misc/serial_zero.der",
"tests/netflix/ca.der",
Expand Down
16 changes: 14 additions & 2 deletions src/verify_cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ pub fn build_chain(
) -> Result<(), Error> {
let used_as_ca = used_as_ca(&cert.ee_or_ca);

check_issuer_independent_properties(
let must_be_self_signed = match check_issuer_independent_properties(
cert,
time,
used_as_ca,
sub_ca_count,
required_eku_if_present,
)?;
) {
Ok(()) => false,
Err(Error::CAUsedAsEndEntity) => true,
Err(e) => return Err(e),
};

// TODO: HPKP checks.

Expand Down Expand Up @@ -71,6 +75,10 @@ pub fn build_chain(

check_signatures(supported_sig_algs, cert, trust_anchor_spki)?;

if must_be_self_signed && trust_anchor_subject != cert.subject {
return Err(Error::CAUsedAsEndEntity);
}

Ok(())
}) {
Ok(()) => {
Expand All @@ -81,6 +89,10 @@ pub fn build_chain(
}
}

if must_be_self_signed {
return Err(Error::CAUsedAsEndEntity);
}

loop_while_non_fatal_error(intermediate_certs, |cert_der| {
let potential_issuer =
cert::parse_cert(untrusted::Input::from(*cert_der), EndEntityOrCA::CA(&cert))?;
Expand Down
17 changes: 17 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ fn read_root_with_neg_serial() {
.expect("idcat cert should parse as anchor");
}

#[test]
fn selfsigned() {
let cert = include_bytes!("misc/selfsigned.der");

let anchors = vec![webpki::trust_anchor_util::cert_der_as_trust_anchor(cert).unwrap()];
let anchors = webpki::TLSServerTrustAnchors(&anchors);

#[allow(clippy::unreadable_literal)] // TODO: Make this clear.
let time = webpki::Time::from_seconds_since_unix_epoch(1610233207);

let cert = webpki::EndEntityCert::from(cert).unwrap();
assert_eq!(
Ok(()),
cert.verify_is_valid_tls_server_cert(ALL_SIGALGS, &anchors, &[], time)
);
}

#[cfg(feature = "std")]
#[test]
fn time_constructor() {
Expand Down
Binary file added tests/misc/selfsigned.der
Binary file not shown.