diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2015-12-03 13:49:39 -0500 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2015-12-03 13:49:39 -0500 |
commit | 7b7f97a636d9b2081a33226380a9bad48a749fd4 (patch) | |
tree | f1ddf897368ddb3bbfe33cba645f5f060a639a00 /tests/test_x509.py | |
parent | 9ec0c8e33be79a27f2c38ad3da98a1315928ce39 (diff) | |
parent | 756d7d2efaee701b6979cd54a24ab1e892759d44 (diff) | |
download | cryptography-7b7f97a636d9b2081a33226380a9bad48a749fd4.tar.gz cryptography-7b7f97a636d9b2081a33226380a9bad48a749fd4.tar.bz2 cryptography-7b7f97a636d9b2081a33226380a9bad48a749fd4.zip |
Merge pull request #2504 from reaperhulk/encode-name-constraints
implement support for encoding name constraints
Diffstat (limited to 'tests/test_x509.py')
-rw-r--r-- | tests/test_x509.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/test_x509.py b/tests/test_x509.py index 9b5dda69..5a1c4c54 100644 --- a/tests/test_x509.py +++ b/tests/test_x509.py @@ -2030,6 +2030,41 @@ class TestCertificateBuilder(object): @pytest.mark.requires_backend_interface(interface=RSABackend) @pytest.mark.requires_backend_interface(interface=X509Backend) + def test_name_constraints(self, backend): + issuer_private_key = RSA_KEY_2048.private_key(backend) + subject_private_key = RSA_KEY_2048.private_key(backend) + + not_valid_before = datetime.datetime(2002, 1, 1, 12, 1) + not_valid_after = datetime.datetime(2030, 12, 31, 8, 30) + + excluded = [x509.DNSName(u"name.local")] + nc = x509.NameConstraints( + permitted_subtrees=None, excluded_subtrees=excluded + ) + + cert = x509.CertificateBuilder().subject_name( + x509.Name([x509.NameAttribute(NameOID.COUNTRY_NAME, u'US')]) + ).issuer_name( + x509.Name([x509.NameAttribute(NameOID.COUNTRY_NAME, u'US')]) + ).not_valid_before( + not_valid_before + ).not_valid_after( + not_valid_after + ).public_key( + subject_private_key.public_key() + ).serial_number( + 123 + ).add_extension( + nc, critical=False + ).sign(issuer_private_key, hashes.SHA256(), backend) + + ext = cert.extensions.get_extension_for_oid( + ExtensionOID.NAME_CONSTRAINTS + ) + assert ext.value == nc + + @pytest.mark.requires_backend_interface(interface=RSABackend) + @pytest.mark.requires_backend_interface(interface=X509Backend) def test_key_usage(self, backend): issuer_private_key = RSA_KEY_2048.private_key(backend) subject_private_key = RSA_KEY_2048.private_key(backend) |