Closed jlaine closed 10 months ago
@rthalley I'm not entirely comfortable with this code, because extract_patterns
could also raise an Exception.
I think I'd be more comfortable with exactly two errors paths:
CertificateError
=> use str(exc)
VerificationError
=> f"Certificate subjectAltName does not match {hostname}."
All modified and coverable lines are covered by tests :white_check_mark:
Comparison is base (
20cd4ee
) 100.00% compared to head (9dd2b96
) 100.00%.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
You could also go for "belt and braces" and just fall back to the first exception if extract_patterns
raises, e.g.
try:
patterns = service_identity.cryptography.extract_patterns(certificate)
except Exception:
patterns = []
if len(patterns) == 0:
errmsg = str(exc)
I'm going to merge as-is after thinking about it, we can always revisit this.
When a certificate contains no subjectAltName extension,
service-identity
now raises aCertificateError
instead of aVerificationError
.