diff --git a/lms/djangoapps/verify_student/models.py b/lms/djangoapps/verify_student/models.py index 2a0cb2d466..5c5377cb04 100644 --- a/lms/djangoapps/verify_student/models.py +++ b/lms/djangoapps/verify_student/models.py @@ -10,11 +10,13 @@ photo verification process as generic as possible. """ from __future__ import absolute_import, unicode_literals +import base64 import codecs import functools import json import logging import os.path +import simplejson import uuid from datetime import timedelta from email.utils import formatdate @@ -810,11 +812,10 @@ class SoftwareSecurePhotoVerification(PhotoVerification): faces. """ face_aes_key_str = settings.VERIFY_STUDENT["SOFTWARE_SECURE"]["FACE_IMAGE_AES_KEY"] - face_aes_key = face_aes_key_str.decode("hex") + face_aes_key = codecs.decode(face_aes_key_str, 'hex') rsa_key_str = settings.VERIFY_STUDENT["SOFTWARE_SECURE"]["RSA_PUBLIC_KEY"] rsa_encrypted_face_aes_key = rsa_encrypt(face_aes_key, rsa_key_str) - - return rsa_encrypted_face_aes_key.encode("base64") + return base64.b64encode(rsa_encrypted_face_aes_key) def create_request(self, copy_id_photo_from=None): """ @@ -884,7 +885,7 @@ class SoftwareSecurePhotoVerification(PhotoVerification): header_txt = "\n".join( u"{}: {}".format(h, v) for h, v in sorted(headers.items()) ) - body_txt = json.dumps(body, indent=2, sort_keys=True, ensure_ascii=False).encode('utf-8') + body_txt = json.dumps(body, indent=2, sort_keys=True, ensure_ascii=False) return header_txt + "\n\n" + body_txt @@ -912,10 +913,11 @@ class SoftwareSecurePhotoVerification(PhotoVerification): return fake_response headers, body = self.create_request(copy_id_photo_from=copy_id_photo_from) + response = requests.post( settings.VERIFY_STUDENT["SOFTWARE_SECURE"]["API_URL"], headers=headers, - data=json.dumps(body, indent=2, sort_keys=True, ensure_ascii=False).encode('utf-8'), + data=simplejson.dumps(body, indent=2, sort_keys=True, ensure_ascii=False).encode('utf-8'), verify=False ) diff --git a/lms/djangoapps/verify_student/ssencrypt.py b/lms/djangoapps/verify_student/ssencrypt.py index 0db7a231cd..8e4d907281 100644 --- a/lms/djangoapps/verify_student/ssencrypt.py +++ b/lms/djangoapps/verify_student/ssencrypt.py @@ -179,7 +179,7 @@ def generate_signed_message(method, headers_dict, body_dict, access_key, secret_ signature = binascii.b2a_base64(hashed.digest()).rstrip(b'\n') authorization_header = u"SSI {}:{}".format(access_key, signature) - message += '\n' + message += b'\n' return message, signature, authorization_header @@ -191,7 +191,7 @@ def signing_format_message(method, headers_dict, body_dict): """ headers_str = "{}\n\n{}".format(method, header_string(headers_dict)) body_str = body_string(body_dict) - message = headers_str + body_str + message = six.b(headers_str) + body_str return message @@ -231,4 +231,4 @@ def body_string(body_dict, prefix=""): value = "null" body_list.append(u"{}{}:{}\n".format(prefix, key, value)) - return "".join(body_list) # Note that trailing \n's are important + return b"".join(body_list) # Note that trailing \n's are important diff --git a/lms/djangoapps/verify_student/tests/test_models.py b/lms/djangoapps/verify_student/tests/test_models.py index 33bf681b75..a269dd4b70 100644 --- a/lms/djangoapps/verify_student/tests/test_models.py +++ b/lms/djangoapps/verify_student/tests/test_models.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -import json +import base64 +import simplejson as json from datetime import datetime, timedelta import boto @@ -66,8 +67,8 @@ def mock_software_secure_post(url, headers=None, data=None, **kwargs): assert data_dict.get(key) # The keys should be stored as Base64 strings, i.e. this should not explode - data_dict["PhotoIDKey"].decode("base64") - data_dict["UserPhotoKey"].decode("base64") + data_dict["PhotoIDKey"] = base64.b64decode(data_dict["PhotoIDKey"]) + data_dict["UserPhotoKey"] = base64.b64decode(data_dict["UserPhotoKey"]) response = requests.Response() response.status_code = 200