diff options
author | Noémi Ványi <sitbackandwait@gmail.com> | 2017-07-20 15:44:02 +0200 |
---|---|---|
committer | Noémi Ványi <sitbackandwait@gmail.com> | 2017-09-08 21:33:11 +0200 |
commit | e73cb14889d29082c3a585644d547e6798fdb6fc (patch) | |
tree | dab93bb86bf1cc93a4435f80a876dba95a478739 /searx | |
parent | 9804ab7a1bd6dd4b7abca06e016b08c94cde4514 (diff) | |
download | searxng-e73cb14889d29082c3a585644d547e6798fdb6fc.tar.gz searxng-e73cb14889d29082c3a585644d547e6798fdb6fc.zip |
fix hmac python3 compatibility
Diffstat (limited to 'searx')
-rw-r--r-- | searx/utils.py | 9 | ||||
-rw-r--r-- | searx/webapp.py | 7 |
2 files changed, 13 insertions, 3 deletions
diff --git a/searx/utils.py b/searx/utils.py index 35b20ad83..8be7beb62 100644 --- a/searx/utils.py +++ b/searx/utils.py @@ -1,4 +1,6 @@ import csv +import hashlib +import hmac import os import re @@ -321,3 +323,10 @@ def load_module(filename, module_dir): module = load_source(modname, filepath) module.name = modname return module + + +def new_hmac(secret_key, url): + if sys.version_info[0] == 2: + return hmac.new(bytes(secret_key), url, hashlib.sha256).hexdigest() + else: + return hmac.new(bytes(secret_key, 'utf-8'), url, hashlib.sha256).hexdigest() diff --git a/searx/webapp.py b/searx/webapp.py index 0751fb983..f90299b2a 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -69,6 +69,7 @@ from searx.plugins import plugins from searx.preferences import Preferences, ValidationException from searx.answerers import answerers from searx.url_utils import urlencode, urlparse, urljoin +from searx.utils import new_hmac # check if the pyopenssl package is installed. # It is needed for SSL connection without trouble, see #298 @@ -290,7 +291,7 @@ def image_proxify(url): if settings.get('result_proxy'): return proxify(url) - h = hmac.new(settings['server']['secret_key'], url.encode('utf-8'), hashlib.sha256).hexdigest() + h = new_hmac(settings['server']['secret_key'], url.encode('utf-8')) return '{0}?{1}'.format(url_for('image_proxy'), urlencode(dict(url=url.encode('utf-8'), h=h))) @@ -704,7 +705,7 @@ def image_proxy(): if not url: return '', 400 - h = hmac.new(settings['server']['secret_key'], url, hashlib.sha256).hexdigest() + h = new_hmac(settings['server']['secret_key'], url) if h != request.args.get('h'): return '', 400 @@ -731,7 +732,7 @@ def image_proxy(): logger.debug('image-proxy: wrong content-type: {0}'.format(resp.headers.get('content-type'))) return '', 400 - img = '' + img = b'' chunk_counter = 0 for chunk in resp.iter_content(1024 * 1024): |