-
Notifications
You must be signed in to change notification settings - Fork 1.7k
verification: add skeleton for revocation checking #14501
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
base: main
Are you sure you want to change the base?
Changes from all commits
a521276
280da61
533f582
98bd2db
dfe51b6
e5e4ba9
c9863a5
0b64bb5
9d1e5a9
c8fd39d
5342e5c
530c3fd
aed6887
33412e0
a9ff050
f2d21ef
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 |
|---|---|---|
|
|
@@ -4,17 +4,20 @@ | |
|
|
||
| from __future__ import annotations | ||
|
|
||
| import abc | ||
| import typing | ||
|
|
||
| from cryptography.hazmat.bindings._rust import x509 as rust_x509 | ||
| from cryptography.x509.general_name import DNSName, IPAddress | ||
|
|
||
| __all__ = [ | ||
| "CRLRevocationChecker", | ||
| "ClientVerifier", | ||
| "Criticality", | ||
| "ExtensionPolicy", | ||
| "Policy", | ||
| "PolicyBuilder", | ||
| "RevocationChecker", | ||
| "ServerVerifier", | ||
| "Store", | ||
| "Subject", | ||
|
|
@@ -32,3 +35,22 @@ | |
| ExtensionPolicy = rust_x509.ExtensionPolicy | ||
| Criticality = rust_x509.Criticality | ||
| VerificationError = rust_x509.VerificationError | ||
| CRLRevocationChecker = rust_x509.CRLRevocationChecker | ||
|
|
||
|
|
||
| class RevocationChecker(rust_x509.RevocationChecker, metaclass=abc.ABCMeta): | ||
| """ | ||
| An interface for revocation checkers. | ||
| """ | ||
|
Member
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. So right now the idea is that we won't actually have a Python API you can implement for revocation checking, it'll be handled internally and these are more markers, is that the idea?
Contributor
Author
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.
|
||
|
|
||
| @abc.abstractmethod | ||
| def is_revoked( | ||
| self, | ||
| leaf: rust_x509.Certificate, | ||
| issuer: rust_x509.Certificate, | ||
| policy: Policy, | ||
| ) -> bool | None: | ||
| """ | ||
| Returns whether the certificate is revoked. If the revocation status | ||
| cannot be determined, the revocation checker may return None. | ||
| """ | ||
|
Comment on lines
+46
to
+56
Contributor
Author
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 signature is a bit subtle. There are situations in which a revocation checker cannot determine the revocation status for a given certificate: for the CRL checker, the checker might not contain a relevant CRL; and for OCSP, the responder may be offline. I figure that it's best to signal this instead of collapsing that error state into "not revoked". |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // This file is dual licensed under the terms of the Apache License, Version | ||
| // 2.0, and the BSD License. See the LICENSE file in the root of this repository | ||
| // for complete details. | ||
|
|
||
| use cryptography_x509::crl::CertificateRevocationList; | ||
|
|
||
| use crate::{ | ||
| ops::{CryptoOps, VerificationCertificate}, | ||
| policy::Policy, | ||
| ValidationError, ValidationErrorKind, ValidationResult, | ||
| }; | ||
|
|
||
| pub trait CheckRevocation<B: CryptoOps> { | ||
| fn is_revoked<'chain>( | ||
| &self, | ||
| cert: &VerificationCertificate<'chain, B>, | ||
| issuer: &VerificationCertificate<'chain, B>, | ||
| policy: &Policy<'_, B>, | ||
| ) -> ValidationResult<'chain, bool, B>; | ||
| } | ||
|
|
||
| pub struct CrlRevocationChecker<'a> { | ||
| crls: Vec<&'a CertificateRevocationList<'a>>, | ||
| } | ||
|
|
||
| impl<'a, B: CryptoOps> CheckRevocation<B> for CrlRevocationChecker<'a> { | ||
| fn is_revoked<'chain>( | ||
| &self, | ||
| cert: &VerificationCertificate<'chain, B>, | ||
| issuer: &VerificationCertificate<'chain, B>, | ||
| policy: &Policy<'_, B>, | ||
| ) -> ValidationResult<'chain, bool, B> { | ||
| let _crls = &self.crls; | ||
| let _cert = cert; | ||
| let _issuer = issuer; | ||
| let _policy = policy; | ||
|
|
||
| Err(ValidationError::new(ValidationErrorKind::FatalError( | ||
| "unimplemented", | ||
| ))) | ||
| } | ||
| } | ||
|
|
||
| impl<'a> CrlRevocationChecker<'a> { | ||
| pub fn new(crls: impl IntoIterator<Item = &'a CertificateRevocationList<'a>>) -> Self { | ||
| Self { | ||
| crls: crls.into_iter().collect(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub type RevocationChecker<'a, B> = dyn CheckRevocation<B> + Send + Sync + 'a; |
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.
note that we now have an ABC that inherits from the Rust class that implements the
CheckRevocationtrait