I'm trying to figure out how to generate the value for the response to the Amazon Cognito challenge: DEVICE_PASSWORD_VERIFIER
. I've spent several days on this problem now, perused many of Amazon's documentation as well as references the other SO post on this topic, which also did not get it to work. I've made a temporary repository with my code as it currently stands (with everything redacted, but you should be able to run it if you fill in the environment variables).
I'm using the AWS Java SDK. I manage to pass the first challenge DEVICE_SRP_AUTH
, whereupon I always get NotAuthorizedException: Invalid username or password
on the second challenge DEVICE_PASSWORD_VERIFIER
. I'm assuming that the code I've written to generate either the SRP_A
value or the PASSWORD_CLAIM_SIGNATURE
is wrong, though I cannot figure out what or where. All the relevant functions to generating these values can be found in the DeviceHelper
class. Furthermore, I am using the ADMIN_USER_PASSWORD_AUTH
auth flow as well as the adminRespondToAuthChallenge
functions.
Edit: If anyone knows of any good libraries that support generating these values for AWS Cognito, that'd be a good solution too. However, I did not manage to find any on my own.
Here's the settings of the user pool:
Any help would be greatly appreciated as I am now at a complete loss. Cheers.
For anyone that runs into the same issue, I've updated my code in the repository linked in the question. It works now, feel free to copy said code for your own use, just don't waste literal days of your time trying to figure out a solution on your own like I did. Realistically Amazon should provide the functions to generate these values within their SDK, but they don't. So, feel free to use mine.
You may also want to reference the SRPHelper class in the Amplify Android library. This also implements this flow, but you must not do M1 = MAC(poolId | userId | secret | timestamp, key)
for this authentication flow. Instead use, M1 = MAC(deviceGroupKey | deviceKey | base64_decode(secretBlock) | timestamp)
. Though you get a USER_ID_FOR_SRP
value from the first challenge, you must not use this either. Ignore it. Furthermore, the calculation is FullPassword = SHA256(deviceGroupKey | deviceKey | ":" | devicePassword)
, not anything else.