trevp / tlslite

TLS Library in python
Other
235 stars 67 forks source link

Fix for loading x509 RSA certificates with PyCrypto #114

Closed rkondratenko closed 8 years ago

rkondratenko commented 8 years ago

When M2Crypto is not loaded attempt to parse x509 certificate fails with following traceback: File "myfile.py", line 124, in readServerSection x509.parse(c) File "/opt/tlslite/x509.py", line 43, in parse self.parseBinary(bytes) File "/opt/tlslite/x509.py", line 97, in parseBinary self.publicKey = _createPublicRSAKey(n, e) File "/opt/tlslite/utils/keyfactory.py", line 179, in _createPublicRSAKey return PyCrypto_RSAKey(n, e) File "/opt/tlslite/utils/pycrypto_rsakey.py", line 18, in init self.rsa = RSA.construct( (n, e) ) File "/usr/lib/python2.7/dist-packages/Crypto/PublicKey/RSA.py", line 539, in construct key = self._math.rsa_construct(*tup) File "/usr/lib/python2.7/dist-packages/Crypto/PublicKey/_slowmath.py", line 85, in rsa_construct assert isinstance(e, long)

This is because PyCrypto expects parameters as long, but tlslite passes e as int. This was tested on PyCrypto 2.6.1

tomato42 commented 8 years ago

Your approach won't work on Python 3

Could you check tlslite-ng?

It should be fixed there. See coverage for keyfactory.py and pycrypto_rsakey.py

rkondratenko commented 8 years ago

Thank you. That one works fine.