diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-02-02 18:15:55 +0100 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-02-02 18:15:55 +0100 |
commit | a188ae5ac55c4f9564d7590c827be9a7eb9afba4 (patch) | |
tree | d4a34bb713c0beb769627836ff030ebab6c7513d | |
parent | 81b32cf42629dcbe8f59633dcb9b62816b781968 (diff) | |
download | mitmproxy-a188ae5ac55c4f9564d7590c827be9a7eb9afba4.tar.gz mitmproxy-a188ae5ac55c4f9564d7590c827be9a7eb9afba4.tar.bz2 mitmproxy-a188ae5ac55c4f9564d7590c827be9a7eb9afba4.zip |
allow creation of certs without CN
-rw-r--r-- | netlib/certutils.py | 5 | ||||
-rw-r--r-- | test/test_certutils.py | 20 |
2 files changed, 18 insertions, 7 deletions
diff --git a/netlib/certutils.py b/netlib/certutils.py index e6d71c39..a0111381 100644 --- a/netlib/certutils.py +++ b/netlib/certutils.py @@ -101,7 +101,8 @@ def dummy_cert(privkey, cacert, commonname, sans): cert.gmtime_adj_notBefore(-3600 * 48) cert.gmtime_adj_notAfter(DEFAULT_EXP) cert.set_issuer(cacert.get_subject()) - cert.get_subject().CN = commonname + if commonname is not None: + cert.get_subject().CN = commonname cert.set_serial_number(int(time.time() * 10000)) if ss: cert.set_version(2) @@ -294,6 +295,8 @@ class CertStore(object): @staticmethod def asterisk_forms(dn): + if dn is None: + return [] parts = dn.split(b".") parts.reverse() curr_dn = b"" diff --git a/test/test_certutils.py b/test/test_certutils.py index 991d59d6..027dcc93 100644 --- a/test/test_certutils.py +++ b/test/test_certutils.py @@ -41,8 +41,12 @@ class TestCertStore: ca2 = certutils.CertStore.from_store(d, "test") assert ca2.get_cert(b"foo", []) - assert ca.default_ca.get_serial_number( - ) == ca2.default_ca.get_serial_number() + assert ca.default_ca.get_serial_number() == ca2.default_ca.get_serial_number() + + def test_create_no_common_name(self): + with tutils.tmpdir() as d: + ca = certutils.CertStore.from_store(d, "test") + assert ca.get_cert(None, [])[0].cn is None def test_create_tmp(self): with tutils.tmpdir() as d: @@ -54,10 +58,6 @@ class TestCertStore: r = ca.get_cert(b"*.foo.com", []) assert r[1] == ca.default_privatekey - def test_add_cert(self): - with tutils.tmpdir() as d: - certutils.CertStore.from_store(d, "test") - def test_sans(self): with tutils.tmpdir() as d: ca = certutils.CertStore.from_store(d, "test") @@ -105,6 +105,14 @@ class TestDummyCert: ) assert r.cn == b"foo.com" + r = certutils.dummy_cert( + ca.default_privatekey, + ca.default_ca, + None, + [] + ) + assert r.cn is None + class TestSSLCert: |