From 3808b2991c4583ca84f8be7a8ac0d655edf96060 Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Wed, 18 Dec 2019 13:54:37 -0500 Subject: [PATCH] Ensure that photo verification data is correctly typed. There were cases where we needed to encode things to codecs other than ascii. In these cases, python returns byte strings but we needed them to be unicode so that they serialize correctly later when we combine them with other unicode strings. --- .../management/commands/retry_failed_photo_verifications.py | 2 +- lms/djangoapps/verify_student/models.py | 2 +- lms/djangoapps/verify_student/ssencrypt.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lms/djangoapps/verify_student/management/commands/retry_failed_photo_verifications.py b/lms/djangoapps/verify_student/management/commands/retry_failed_photo_verifications.py index 3979e5d850..d75e5a6335 100644 --- a/lms/djangoapps/verify_student/management/commands/retry_failed_photo_verifications.py +++ b/lms/djangoapps/verify_student/management/commands/retry_failed_photo_verifications.py @@ -31,7 +31,7 @@ class Command(BaseCommand): dest='verification_ids', action='store', nargs='+', - type=int, + type=str, help='verifications id used to retry verification' ) diff --git a/lms/djangoapps/verify_student/models.py b/lms/djangoapps/verify_student/models.py index 73f2e6b201..9bcd1f4c05 100644 --- a/lms/djangoapps/verify_student/models.py +++ b/lms/djangoapps/verify_student/models.py @@ -837,7 +837,7 @@ class SoftwareSecurePhotoVerification(PhotoVerification): 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 base64.b64encode(rsa_encrypted_face_aes_key) + return base64.b64encode(rsa_encrypted_face_aes_key).decode('utf-8') def create_request(self, copy_id_photo_from=None): """ diff --git a/lms/djangoapps/verify_student/ssencrypt.py b/lms/djangoapps/verify_student/ssencrypt.py index 0db7a231cd..3715055bb9 100644 --- a/lms/djangoapps/verify_student/ssencrypt.py +++ b/lms/djangoapps/verify_student/ssencrypt.py @@ -176,7 +176,7 @@ def generate_signed_message(method, headers_dict, body_dict, access_key, secret_ # hmac needs a byte string for it's starting key, can't be unicode. hashed = hmac.new(secret_key.encode('utf-8'), message.encode('utf-8'), sha256) - signature = binascii.b2a_base64(hashed.digest()).rstrip(b'\n') + signature = binascii.b2a_base64(hashed.digest()).rstrip(b'\n').decode('utf-8') authorization_header = u"SSI {}:{}".format(access_key, signature) message += '\n'