Mercurial > p > roundup > code
diff roundup/password.py @ 5350:66a17c80e035
Force all uses of random to use SystemRandom and abort if
pseudorandom random.Random would be used rather than
Random.SystemRandom.
random.Random is returning the same value time after time. Even when
being seeded after instantiation, calls to the random.random()
function return the same value like it's not advanceing the state of
the generator.
So "fix" is to force use of system random generator to generate:
one time keys for password reset (action.py)
random passwords when resetting passwords (password.py)
serial number for auto ssl cert generation (roundup_server.py)
Message-ID's in email: mailgw.py, client.py
anti-csrf nonces (templating.py)
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 07 Jul 2018 22:02:41 -0400 |
| parents | 9792b18e0b19 |
| children | 91954be46a66 |
line wrap: on
line diff
--- a/roundup/password.py Thu Jul 05 22:48:50 2018 -0400 +++ b/roundup/password.py Sat Jul 07 22:02:41 2018 -0400 @@ -19,11 +19,20 @@ """ __docformat__ = 'restructuredtext' -import re, string, random +import re, string import os from base64 import b64encode, b64decode from hashlib import md5, sha1 +try: + # Use the cryptographic source of randomness if available + from random import SystemRandom + random=SystemRandom() +except ImportError: + raise + from random import Random + random=Random() + try: import crypt except ImportError: @@ -363,6 +372,13 @@ assert 'sekrit' == p assert 'not sekrit' != p + + print random.randrange(36, 52) + # this seems to return the save password every time + # when run inside a roundup daemon. + # but it tests out ok. I don't know why. -- rouilj + print generatePassword() + if __name__ == '__main__': test()
