allow creation of certs without CN

This commit is contained in:
Maximilian Hils 2016-02-02 18:15:55 +01:00
parent 81b32cf426
commit a188ae5ac5
2 changed files with 18 additions and 7 deletions

View File

@ -101,7 +101,8 @@ def dummy_cert(privkey, cacert, commonname, sans):
cert.gmtime_adj_notBefore(-3600 * 48) cert.gmtime_adj_notBefore(-3600 * 48)
cert.gmtime_adj_notAfter(DEFAULT_EXP) cert.gmtime_adj_notAfter(DEFAULT_EXP)
cert.set_issuer(cacert.get_subject()) 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)) cert.set_serial_number(int(time.time() * 10000))
if ss: if ss:
cert.set_version(2) cert.set_version(2)
@ -294,6 +295,8 @@ class CertStore(object):
@staticmethod @staticmethod
def asterisk_forms(dn): def asterisk_forms(dn):
if dn is None:
return []
parts = dn.split(b".") parts = dn.split(b".")
parts.reverse() parts.reverse()
curr_dn = b"" curr_dn = b""

View File

@ -41,8 +41,12 @@ class TestCertStore:
ca2 = certutils.CertStore.from_store(d, "test") ca2 = certutils.CertStore.from_store(d, "test")
assert ca2.get_cert(b"foo", []) assert ca2.get_cert(b"foo", [])
assert ca.default_ca.get_serial_number( assert ca.default_ca.get_serial_number() == ca2.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): def test_create_tmp(self):
with tutils.tmpdir() as d: with tutils.tmpdir() as d:
@ -54,10 +58,6 @@ class TestCertStore:
r = ca.get_cert(b"*.foo.com", []) r = ca.get_cert(b"*.foo.com", [])
assert r[1] == ca.default_privatekey 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): def test_sans(self):
with tutils.tmpdir() as d: with tutils.tmpdir() as d:
ca = certutils.CertStore.from_store(d, "test") ca = certutils.CertStore.from_store(d, "test")
@ -105,6 +105,14 @@ class TestDummyCert:
) )
assert r.cn == b"foo.com" assert r.cn == b"foo.com"
r = certutils.dummy_cert(
ca.default_privatekey,
ca.default_ca,
None,
[]
)
assert r.cn is None
class TestSSLCert: class TestSSLCert: