diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-07-05 14:07:16 -0500 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-07-05 14:07:16 -0500 |
commit | 5b57cbfbd735604a9589cb0cf8950ec858b94f7d (patch) | |
tree | 38cbe39b8a3f73812ac00971d1a9333d34b66a8b /tests | |
parent | 026530a1f54a3180b56cc5d330283ea182db1249 (diff) | |
parent | cc781e31f37d53c7d8ba0654db4e47e04c88f662 (diff) | |
download | cryptography-5b57cbfbd735604a9589cb0cf8950ec858b94f7d.tar.gz cryptography-5b57cbfbd735604a9589cb0cf8950ec858b94f7d.tar.bz2 cryptography-5b57cbfbd735604a9589cb0cf8950ec858b94f7d.zip |
Merge pull request #2085 from alex/encode-san
Initial code to encode SANs
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_x509.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/test_x509.py b/tests/test_x509.py index 1e0c9cdc..78552978 100644 --- a/tests/test_x509.py +++ b/tests/test_x509.py @@ -911,6 +911,49 @@ class TestCertificateSigningRequestBuilder(object): ]) ) + def test_subject_alt_names(self, backend): + private_key = RSA_KEY_2048.private_key(backend) + + csr = x509.CertificateSigningRequestBuilder().subject_name( + x509.Name([ + x509.NameAttribute(x509.OID_COMMON_NAME, u"SAN"), + ]) + ).add_extension( + x509.SubjectAlternativeName([ + x509.DNSName(u"example.com"), + x509.DNSName(u"*.example.com"), + ]), + critical=False, + ).sign(private_key, hashes.SHA256(), backend) + + assert len(csr.extensions) == 1 + ext = csr.extensions.get_extension_for_oid( + x509.OID_SUBJECT_ALTERNATIVE_NAME + ) + assert not ext.critical + assert ext.oid == x509.OID_SUBJECT_ALTERNATIVE_NAME + assert list(ext.value) == [ + x509.DNSName(u"example.com"), + x509.DNSName(u"*.example.com"), + ] + + def test_subject_alt_name_unsupported_general_name(self, backend): + private_key = RSA_KEY_2048.private_key(backend) + + builder = x509.CertificateSigningRequestBuilder().subject_name( + x509.Name([ + x509.NameAttribute(x509.OID_COMMON_NAME, u"SAN"), + ]) + ).add_extension( + x509.SubjectAlternativeName([ + x509.RFC822Name(u"test@example.com"), + ]), + critical=False, + ) + + with pytest.raises(NotImplementedError): + builder.sign(private_key, hashes.SHA256(), backend) + @pytest.mark.requires_backend_interface(interface=DSABackend) @pytest.mark.requires_backend_interface(interface=X509Backend) |