From 6bf84151e414a663fdc22e71b7f67f441955e9d8 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Tue, 31 Oct 2017 11:07:28 +0100 Subject: [PATCH] Silent bug fix (.encode() is not safe for base64 encoding because of whitespaces) --- lib/utils/api.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/utils/api.py b/lib/utils/api.py index 5003ffae0..ee96635c6 100644 --- a/lib/utils/api.py +++ b/lib/utils/api.py @@ -23,6 +23,7 @@ from lib.core.common import dataToStdout from lib.core.common import getSafeExString from lib.core.common import saveConfig from lib.core.common import unArrayizeValue +from lib.core.convert import base64encode from lib.core.convert import hexencode from lib.core.convert import dejsonize from lib.core.convert import jsonize @@ -654,7 +655,7 @@ def download(taskid, target, filename): logger.debug("[%s] Retrieved content of file %s" % (taskid, target)) with open(path, 'rb') as inf: file_content = inf.read() - return jsonize({"success": True, "file": file_content.encode("base64")}) + return jsonize({"success": True, "file": base64encode(file_content)}) else: logger.warning("[%s] File does not exist %s" % (taskid, target)) return jsonize({"success": False, "message": "File does not exist"}) @@ -722,7 +723,7 @@ def _client(url, options=None): headers = {"Content-Type": "application/json"} if DataStore.username or DataStore.password: - headers["Authorization"] = "Basic %s" % ("%s:%s" % (DataStore.username or "", DataStore.password or "")).encode("base64").strip() + headers["Authorization"] = "Basic %s" % base64encode("%s:%s" % (DataStore.username or "", DataStore.password or "")) req = urllib2.Request(url, data, headers) response = urllib2.urlopen(req)