mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
allow creation of certs without CN
This commit is contained in:
parent
81b32cf426
commit
a188ae5ac5
@ -101,6 +101,7 @@ 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())
|
||||||
|
if commonname is not None:
|
||||||
cert.get_subject().CN = commonname
|
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:
|
||||||
@ -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""
|
||||||
|
@ -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:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user