diff options
author | Thomas Kriechbaumer <Kriechi@users.noreply.github.com> | 2016-02-08 09:52:29 +0100 |
---|---|---|
committer | Thomas Kriechbaumer <Kriechi@users.noreply.github.com> | 2016-02-08 09:52:29 +0100 |
commit | 4ee1ad88fc440164985c8efc50c0be133a0053bc (patch) | |
tree | 210635d4aa964873f8054c80fcbeb2e9f94ce6ab /netlib/certutils.py | |
parent | 4873547de3c65ba7c14cace4bca7b17368b2900d (diff) | |
parent | 655b521749efd5a600d342a1d95b67d32da280a8 (diff) | |
download | mitmproxy-4ee1ad88fc440164985c8efc50c0be133a0053bc.tar.gz mitmproxy-4ee1ad88fc440164985c8efc50c0be133a0053bc.tar.bz2 mitmproxy-4ee1ad88fc440164985c8efc50c0be133a0053bc.zip |
Merge pull request #120 from mitmproxy/model-cleanup
Model Cleanup
Diffstat (limited to 'netlib/certutils.py')
-rw-r--r-- | netlib/certutils.py | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/netlib/certutils.py b/netlib/certutils.py index a0111381..616a778e 100644 --- a/netlib/certutils.py +++ b/netlib/certutils.py @@ -12,7 +12,10 @@ from pyasn1.codec.der.decoder import decode from pyasn1.error import PyAsn1Error import OpenSSL +from .utils import Serializable + # Default expiry must not be too long: https://github.com/mitmproxy/mitmproxy/issues/815 + DEFAULT_EXP = 94608000 # = 24 * 60 * 60 * 365 * 3 # Generated with "openssl dhparam". It's too slow to generate this on startup. DEFAULT_DHPARAM = b""" @@ -361,7 +364,7 @@ class _GeneralNames(univ.SequenceOf): constraint.ValueSizeConstraint(1, 1024) -class SSLCert(object): +class SSLCert(Serializable): def __init__(self, cert): """ @@ -375,15 +378,25 @@ class SSLCert(object): def __ne__(self, other): return not self.__eq__(other) + def get_state(self): + return self.to_pem() + + def set_state(self, state): + self.x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, state) + + @classmethod + def from_state(cls, state): + cls.from_pem(state) + @classmethod - def from_pem(klass, txt): + def from_pem(cls, txt): x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, txt) - return klass(x509) + return cls(x509) @classmethod - def from_der(klass, der): + def from_der(cls, der): pem = ssl.DER_cert_to_PEM_cert(der) - return klass.from_pem(pem) + return cls.from_pem(pem) def to_pem(self): return OpenSSL.crypto.dump_certificate( |