Read OCSP responder certificates inside the standard sequence wrapper

This commit is contained in:
Dylan M. Taylor committed 2026-11-18 11:59:29 -05:00
1 parent c51ed21b27
commit a026eb44bf
2 files changed
+23 -4

No files matched your search

+14 -3
View File
@@ -249,10 +249,21 @@ impl OcspResponse {
for t in it {
if t.tag == tag::ctx(0) {
for c in t.children()? {
if c.tag == tag::SEQUENCE
&& let Ok(cert) = Certificate::parse(c.raw)
{
if c.tag != tag::SEQUENCE {
continue;
}
// Preserve the historical direct-certificate form. RFC 6960 instead wraps
// certificates in one SEQUENCE OF inside [0]; unwrap only that one level.
if let Ok(cert) = Certificate::parse(c.raw) {
responder_cert.get_or_insert(cert);
} else if let Ok(certs) = c.children() {
for cert in certs {
if cert.tag == tag::SEQUENCE
&& let Ok(cert) = Certificate::parse(cert.raw)
{
responder_cert.get_or_insert(cert);
}
}
}
}
}
+9 -1
View File
@@ -498,9 +498,17 @@ fn a_responder_that_copies_the_issuers_name_does_not_answer_for_it() {
let single = der::seq(&[&cert_id, &revoked, &this.encode(), &der::tlv(tag::ctx(0), &next.encode())]);
let by_key = der::tlv(tag::ctx(2), &der::octets(&DigestAlg::Sha1.digest(&[&impostor.public_key.key_bits()])));
// RFC 6960's `[0] EXPLICIT SEQUENCE OF Certificate`, and the certificate directly in `[0]`.
for certs in [der::explicit(0, &der::seq(&[&impostor.raw])), der::explicit(0, &impostor.raw)] {
for certs in [
der::explicit(0, &der::seq(&[&impostor.raw])),
der::explicit(0, &impostor.raw),
// An unreadable entry must not hide the first readable certificate; later entries
// must not replace it. Parsing it still does not authorize the impostor.
der::explicit(0, &der::seq(&[&der::seq(&[]), &impostor.raw, &issuer.raw])),
] {
let forged = OcspResponse::parse(&signed_ocsp(&key, &by_key, Some(&certs), &single, this)).unwrap();
assert_eq!(forged.check(issuer, issuer, mid_june()), RevocationStatus::Unknown);
// Rejection must follow verification policy, not failure to read the embedded certificate.
assert_eq!(forged.into_parts().responder_cert.map(|cert| cert.raw), Some(impostor.raw.clone()));
}
}