gpsoauth icon indicating copy to clipboard operation
gpsoauth copied to clipboard

Negative RSA exponent for android_key_7_3_29 on Windows

Open phausamann opened this issue 6 years ago • 3 comments

For some reason, the android_key_7_3_29 global variable has a negative exponent on my Windows machine.

from gpsoauth import google, android_key_7_3_29
google.signature('[email protected]', 'asdf', android_key_7_3_29)

raises:

Traceback (most recent call last):  
  File "<input>", line 1, in <module>
  File "<PYTHONLIB>\site-packages\gpsoauth\google.py", line 50, in signature
    encrypted_login = cipher.encrypt((email + u'\x00' + password).encode('utf-8'))
  File "<PYTHONLIB>\site-packages\Cryptodome\Cipher\PKCS1_OAEP.py", line 138, in encrypt
    m_int = self._key._encrypt(em_int)
  File "<PYTHONLIB>\site-packages\Cryptodome\PublicKey\RSA.py", line 145, in _encrypt
    return int(pow(Integer(plaintext), self._e, self._n))
  File "<PYTHONLIB>\site-packages\Cryptodome\Math\_Numbers_gmp.py", line 404, in __pow__
    return result.inplace_pow(exponent, modulus)
  File "<PYTHONLIB>\site-packages\Cryptodome\Math\_Numbers_gmp.py", line 395, in inplace_pow
    raise ValueError("Exponent must not be negative")
ValueError: Exponent must not be negative

System info:

  • gpsoauth version 0.4.1
  • Python 3.6.5 [MSC v.1900 64 bit (AMD64)]
  • Windows-10-10.0.16299-SP0 x64

phausamann avatar Apr 10 '18 07:04 phausamann

That's pretty odd. Can you try printing the value of the key, and if that's not helpful, then also the values in RSA.py:145? Then we can compare them against what we see on a linux machine.

simon-weber avatar Apr 10 '18 17:04 simon-weber

On both Windows and BashOnUbuntuOnWindows (where I don't get the error) I get:

>>> android_key_7_3_29
RsaKey(n=141956196257934770187925561804359820971448272350983018436093173897855484510782207920697285059648243152878542520514658971720228524276304322321325896163977435852395272134149378260200371457183474602754725451457370420041505749329659663863538423736961928495802209949126722610439862310060378247113201580053877385209, e=65537)

The reason for the bug seems do be that in Cryptodome.Math._Numbers_gmp.Integer.inplace_pow, line 394, exponent.is_negative() returns True on Windows.

phausamann avatar Apr 13 '18 08:04 phausamann

Hm. e is 2**16+1. Is it possible that something on windows is trying to put that value into a 16-bit int and overflowing?

simon-weber avatar Apr 13 '18 14:04 simon-weber