Opened 16 years ago

Last modified 16 years ago

#10253 closed

sessions.base.py random.SystemRandom() fails — at Initial Version

Reported by: monkut Owned by: nobody
Component: contrib.sessions Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Related to changeset 8340.

# Use the system (hardware-based) random number generator if it exists.
if hasattr(random, 'SystemRandom'):

randrange = random.SystemRandom().randrange

else:

randrange = random.randrange

MAX_SESSION_KEY = 18446744073709551616L # 2 << 63

Platform info:

platform.system()

'SunOS'

platform.version()

'Generic_105181-35'

platform.release()

'5.6'

platform.python_version()

'2.5.2'

Condition in line 17 of base.py, "if hasattr(random, 'SystemRandom'):", evaluates to True, but randrange fails.

hasattr(random, 'SystemRandom')

True

randrange = random.SystemRandom().randrange
randrange(0, MAX_SESSION_KEY)

Traceback (most recent call last):

File "<stdin>", line 1, in <module>
File "/apps/public/python_2.5.2/lib/python2.5/random.py", line 188, in randrange

return int(istart + self._randbelow(width))

File "/apps/public/python_2.5.2/lib/python2.5/random.py", line 235, in _randbelow

r = getrandbits(k)

File "/apps/public/python_2.5.2/lib/python2.5/random.py", line 778, in getrandbits

x = long(_hexlify(_urandom(bytes)), 16)

File "/apps/public/python_2.5.2/lib/python2.5/os.py", line 730, in urandom

raise NotImplementedError("/dev/urandom (or equivalent) not found")

NotImplementedError: /dev/urandom (or equivalent) not found

Exception occurs at when attempting to generate a new session key (when trying to access admin).

File "/django/contrib/sessions/backends/base.py", line 142, in _get_new_session_key % (randrange(0, MAX_SESSION_KEY), pid, time.time(),

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top