Fix RSA Invalid Condition on login
Fixes #10 (closed)
First of all, thanks for this library. I was having some unicode issues with megatools and decided to give mega.py a shot.
mega.py was using a hardcoded RSA public exponent of 257. But this was raising an RSA Invalid Condition exception. According to MEGA's webclient js:
// MEGA.nz -- crypto.js var q = privkey, p = privkey, d = privkey, u = privkey, q1 = q.subtract(1), p1 = p.subtract(1), m = new asmCrypto.Modulus(p.multiply(q)), e = new asmCrypto.Modulus(p1.multiply(q1)).inverse(d), dp = d.divide(p1).remainder, dq = d.divide(q1).remainder;
The public exponent
e needs to be calculated from the inverse of
This pull request:
modular_inverseand calculates the public exponent
- clarifies the private_key decoding by de-golfing that code
- clarifies the RSA construct by assigning each piece to a named variable first
If this pull request is accepted, I would like to make some followup pull requests to further increase clarity, add comments and docstrings, move API calls into named functions with docstrings, and de-golf complicated lines.
This is my first time using gitlab instead of github so please let me know if I did anything wrong. Everything is similar but... different.