Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
119d7768
Commit
119d7768
authored
Jun 02, 2014
by
Brian Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Also use md5 for constructing key for hmac.
parent
919b4338
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
5 deletions
+6
-5
common/djangoapps/track/middleware.py
+5
-5
common/djangoapps/track/tests/test_middleware.py
+1
-0
No files found.
common/djangoapps/track/middleware.py
View file @
119d7768
...
@@ -125,12 +125,12 @@ class TrackMiddleware(object):
...
@@ -125,12 +125,12 @@ class TrackMiddleware(object):
return
''
return
''
# Follow the model of django.utils.crypto.salted_hmac() and
# Follow the model of django.utils.crypto.salted_hmac() and
# django.contrib.sessions.backends.base._hash()
,
but use MD5
# django.contrib.sessions.backends.base._hash() but use MD5
#
so that the result has the same length (32) as the original
#
instead of SHA1 so that the result has the same length (32)
# session_key.
#
as the original
session_key.
key_salt
=
"common.djangoapps.track"
+
self
.
__class__
.
__name__
key_salt
=
"common.djangoapps.track"
+
self
.
__class__
.
__name__
key
=
hashlib
.
sha1
(
key_salt
+
settings
.
SECRET_KEY
)
.
digest
()
key
=
hashlib
.
md5
(
key_salt
+
settings
.
SECRET_KEY
)
.
digest
()
encrypted_session_key
=
hmac
.
new
(
key
,
msg
=
session_key
)
.
hexdigest
()
encrypted_session_key
=
hmac
.
new
(
key
,
msg
=
session_key
,
digestmod
=
hashlib
.
md5
)
.
hexdigest
()
return
encrypted_session_key
return
encrypted_session_key
def
get_user_primary_key
(
self
,
request
):
def
get_user_primary_key
(
self
,
request
):
...
...
common/djangoapps/track/tests/test_middleware.py
View file @
119d7768
...
@@ -118,6 +118,7 @@ class TrackMiddlewareTestCase(TestCase):
...
@@ -118,6 +118,7 @@ class TrackMiddlewareTestCase(TestCase):
request
.
session
.
save
()
request
.
session
.
save
()
session_key
=
request
.
session
.
session_key
session_key
=
request
.
session
.
session_key
expected_session_key
=
self
.
track_middleware
.
encrypt_session_key
(
session_key
)
expected_session_key
=
self
.
track_middleware
.
encrypt_session_key
(
session_key
)
self
.
assertEquals
(
len
(
session_key
),
len
(
expected_session_key
))
context
=
self
.
get_context_for_request
(
request
)
context
=
self
.
get_context_for_request
(
request
)
self
.
assert_dict_subset
(
context
,
{
self
.
assert_dict_subset
(
context
,
{
'session'
:
expected_session_key
,
'session'
:
expected_session_key
,
...
...
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