Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/cryptography/hazmat/backends/openssl/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ def create_x509_csr(self, builder, private_key, algorithm):

# Set subject name.
res = self._lib.X509_REQ_set_subject_name(
x509_req, _encode_name(self, list(builder._subject_name))
x509_req, _encode_name(self, builder._subject_name)
)
assert res == 1

Expand Down
2 changes: 2 additions & 0 deletions src/cryptography/x509.py
Original file line number Diff line number Diff line change
Expand Up @@ -1486,4 +1486,6 @@ def sign(self, private_key, algorithm, backend):
"""
Signs the request using the requestor's private key.
"""
if self._subject_name is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this test isinstance to confirm subject name is an x509.Name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like the responsibility of the subject_name method

raise ValueError("A CertificateSigningRequest must have a subject")
return backend.create_x509_csr(self, private_key, algorithm)
12 changes: 11 additions & 1 deletion tests/test_x509.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,20 @@ class TestCertificateSigningRequestBuilder(object):
def test_sign_invalid_hash_algorithm(self, backend):
private_key = RSA_KEY_2048.private_key(backend)

builder = x509.CertificateSigningRequestBuilder()
builder = x509.CertificateSigningRequestBuilder().subject_name(
x509.Name([])
)
with pytest.raises(TypeError):
builder.sign(private_key, 'NotAHash', backend)

@pytest.mark.requires_backend_interface(interface=RSABackend)
def test_no_subject_name(self, backend):
private_key = RSA_KEY_2048.private_key(backend)

builder = x509.CertificateSigningRequestBuilder()
with pytest.raises(ValueError):
builder.sign(private_key, hashes.SHA256(), backend)

@pytest.mark.requires_backend_interface(interface=RSABackend)
def test_build_ca_request_with_rsa(self, backend):
private_key = RSA_KEY_2048.private_key(backend)
Expand Down