Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pickle #479

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tlslite/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,8 @@ class SNIExtension(TLSExtension):
"""

ServerName = namedtuple('ServerName', 'name_type name')
# make the namedtuple pickleable
globals()[ServerName.__name__] = ServerName

def __init__(self):
"""
Expand Down
19 changes: 19 additions & 0 deletions tlslite/utils/openssl_rsakey.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def password_callback(v, prompt1='Enter private key passphrase:',

if m2cryptoLoaded:
import M2Crypto
# the methods like rsa_get_e and rsa_get_n are native, so pylint can't find
# them, ignore those errors
#pylint: disable=no-member

class OpenSSL_RSAKey(RSAKey):
def __init__(self, n=0, e=0, key_type="rsa"):
Expand All @@ -43,6 +46,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)
Expand Down