Skip to content

Commit f5e9583

Browse files
committed
Fixed str/bytes issues with hashlib function arguments.
- Legacy-Id: 16354
1 parent f5ae254 commit f5e9583

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

ietf/utils/accesstoken.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
# Copyright The IETF Trust 2013-2019, All Rights Reserved
12
import time, random, hashlib
23

34
from django.conf import settings
5+
from django.utils.encoding import force_bytes
46

57
def generate_random_key(max_length=32):
68
"""Generate a random access token."""
7-
return hashlib.sha256(settings.SECRET_KEY + ("%.16f" % time.time()) + ("%.16f" % random.random())).hexdigest()[:max_length]
9+
return hashlib.sha256(force_bytes(settings.SECRET_KEY) + (b"%.16f" % time.time()) + (b"%.16f" % random.random())).hexdigest()[:max_length]
810

911
def generate_access_token(key, max_length=32):
1012
"""Make an access token out of key."""
1113
assert key, "key must not be empty"
1214
# we hash it with the private key to make sure only we can
1315
# generate and use the final token - so storing the key in the
1416
# database is safe
15-
return hashlib.sha256(settings.SECRET_KEY + key).hexdigest()[:max_length]
17+
return hashlib.sha256(force_bytes(settings.SECRET_KEY) + force_bytes(key)).hexdigest()[:max_length]

0 commit comments

Comments
 (0)