Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
8e127f87
Commit
8e127f87
authored
Oct 31, 2012
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LP #1071067: Use a stronger random number generator and a constant time comparison function.
parent
41be01e2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
6 deletions
+30
-6
src/Products/Sessions/BrowserIdManager.py
src/Products/Sessions/BrowserIdManager.py
+29
-5
versions.cfg
versions.cfg
+1
-1
No files found.
src/Products/Sessions/BrowserIdManager.py
View file @
8e127f87
############################################################################
#
#
# Copyright (c) 2002 Zope Foundation and Contributors.
#
# This software is subject to the provisions of the Zope Public License,
...
...
@@ -10,10 +10,12 @@
# FOR A PARTICULAR PURPOSE
#
############################################################################
import
binascii
from
cgi
import
escape
from
hashlib
import
sha256
import
logging
import
random
import
os
import
re
import
string
import
sys
...
...
@@ -63,6 +65,29 @@ TRAVERSAL_APPHANDLE = 'BrowserIdManager'
LOG = logging.getLogger('
Zope
.
BrowserIdManager
')
# Use the system PRNG if possible
import random
try:
random = random.SystemRandom()
using_sysrandom = True
except NotImplementedError:
using_sysrandom = False
def _randint(start, end):
if not using_sysrandom:
# This is ugly, and a hack, but it makes things better than
# the alternative of predictability. This re-seeds the PRNG
# using a value that is hard for an attacker to predict, every
# time a random string is required. This may change the
# properties of the chosen random sequence slightly, but this
# is better than absolute predictability.
random.seed(sha256(
"%s%s%s" % (random.getstate(), time.time(), os.getpid())
).digest())
return random.randint(start, end)
def constructBrowserIdManager(
self, id=BROWSERID_MANAGER_NAME, title='', idname='
_ZopeId
',
location=('
cookies
', '
form
'), cookiepath='
/
', cookiedomain='',
...
...
@@ -553,7 +578,7 @@ def isAWellFormedBrowserId(bid, binerr=binascii.Error):
return
None
def
getNewBrowserId
(
randint
=
random
.
randint
,
maxint
=
99999999
):
def
getNewBrowserId
(
randint
=
_
randint
,
maxint
=
99999999
):
""" Returns 19-character string browser id
'AAAAAAAABBBBBBBB'
where:
...
...
@@ -568,5 +593,4 @@ def getNewBrowserId(randint=random.randint, maxint=99999999):
An example is: 89972317A0C3EHnUi90w
"""
return
'%08i%s'
%
(
randint
(
0
,
maxint
-
1
),
getB64TStamp
())
return
'%08i%s'
%
(
randint
(
0
,
maxint
-
1
),
getB64TStamp
())
versions.cfg
View file @
8e127f87
...
...
@@ -5,7 +5,7 @@ versions = versions
[versions]
# Zope2-specific
Zope2 =
AccessControl = 3.0.
5
AccessControl = 3.0.
6
Acquisition = 4.0a1
DateTime = 3.0.2
DocumentTemplate = 2.13.2
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment