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

Add top-level ServerVerifier.verify API #9805

Merged
merged 5 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions src/cryptography/hazmat/bindings/_rust/x509.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class ServerVerifier:
def subject(self) -> x509.verification.Subject: ...
@property
def validation_time(self) -> datetime.datetime: ...
def verify(
self,
leaf: x509.Certificate,
intermediates: list[x509.Certificate],
store: Store,
woodruffw marked this conversation as resolved.
Show resolved Hide resolved
) -> list[x509.Certificate]: ...

class Store:
def __init__(self, certs: list[x509.Certificate]) -> None: ...
10 changes: 10 additions & 0 deletions src/rust/src/x509/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ impl PyServerVerifier {
fn validation_time<'p>(&self, py: pyo3::Python<'p>) -> pyo3::PyResult<&'p pyo3::PyAny> {
datetime_to_py(py, &self.as_policy().validation_time)
}

fn verify<'p>(
&self,
_py: pyo3::Python<'p>,
_leaf: &PyCertificate,
_intermediates: &'p pyo3::types::PyList,
_store: &'p PyStore,
) -> CryptographyResult<Vec<PyCertificate>> {
Err(pyo3::exceptions::PyNotImplementedError::new_err("unimplemented").into())
}
}

fn build_subject_owner(
Expand Down
21 changes: 15 additions & 6 deletions tests/x509/test_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,13 @@ def test_subject_bad_types(self):
"cryptography.io" # type: ignore[arg-type]
)
with pytest.raises(TypeError):
PolicyBuilder().build_server_verifier(
"0.0.0.0" # type: ignore[arg-type]
)
PolicyBuilder().build_server_verifier("0.0.0.0") # type: ignore[arg-type]
with pytest.raises(TypeError):
PolicyBuilder().build_server_verifier(
IPv4Address("0.0.0.0") # type: ignore[arg-type]
)
with pytest.raises(TypeError):
PolicyBuilder().build_server_verifier(
None # type: ignore[arg-type]
)
PolicyBuilder().build_server_verifier(None) # type: ignore[arg-type]

def test_builder_pattern(self):
now = datetime.datetime.now().replace(microsecond=0)
Expand Down Expand Up @@ -78,3 +74,16 @@ def test_store_initializes(self):
x509.load_pem_x509_certificate,
)
assert Store([cert]) is not None


class TestServerVerifier:
def test_not_implemented(self):
verifier = PolicyBuilder().build_server_verifier(
DNSName("cryptography.io")
)
cert = _load_cert(
os.path.join("x509", "cryptography.io.pem"),
x509.load_pem_x509_certificate,
)
with pytest.raises(NotImplementedError):
verifier.verify(cert, [], Store([cert]))
Loading