Skip to content

Commit 36adbe9

Browse files
committed
Remove EKU-related setters, getters and documentation from this PR.
1 parent eb4050b commit 36adbe9

File tree

5 files changed

+3
-128
lines changed

5 files changed

+3
-128
lines changed

docs/x509/verification.rst

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ the root of trust:
132132
.. class:: ClientVerifier
133133

134134
.. versionadded:: 43.0.0
135-
.. versionchanged:: 44.0.0
136-
Added :attr:`eku`.
137135

138136
A ClientVerifier verifies client certificates.
139137

@@ -161,18 +159,6 @@ the root of trust:
161159
:type: :class:`Store`
162160

163161
The verifier's trust store.
164-
165-
.. attribute:: eku
166-
167-
:type: :class:`~cryptography.x509.ObjectIdentifier` or None
168-
169-
The value of the Extended Key Usage extension required by this verifier
170-
If the verifier was built using :meth:`PolicyBuilder.build_client_verifier`,
171-
this will always be :attr:`~cryptography.x509.oid.ExtendedKeyUsageOID.CLIENT_AUTH`.
172-
173-
:note:
174-
See :meth:`CustomPolicyBuilder.eku` documentation for how verification is affected
175-
when changing the required EKU or using a custom extension policy.
176162

177163
.. method:: verify(leaf, intermediates)
178164

@@ -229,18 +215,6 @@ the root of trust:
229215

230216
The verifier's trust store.
231217

232-
.. attribute:: eku
233-
234-
:type: :class:`~cryptography.x509.ObjectIdentifier`
235-
236-
The value of the Extended Key Usage extension required by this verifier
237-
If the verifier was built using :meth:`PolicyBuilder.build_server_verifier`,
238-
this will always be :attr:`~cryptography.x509.oid.ExtendedKeyUsageOID.SERVER_AUTH`.
239-
240-
:note:
241-
See :meth:`CustomPolicyBuilder.eku` documentation for how verification is affected
242-
when changing the required EKU or using a custom extension policy.
243-
244218
.. method:: verify(leaf, intermediates)
245219

246220
Performs path validation on ``leaf``, returning a valid path
@@ -365,24 +339,6 @@ the root of trust:
365339

366340
:returns: A new instance of :class:`PolicyBuilder`
367341

368-
.. method:: eku(new_eku)
369-
370-
Sets the Extended Key Usage required by the verifier's policy.
371-
372-
If this method is not called, the EKU defaults to :attr:`~cryptography.x509.oid.ExtendedKeyUsageOID.SERVER_AUTH`
373-
if :meth:`build_server_verifier` is called, and :attr:`~cryptography.x509.oid.ExtendedKeyUsageOID.CLIENT_AUTH` if
374-
:meth:`build_client_verifier` is called.
375-
376-
When using the default extension policies, only certificates
377-
with the Extended Key Usage extension containing the specified value
378-
will be accepted. To accept more than one EKU or any EKU, use an extension policy
379-
with a custom validator. The EKU set via this method is accessible to custom extension validator
380-
callbacks via the `policy` argument.
381-
382-
:param ~cryptography.x509.ObjectIdentifier new_eku:
383-
384-
:returns: A new instance of :class:`PolicyBuilder`
385-
386342
.. method:: build_server_verifier(subject)
387343

388344
Builds a verifier for verifying server certificates.

src/cryptography/hazmat/bindings/_rust/x509.pyi

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ class CustomPolicyBuilder:
7373
def max_chain_depth(
7474
self, new_max_chain_depth: int
7575
) -> CustomPolicyBuilder: ...
76-
def eku(self, new_eku: x509.ObjectIdentifier) -> CustomPolicyBuilder: ...
7776
def build_client_verifier(self) -> ClientVerifier: ...
7877
def build_server_verifier(
7978
self, subject: x509.verification.Subject
@@ -92,8 +91,6 @@ class ClientVerifier:
9291
def store(self) -> Store: ...
9392
@property
9493
def max_chain_depth(self) -> int: ...
95-
@property
96-
def eku(self) -> x509.ObjectIdentifier: ...
9794
def verify(
9895
self,
9996
leaf: x509.Certificate,
@@ -109,8 +106,6 @@ class ServerVerifier:
109106
def store(self) -> Store: ...
110107
@property
111108
def max_chain_depth(self) -> int: ...
112-
@property
113-
def eku(self) -> x509.ObjectIdentifier: ...
114109
def verify(
115110
self,
116111
leaf: x509.Certificate,

src/rust/cryptography-x509/src/oid.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,6 @@ pub const EKU_ANY_KEY_USAGE_OID: asn1::ObjectIdentifier = asn1::oid!(2, 5, 29, 3
148148
pub const EKU_CERTIFICATE_TRANSPARENCY_OID: asn1::ObjectIdentifier =
149149
asn1::oid!(1, 3, 6, 1, 4, 1, 11129, 2, 4, 4);
150150

151-
pub const ALL_EKU_OIDS: [asn1::ObjectIdentifier; 8] = [
152-
EKU_SERVER_AUTH_OID,
153-
EKU_CLIENT_AUTH_OID,
154-
EKU_CODE_SIGNING_OID,
155-
EKU_EMAIL_PROTECTION_OID,
156-
EKU_TIME_STAMPING_OID,
157-
EKU_OCSP_SIGNING_OID,
158-
EKU_ANY_KEY_USAGE_OID,
159-
EKU_CERTIFICATE_TRANSPARENCY_OID,
160-
];
161-
162151
pub const PBES2_OID: asn1::ObjectIdentifier = asn1::oid!(1, 2, 840, 113549, 1, 5, 13);
163152
pub const PBKDF2_OID: asn1::ObjectIdentifier = asn1::oid!(1, 2, 840, 113549, 1, 5, 12);
164153

src/rust/src/x509/verify.rs

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
// for complete details.
44

55
use cryptography_x509::{
6-
certificate::Certificate,
7-
extensions::SubjectAlternativeName,
8-
oid::{ALL_EKU_OIDS, SUBJECT_ALTERNATIVE_NAME_OID},
6+
certificate::Certificate, extensions::SubjectAlternativeName, oid::SUBJECT_ALTERNATIVE_NAME_OID,
97
};
108
use cryptography_x509_verification::{
119
ops::{CryptoOps, VerificationCertificate},
@@ -15,15 +13,12 @@ use cryptography_x509_verification::{
1513
};
1614
use pyo3::types::{PyAnyMethods, PyListMethods};
1715

16+
use crate::backend::keys;
17+
use crate::error::{CryptographyError, CryptographyResult};
1818
use crate::types;
1919
use crate::x509::certificate::Certificate as PyCertificate;
2020
use crate::x509::common::{datetime_now, datetime_to_py, py_to_datetime};
2121
use crate::x509::sign;
22-
use crate::{
23-
asn1::oid_to_py_oid,
24-
error::{CryptographyError, CryptographyResult},
25-
};
26-
use crate::{asn1::py_oid_to_oid, backend::keys};
2722

2823
use super::parse_general_names;
2924

@@ -152,7 +147,6 @@ pub(crate) struct CustomPolicyBuilder {
152147
time: Option<asn1::DateTime>,
153148
store: Option<pyo3::Py<PyStore>>,
154149
max_chain_depth: Option<u8>,
155-
eku: Option<asn1::ObjectIdentifier>,
156150
ca_ext_policy: Option<ExtensionPolicy<PyCryptoOps>>,
157151
ee_ext_policy: Option<ExtensionPolicy<PyCryptoOps>>,
158152
}
@@ -165,7 +159,6 @@ impl CustomPolicyBuilder {
165159
time: self.time.clone(),
166160
store: self.store.as_ref().map(|s| s.clone_ref(py)),
167161
max_chain_depth: self.max_chain_depth,
168-
eku: self.eku.clone(),
169162
ca_ext_policy: self.ca_ext_policy.clone(),
170163
ee_ext_policy: self.ee_ext_policy.clone(),
171164
}
@@ -180,7 +173,6 @@ impl CustomPolicyBuilder {
180173
time: None,
181174
store: None,
182175
max_chain_depth: None,
183-
eku: None,
184176
ca_ext_policy: None,
185177
ee_ext_policy: None,
186178
}
@@ -225,29 +217,6 @@ impl CustomPolicyBuilder {
225217
})
226218
}
227219

228-
fn eku(
229-
&self,
230-
py: pyo3::Python<'_>,
231-
new_eku: pyo3::Bound<'_, pyo3::PyAny>,
232-
) -> CryptographyResult<CustomPolicyBuilder> {
233-
policy_builder_set_once_check!(self, eku, "EKU");
234-
235-
let oid = py_oid_to_oid(new_eku)?;
236-
237-
if !ALL_EKU_OIDS.contains(&oid) {
238-
return Err(CryptographyError::from(
239-
pyo3::exceptions::PyValueError::new_err(
240-
"Unknown EKU OID. Only EKUs from x509.ExtendedKeyUsageOID are supported.",
241-
),
242-
));
243-
}
244-
245-
Ok(CustomPolicyBuilder {
246-
eku: Some(oid),
247-
..self.py_clone(py)
248-
})
249-
}
250-
251220
fn build_client_verifier(&self, py: pyo3::Python<'_>) -> CryptographyResult<PyClientVerifier> {
252221
build_client_verifier_impl(py, &self.store, &self.time, |time| {
253222
// TODO: Replace with a custom policy once it's implemented in cryptography-x509-verification
@@ -399,12 +368,6 @@ impl PyClientVerifier {
399368
self.as_policy().max_chain_depth
400369
}
401370

402-
#[getter]
403-
fn eku(&self, py: pyo3::Python<'_>) -> pyo3::PyResult<pyo3::Py<pyo3::PyAny>> {
404-
let eku = &self.as_policy().extended_key_usage;
405-
return Ok(oid_to_py_oid(py, eku)?.as_unbound().clone_ref(py));
406-
}
407-
408371
fn verify(
409372
&self,
410373
py: pyo3::Python<'_>,
@@ -506,12 +469,6 @@ impl PyServerVerifier {
506469
self.as_policy().max_chain_depth
507470
}
508471

509-
#[getter]
510-
fn eku(&self, py: pyo3::Python<'_>) -> pyo3::PyResult<pyo3::Py<pyo3::PyAny>> {
511-
let eku = &self.as_policy().extended_key_usage;
512-
return Ok(oid_to_py_oid(py, eku)?.as_unbound().clone_ref(py));
513-
}
514-
515472
fn verify<'p>(
516473
&self,
517474
py: pyo3::Python<'p>,

tests/x509/verification/test_verification.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212

1313
from cryptography import x509
1414
from cryptography.x509.general_name import DNSName, IPAddress
15-
from cryptography.x509.oid import (
16-
AuthorityInformationAccessOID,
17-
ExtendedKeyUsageOID,
18-
)
1915
from cryptography.x509.verification import (
2016
CustomPolicyBuilder,
2117
PolicyBuilder,
@@ -108,7 +104,6 @@ def test_builder_pattern(self, builder_type: Type[AnyPolicyBuilder]):
108104
assert verifier.validation_time == now
109105
assert verifier.store == store
110106
assert verifier.max_chain_depth == max_chain_depth
111-
assert verifier.eku == ExtendedKeyUsageOID.SERVER_AUTH
112107

113108
def test_build_server_verifier_missing_store(
114109
self, builder_type: Type[AnyPolicyBuilder]
@@ -119,22 +114,6 @@ def test_build_server_verifier_missing_store(
119114
builder_type().build_server_verifier(DNSName("cryptography.io"))
120115

121116

122-
class TestCustomPolicyBuilder:
123-
def test_eku_already_set(self):
124-
with pytest.raises(ValueError):
125-
CustomPolicyBuilder().eku(ExtendedKeyUsageOID.IPSEC_IKE).eku(
126-
ExtendedKeyUsageOID.IPSEC_IKE
127-
)
128-
129-
def test_eku_bad_type(self):
130-
with pytest.raises(TypeError):
131-
CustomPolicyBuilder().eku("not an OID") # type: ignore[arg-type]
132-
133-
def test_eku_non_eku_oid(self):
134-
with pytest.raises(ValueError):
135-
CustomPolicyBuilder().eku(AuthorityInformationAccessOID.OCSP)
136-
137-
138117
class TestStore:
139118
def test_store_rejects_empty_list(self):
140119
with pytest.raises(ValueError):
@@ -180,7 +159,6 @@ def test_verify(self, builder_type: Type[AnyPolicyBuilder]):
180159
assert verifier.validation_time == validation_time.replace(tzinfo=None)
181160
assert verifier.max_chain_depth == 16
182161
assert verifier.store is store
183-
assert verifier.eku == ExtendedKeyUsageOID.CLIENT_AUTH
184162

185163
verified_client = verifier.verify(leaf, [])
186164
assert verified_client.chain == [leaf]

0 commit comments

Comments
 (0)