pyauth / pyotp

Python One-Time Password Library
https://pyauth.github.io/pyotp/
Other
2.95k stars 321 forks source link

random_base32 function uses non-cryptographic generator #67

Closed randombit closed 5 years ago

randombit commented 6 years ago

random_base32 calls random.choice which uses Python random() which is implemented using the Mersenne Twister algorithm. This RNG is not cryptographically secure, and given enough of the output is is possible to recover the seed (for example https://github.com/fx5/not_random).

A scenario where this might occur is if random_base32 is used by a service provider. A user requests a new OTP key a few thousand times in a row, recovers the PRNG seed, and then is able to derive all other OTP keys generated by the same server process.

This is easy enough to fix, just use os.urandom if available.

kislyuk commented 5 years ago

Fixed in master. Thanks for reporting.