diff options
author | Abcdefghijklmnopqrstuvwxyzxyz <huang_yue_zhi@outlook.com> | 2018-11-09 16:06:04 +0800 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2018-11-09 09:06:04 +0100 |
commit | d4f4cfe2252ac82bc361c098e7fba48d70466890 (patch) | |
tree | 79c840861d323ce4a8980bceb2b0a3ccec2d5406 /mitmproxy/certs.py | |
parent | 3f3ed4743a3dda8901a35aa14d8e1c689933a1a4 (diff) | |
download | mitmproxy-d4f4cfe2252ac82bc361c098e7fba48d70466890.tar.gz mitmproxy-d4f4cfe2252ac82bc361c098e7fba48d70466890.tar.bz2 mitmproxy-d4f4cfe2252ac82bc361c098e7fba48d70466890.zip |
Add Organization field for the generated certificate (#3376)
add organization field for the generated certificate
Diffstat (limited to 'mitmproxy/certs.py')
-rw-r--r-- | mitmproxy/certs.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/mitmproxy/certs.py b/mitmproxy/certs.py index 8b8ba6f2..6970618e 100644 --- a/mitmproxy/certs.py +++ b/mitmproxy/certs.py @@ -80,7 +80,7 @@ def create_ca(o, cn, exp): return key, cert -def dummy_cert(privkey, cacert, commonname, sans): +def dummy_cert(privkey, cacert, commonname, sans, o): """ Generates a dummy certificate. @@ -88,6 +88,7 @@ def dummy_cert(privkey, cacert, commonname, sans): cacert: CA certificate commonname: Common name for the generated certificate. sans: A list of Subject Alternate Names. + o: Organization name for the generated certificate. Returns cert if operation succeeded, None if not. """ @@ -107,6 +108,8 @@ def dummy_cert(privkey, cacert, commonname, sans): cert.set_issuer(cacert.get_subject()) if commonname is not None and len(commonname) < 64: cert.get_subject().CN = commonname + if o is not None: + cert.get_subject().O = o cert.set_serial_number(int(time.time() * 10000)) if ss: cert.set_version(2) @@ -305,7 +308,7 @@ class CertStore: ret.append(b"*." + b".".join(parts[i:])) return ret - def get_cert(self, commonname: typing.Optional[bytes], sans: typing.List[bytes]): + def get_cert(self, commonname: typing.Optional[bytes], sans: typing.List[bytes], o: typing.Optional[bytes] = None): """ Returns an (cert, privkey, cert_chain) tuple. @@ -313,6 +316,8 @@ class CertStore: valid, plain-ASCII, IDNA-encoded domain name. sans: A list of Subject Alternate Names. + + o: Organization name for the generated certificate. """ potential_keys: typing.List[TCertId] = [] @@ -335,7 +340,8 @@ class CertStore: self.default_privatekey, self.default_ca, commonname, - sans), + sans, + o), privatekey=self.default_privatekey, chain_file=self.default_chain_file) self.certs[(commonname, tuple(sans))] = entry @@ -448,6 +454,14 @@ class Cert(serializable.Serializable): return c @property + def o(self): + c = None + for i in self.subject: + if i[0] == b"O": + c = i[1] + return c + + @property def altnames(self): """ Returns: |