Open droans opened 4 months ago
Messed with this a little bit and couldn't get very far.
curl -X POST https://cognito-idp.us-east-1.amazonaws.com \
-H 'Content-Type: application/x-amz-json-1.1' \
-H 'X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuth' \
-d '{
"AuthParameters": {
"USERNAME": "<email@gmail.com>",
"PASSWORD": "<password>"
},
"AuthFlow": "USER_PASSWORD_AUTH",
"ClientId": "6kqofhc8hm394ielqdkvli0oea"
}'
got me the JSON response of the AccessToken, IdToken, and RefreshToken, but couldn't get past that. (Truncated example below):
"AuthenticationResult": {
"AccessToken": "eyJraWQiOiJZSW8zUUNDVGZ3TnNYRjIxSGxwYWZGMlQ4VXk2TGJ1OVl4aEtpK29oS0VFPSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiI3ODg0OWEyNi0xNTc2LTQxMjctYjNhNS1iYjliM2I1NmUxNDAiLCJpc3MiOiJodHRwczpcL1wvY29nbml0by1pZHAudXMtZWFzdC0xLmFtYXpvbmF3cy5jb21cL3VzLWVhc3QtMV9XMUNESHZOV2kiLCJjbGllbnRfaWQiOiI2a3FvZmhjOGhtMzk0aWVscWRrdmxpMG9lYSIsIm9yaWdpbl9qdGkiOiJhNzcxM2Y0NC01NTBmLTRiNGYtYjkwNC05NDFmNjRkNWVjNTAiLCJldmVudF9pZCI6ImU4NDRhMTAwLWRhNTgDkzWrJvFAKc1joBcwRN0BSYrNEYwwJU8Io0JgEmSwJcUc5KY82ihlIMJm4IUXJXnCkL7kHE6K7YXraQkNA0jD_tMqESU4If13cap72W4FHDAFcPChi9yHcPJkJYTtRs291Fp3Bchb-spVeUxsz2oyNkFrJOanOtDEXVu5QneDLQjhzz-si8ObiodQvdbjJxKub3n3LxWZpJwcGaSdgm3oI2-2tWLBcpAuAs2vDXC82i0sW76hZecEjF9Mbvb-ooaNO97x9ZPMN-ZE91Bm5QObExTuJl5BSEaYzx6vca9JI_3UwqjUd9QWnUr6jp_kn46YaPDSySFvUx1w",
"ExpiresIn": 10800,
"Id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sYw8JoTLxu2AdK7p4DlVN1YZQR99IENguhIsRHOuL13LsTexXw3bsV7rF-nC1fOgHgWdd4s3htSiJrSY_Kzj_lkyrzfOwnVKTeWpqwNagYVExDervxmmtTg-vJ15gm3jr6VI1kBMj3mlaxZJdCYjoHwhehkPypM4tZtLGE451RxGo4-OYMDxQFpRlO4t0JoQP9UFvyyvS4RyX37o8SFID10n9_ZihqVUBkoRZnD-846mfZIaUUQDnXdUqNgihcjNwdkWnVrp4Nu2cDsnXa1ry9qLqEY4oHTQXH1cwk4ADhKiW874JanPs_W0zJL7pvuEH05PmkASV946USSdvZG4TCJb78txT-84jrrjE8Ptpk3kzAm-kujSxp6OMYuIn_dXLuysUJ-y9-ENYCRBLDMQ1so3-d3tcxHeBIuo5N2B9ekhIvUgMsDMp0VCjVQz4YGJwDVYU7KLcM-6A8xe9-XlqjimdX9makoPffJmvDLAzGHl15c9_UxGFcJkafXMNrexiRA9akNB_qZkGR5UzzwGQuOa7M64IOZmulmGF50r8SkV14jqw.OaNJW468whhcgqoEFKNPig",
"TokenType": "Bearer"
},
"ChallengeParameters": {}
}
curl -X GET https://api-us-east-1-prod.happiestbaby.com/us/me/v10/pubnub/authorize \
-H 'Authorization: Bearer <long access token>' \
-H 'Content-Type: application/json; charset=UTF-8' \
-H 'Accept-Encoding: gzip' \
-H 'User-Agent: okhttp/4.12.0' \
-H 'Accept: application/json' \
-H 'accept-language: US'
and any variations return {"message":"Forbidden"}
I'm having the same issue now, too, which is odd since it worked perfectly for me the other day.
I'm not certain what the issue is... I still have the Python terminal open from when I tested this and I confirmed that I used the exact same data except for the key itself.
I tested a few different endpoints before I got the correct endpoint. I wonder if that might be related. Let me run a couple tests and I'll try to get a basic Python PoC script.
Also, if you would like to get the data on your own to figure it out, here are the basic steps. You will need a Linux computer and an Android phone.
Now, since the app uses a pinned cert, it won't let us use that cert yet. Instead, we have to pull it from the phone, decompile the app and recompile it without pinning, and then reinstall it. Luckily, there are tools to help already.
apk-mitm
. You can just run npm install -g apk-mitm
. apks
file and get it onto your computer. You can either use adb pull
or send it to yourself another way.apk-mitm <name-of-app>
. It will perform all the hard work for you.apks
file back onto your phone.Go back to PCAPdroid and click Ready. Open the Happiest Baby app, login, and then go back to PCAPdroid and click the stop button. Go over to Connections and ensure that the traffic was recorded and decrypted. Now you can click on each connection to view all the packets sent and received.
I think I figured out the issue. It turns out it was the idToken
that is used.
Here's the code. The authorize()
function will return a requests object.
I've also found the endpoints for interacting with the Snoo - starting, stopping, and changing the level. The example code at the bottom should make things clear.
E: I have updated the code to include a Pyscript script and HA templates for people to manually create a template sensor and select to manage their Snoo until the API is fixed.
For the past couple weeks, I've been receiving an error in my logs that the login endpoint cannot be reached.
Message:
Using PCAPDroid with a recompiled APK, it appears the proper endpoint is
https://cognito-idp.us-east-1.amazonaws.com
with the data being:Headers:
Which will then return a Bearer Token to login in the format of:
I'm not sure if this is any different than before, but you then need to get a second token. It's retrieved by sending a POST request to
https://api-us-east-1-prod.happiestbaby.com/us/me/v10/pubnub/authorize
with the following headers and data:Headers:
Data:
And you'll receive data similar to:
The token is then passed as a parameter in the requests. To retrieve the general status, send a GET request to
https://happiestbaby.pubnubapi.com/v2/subscribe/sub-c-97bade2a-483d-11e6-8b3b-02ee2ddab7fe/ActivityState.<DEVICE_SERIAL>/0?tt=<TIMESTAMP-17200321439663207>&pnsdk=PubNub-Kotlin%2F7.4.0&l_pub=0.091&auth=<ANOTHER_LONG_TOKEN>&heartbeat=300&requestid=<UUID>&state=%7B%7D&uuid=<PHONE_UUID>&tr=24
UUID is formatted as
XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
. PHONE_UUID is formatted similarly but is prefixed with the phone type plus a 23 character hex, so something likeandroid_XXXXXXXXXXXXXXXXXXXXXXX_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX