From c0a19a7d7a55ff80879dc775419caa227a9bffe5 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Wed, 29 Nov 2017 10:48:13 +0100 Subject: [PATCH] Fix padding zero for none glibc system --- warrant/aws_srp.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/warrant/aws_srp.py b/warrant/aws_srp.py index dc0a9bfc..3b53f34e 100644 --- a/warrant/aws_srp.py +++ b/warrant/aws_srp.py @@ -3,7 +3,7 @@ import datetime import hashlib import hmac -import sys +import re import boto3 import os @@ -172,16 +172,14 @@ def get_secret_hash(username, client_id, client_secret): hmac_obj = hmac.new(bytearray(client_secret, 'utf-8'), message, hashlib.sha256) return base64.standard_b64encode(hmac_obj.digest()).decode('utf-8') - def process_challenge(self, challenge_parameters, test_timestamp=None): + def process_challenge(self, challenge_parameters): user_id_for_srp = challenge_parameters['USER_ID_FOR_SRP'] salt_hex = challenge_parameters['SALT'] srp_b_hex = challenge_parameters['SRP_B'] secret_block_b64 = challenge_parameters['SECRET_BLOCK'] - if sys.platform.startswith('win'): - format_string = "%a %b %#d %H:%M:%S UTC %Y" - else: - format_string = "%a %b %-d %H:%M:%S UTC %Y" - timestamp = test_timestamp or datetime.datetime.utcnow().strftime(format_string) + # re strips leading zero from a day number (required by AWS Cognito) + timestamp = re.sub(r" 0(\d) ", r" \1 ", + datetime.datetime.utcnow().strftime("%a %b %d %H:%M:%S UTC %Y")) hkdf = self.get_password_authentication_key(user_id_for_srp, self.password, hex_to_long(srp_b_hex), salt_hex) secret_block_bytes = base64.standard_b64decode(secret_block_b64)