﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
10253	sessions.base.py random.SystemRandom() fails	monkut	nobody	"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(),




"		new	Uncategorized	1.0					Unreviewed	0	0	0	0	0	0
