Skip to content

Commit 8209d63

Browse files
authored
fixes #11944 -- don't panic on attributes with no values (#11947)
1 parent 2eab3f3 commit 8209d63

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

docs/development/test-vectors.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,8 @@ Custom X.509 Request Vectors
612612
invalid.
613613
* ``long-form-attribute.pem`` - A certificate signing request containing an
614614
attribute whose value's tag is encoded in the long form.
615+
* ``zero-element-attribute.pem`` - A certificate signing request containing an
616+
attribute whose value has zero elements.
615617

616618
Custom X.509 Certificate Revocation List Vectors
617619
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl CertificationRequestInfo<'_> {
4444
pub fn check_attribute_length<'a>(
4545
values: asn1::SetOf<'a, asn1::Tlv<'a>>,
4646
) -> Result<(), asn1::ParseError> {
47-
if values.count() > 1 {
47+
if values.count() != 1 {
4848
// TODO: We should raise a more specific error here
4949
// Only single-valued attributes are supported
5050
Err(asn1::ParseError::new(asn1::ParseErrorKind::InvalidValue))

tests/x509/test_x509.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6825,6 +6825,14 @@ def test_no_attributes(self, backend):
68256825
)
68266826
assert len(request.attributes) == 0
68276827

6828+
def test_zero_element_attribute(self):
6829+
request = _load_cert(
6830+
os.path.join("x509", "requests", "zero-element-attribute.pem"),
6831+
x509.load_pem_x509_csr,
6832+
)
6833+
with pytest.raises(ValueError, match="Only single-valued"):
6834+
request.attributes
6835+
68286836

68296837
def test_load_pem_x509_certificates():
68306838
with pytest.raises(ValueError):
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-----BEGIN CERTIFICATE REQUEST-----
2+
MIICgDCCAWgCAQAwLDEQMA4GCSqGSIb3DQEJARYBLzEYMBYGA1UEAwwPbWl0ZWwu
3+
YmxvbmF5LmNoMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA765FwcoI
4+
JtKM566SSLXtz85h1ejx3G+efgG2OSiFIcZzPHQnuUPJ5ONL16VedcWi+8OB2Rbx
5+
KWLf8DH3YK9CAxYeMX/eAay4MCbl9AROiDVhyhHL1DU3pUH4MkVKdwPhZiW1b7gM
6+
W0DcY6iAuhLsftz5J/uyjGztfNRciErBZeNCh34fZcls4Iddkh0A6mz7KT4PmfNt
7+
Ywo6+5sG4G0TZPlmXM803soWqfWCX/8FnzXd9ch1oApLE9zfxOlvWM7YBwyGCzZd
8+
92PfX6D6sbMNmQxoZzT4LXeM4wZ11Jv9PHaGIDV/ub/1/7W0hYWnTHvvJRm9Tiyv
9+
5JCH9/VpGhjIGQIDAQABoA8wDQYJKoZIhvcNAQkOMQAwDQYJKoZIhvcNAQELBQAD
10+
ggEBAA9i4mqUrcakDp4YmjwQXaYQhSzxQZjk8xveHLRcyx4Cg8FAE5iUW8s1S+1f
11+
pODlPrsdmZzRq3o+ZEkZNTM63kaXjDQEzlihlQ2yAScKAV22934pLyrMLn3mo5lO
12+
oYgfSCHgYQE3YpNe8a2UFgWU5dhDbucCqbUO/AnBNTcBHpGHyvijbOBJn1cheLjZ
13+
I7jbylyJBjyRgDiG3QNsgc/Iw58ys3DNCTsG0ghAwOh1g1u0LnZJKll1IWuK/HHI
14+
D8d1ZsJic8ok8BkC/qGsrgQmoJpOP1Fu087svKcUbFT9T8UXzPigL1wEaxRPwkI8
15+
ECT4bDqrtBADIblEpqq4rNp4QoA=
16+
-----END CERTIFICATE REQUEST-----

0 commit comments

Comments
 (0)