Skip to content

Commit 416fe7b

Browse files
labbottflihp
authored andcommitted
Give a better error message for an unexpected self-signed cert
Currently, attempting to verify a self-signed cert chain with a root gives a cryptic error message about mismatched key types. Add another check to give a better error message for this case.
1 parent dd38352 commit 416fe7b

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

verifier/src/lib.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,8 @@ pub enum PkiPathSignatureVerifierError {
298298
NoMatchingRoot,
299299
#[error("Signature verification failed: {0}")]
300300
VerifierFailed(#[from] CertVerifierError),
301+
#[error("The chain is unexpectedly self-signed")]
302+
UnexpectedSelfSigned,
301303
}
302304

303305
/// This struct encapsulates the signature verification process for a PkiPath.
@@ -352,11 +354,21 @@ impl<'a> PkiPathSignatureVerifier<'a> {
352354
Err(CertVerifierError::Signature(_)) => continue,
353355
// if there's any other error return it
354356
Err(e) => {
355-
return Err(
357+
// did we forget this was self-signed?
358+
let verifier =
359+
CertSigVerifierFactory::get_verifier(
360+
&pki_path[0],
361+
)?;
362+
363+
if verifier.verify(&pki_path[0]).is_ok() {
364+
return Err(PkiPathSignatureVerifierError::UnexpectedSelfSigned);
365+
} else {
366+
return Err(
356367
PkiPathSignatureVerifierError::VerifierFailed(
357368
e,
358369
),
359-
)
370+
);
371+
}
360372
}
361373
}
362374
}

0 commit comments

Comments
 (0)