diff --git a/tlslite/utils/openssl_rsakey.py b/tlslite/utils/openssl_rsakey.py index 1f24c31c1..3131b372d 100644 --- a/tlslite/utils/openssl_rsakey.py +++ b/tlslite/utils/openssl_rsakey.py @@ -43,6 +43,22 @@ def __init__(self, n=0, e=0, key_type="rsa"): m2.rsa_set_e(self.rsa, numberToMPI(e)) self.key_type = key_type + def __getstate__(self): + if not self.rsa: + return (self.key_type, ) + return (self.key_type, + mpiToNumber(m2.rsa_get_e(self.rsa)), + mpiToNumber(m2.rsa_get_n(self.rsa))) + + def __setstate__(self, state): + self.rsa = None + self._hasPrivateKey = False + self.key_type = state[0] + if len(state) > 1: + self.rsa = m2.rsa_new() + m2.rsa_set_e(self.rsa, numberToMPI(state[1])) + m2.rsa_set_n(self.rsa, numberToMPI(state[2])) + def __del__(self): if self.rsa: m2.rsa_free(self.rsa)