hawk: force_text on header parts (#38923)

This commit is contained in:
Emmanuel Cazenave 2020-01-09 18:55:00 +01:00
parent 1067158843
commit 1f9bb398c2
1 changed files with 4 additions and 4 deletions

View File

@ -21,7 +21,7 @@ import time
from uuid import uuid4
from django.utils.encoding import force_bytes
from django.utils.encoding import force_bytes, force_text
from django.utils.six.moves.urllib import parse as urlparse
from requests.auth import AuthBase
@ -42,7 +42,7 @@ class HawkAuth(AuthBase):
p_hash.update(force_bytes(req.headers.get('Content-Type', '') + '\n'))
p_hash.update(force_bytes(req.body or ''))
p_hash.update(force_bytes('\n'))
return base64.b64encode(p_hash.digest())
return force_text(base64.b64encode(p_hash.digest()))
def get_authorization_header(self, req):
url_parts = urlparse.urlparse(req.url)
@ -59,8 +59,8 @@ class HawkAuth(AuthBase):
url_parts.hostname, port, hash, self.ext, '']
digestmod = getattr(hashlib, self.algorithm)
result = hmac.new(force_bytes(self.key), force_bytes('\n'.join(data)), digestmod)
mac = base64.b64encode(result.digest())
authorization = 'Hawk id="%s", ts="%s", nonce="%s", hash="%s", mac="%s"'% (self.id, self.timestamp, self.nonce,
mac = force_text(base64.b64encode(result.digest()))
authorization = 'Hawk id="%s", ts="%s", nonce="%s", hash="%s", mac="%s"'% (force_text(self.id), self.timestamp, self.nonce,
hash, mac)
if self.ext:
authorization += ', ext="%s"' % self.ext