trevp/tlslite

parsePrivateKey fails with Python 2.7 and PyCrypto due to long vs int

Closed this issue · 4 comments

Trying to use tlslite.utils.keyfactory.parsePrivateKey with Python 2.7 when PyCypto is installed raises an unhelpful AssertionError. It comes from within PyCrypto which expects long values rather than int and refuses to take anything else.

I'm going to guess this is due to the Python 3 changes from 0.4.4.

Hi Kyle,

On Tue, Apr 30, 2013 at 2:11 AM, Kyle MacFarlane
notifications@github.comwrote:

Trying to use tlslite.utils.keyfactory.parsePrivateKey with Python 2.7
when PyCypto is installed raises an unhelpful AssertionError. It comes
from within PyCryptohttps://github.com/dlitz/pycrypto/blob/master/lib/Crypto/PublicKey/_slowmath.py#L84-L89which expects
long values rather than int and refuses to take anything else.

I'm going to guess this is due to the Python 3 changes from 0.4.4.

Thanks, could be - do you have a patch, by any chance?

Trevor

I downgraded my project back to 0.4.3 rather than patch it.

I had another look at it and the ints seem to be coming from tlslite.cyptomath.bytesToNumber and making it return a long in Python 2 seems to fix things. However the long/int problem could be more widespread.

I also noticed that tlslite.cyptomath.powMod always returns a long which wouldn't be compatible with Python 3 since long was merged with int.

I fixed it by casting all the args to long, but now I get numberToString is not defined. Also get that error in 3.4

Fixed in git head, I think.