capless / warrant

Python library for using AWS Cognito. With support for SRP.
Apache License 2.0
470 stars 191 forks source link

invalid strftime in aws_srp.py #21

Closed stephenoneal closed 7 years ago

stephenoneal commented 7 years ago

https://github.com/capless/warrant/blob/master/warrant/aws_srp.py#L158

I think you want "%a %b %d %H:%M:%S UTC %Y" for the strftime %-d is invalid.

bjinwright commented 7 years ago

I believe you are correct.

armicron commented 7 years ago

It will not authenticate with %d, as it will have a leading zero. @stephenoneal what python version and OS do you use?

http://stackoverflow.com/questions/904928/python-strftime-date-without-leading-0

stephenoneal commented 7 years ago

python 3.4, Windows

stephenoneal commented 7 years ago

oddly i changed it to datetime.datetime.utcnow().strftime("%a %b %d %H:%M:%S UTC %Y") locally and it's passing the PASSWORD_VERIFIER challenge

armicron commented 7 years ago

oddly i changed it to datetime.datetime.utcnow().strftime("%a %b %d %H:%M:%S UTC %Y") locally and it's passing the PASSWORD_VERIFIER challenge

It will fail on May 1.

p.s. To fix this issue the code should be compatible with Windows and Linux both.

bjinwright commented 7 years ago

Oh yeah, that happened at the beginning of this month.

stephenoneal commented 7 years ago

my attention on this is not great right now. need more coffee..

import platform windows_os = any(platform.win32_ver())

    timestamp = test_timestamp or \
                ( datetime.datetime.utcnow().strftime("%a %b %#d %H:%M:%S UTC %Y") if windows_os \
                else datetime.datetime.utcnow().strftime("%a %b %-d %H:%M:%S UTC %Y") )
bjinwright commented 7 years ago

@armicron I think @stephenoneal is proposing a way to detect the OS and format the string accordingly.

armicron commented 7 years ago

I can't test it on windows.

import sys

if sys.platform.startswith('win32'):
    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)
bjinwright commented 7 years ago

Fixed in #28