diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-02-08 04:16:58 +0100 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-02-08 04:16:58 +0100 |
commit | fe0ed63c4a3486402f65638b476149ebba752055 (patch) | |
tree | 1739d349e75ccbb1cf2b8ef48aff885fe8711288 /netlib/certutils.py | |
parent | 4873547de3c65ba7c14cace4bca7b17368b2900d (diff) | |
download | mitmproxy-fe0ed63c4a3486402f65638b476149ebba752055.tar.gz mitmproxy-fe0ed63c4a3486402f65638b476149ebba752055.tar.bz2 mitmproxy-fe0ed63c4a3486402f65638b476149ebba752055.zip |
add Serializable ABC
Diffstat (limited to 'netlib/certutils.py')
-rw-r--r-- | netlib/certutils.py | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/netlib/certutils.py b/netlib/certutils.py index a0111381..ecdc0624 100644 --- a/netlib/certutils.py +++ b/netlib/certutils.py @@ -13,6 +13,8 @@ from pyasn1.error import PyAsn1Error import OpenSSL # Default expiry must not be too long: https://github.com/mitmproxy/mitmproxy/issues/815 +from netlib.utils import Serializable + 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 +363,7 @@ class _GeneralNames(univ.SequenceOf): constraint.ValueSizeConstraint(1, 1024) -class SSLCert(object): +class SSLCert(Serializable): def __init__(self, cert): """ @@ -375,15 +377,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( |