implementing USER_SRP_AUTH with python boto3 for AWS Cognito

前端 未结 2 1314
渐次进展
渐次进展 2020-12-31 06:55

Amazon provides iOS, Android, and Javascript Cognito SDKs that offer a high-level authenticate-user operation.

For example, see Use Case 4 here:

https://gith

相关标签:
2条回答
  • 2020-12-31 07:44

    There are many errors in your implementation. For example:

    1. pysrp uses SHA1 algorithm by default. It should be set to SHA256.
    2. _ng_const length should be 3072 bits and it should be copied from amazon-cognito-identity-js
    3. There is no hkdf function in pysrp.
    4. The response should contain secret_block_b64, not secret_block_hex.
    5. Wrong timestamp format. %H:%m:%S means "hour:month:second" and +0000 should be replaced by UTC.

    Has anyone gotten this working?

    Yes. It's implemented in the warrant.aws_srp module. https://github.com/capless/warrant/blob/develop/warrant/aws_srp.py

    from warrant.aws_srp import AWSSRP
    
    
    USERNAME='xxx'
    PASSWORD='yyy'
    POOL_ID='us-east-1_zzzzz'
    CLIENT_ID = '12xxxxxxxxxxxxxxxxxxxxxxx'
    
    aws = AWSSRP(username=USERNAME, password=PASSWORD, pool_id=POOL_ID,
                 client_id=CLIENT_ID)
    tokens = aws.authenticate_user()
    id_token = tokens['AuthenticationResult']['IdToken']
    refresh_token = tokens['AuthenticationResult']['RefreshToken']
    access_token = tokens['AuthenticationResult']['AccessToken']
    token_type = tokens['AuthenticationResult']['TokenType']
    

    Note, that aws_srp module was not merged into master branch yet.

    authenticate_user method supports only PASSWORD_VERIFIER challenge. If you want to respond to other challenges, just look into the authenticate_user and boto3 documentation.

    0 讨论(0)
  • 2020-12-31 07:47

    Unfortunately it's a hard problem since you don't get any hints from the service with regards to the computations (it mainly says not authorized as you mentioned).

    We are working on improving the developer experience when users are trying to implement SRP on their own in languages where we don't have an SDK. Also, we are trying to add more SDKs.

    As daunting as it sounds, what I would suggest is to take the Javascript or the Android SDK, fix the inputs (SRP_A, SRP_B, TIMESTAMP) and add console.log statements at various points in the implementation to make sure your computations are similar. Then you would run these computations in your implementation and make sure you are getting the same. As you have suggested, the password claim signature needs to be passed as a base64 encoded string to the service so that might be one of the issues.

    Some of the issues I encountered while implementing this was related to BigInteger library differences (the way they do byte padding and transform negative numbers to byte arrays and inversely).

    0 讨论(0)
提交回复
热议问题