This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Connecting to AWS Cognito

I am trying to modify the https_client example from ncs\nrf\samples\nrf9160\https_client on Thingy91 so that it will retrieve an authentifcation token from AWS Cognito.
So far I have changed the certificate to Amazon Root CA 1, changed the URL to "cognito-idp.eu-central-1.amazonaws.com" instead of "google.com" and sending the following data to the server (sensitive data blanked here) instead of HTTP_HEAD as in the example:
    "POST / HTTP/1.1\r\n" \
    "Host: cognito-idp.eu-central-1.amazonaws.com\r\n" \
    "Content-Type: application/x-amz-json-1.1\r\n" \
    "X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuth\r\n" \
    "Content-Length: 149\r\n" \
    "\r\n" \
    "{\"AuthParameters\": {\"USERNAME\": \"xxxxxxxxx\", \"PASSWORD\": \"xxxxxxxxxxxx\"}, \"AuthFlow\": \"USER_PASSWORD_AUTH\", \"ClientId\": \"xxxxxxxxxxxxxxxxxxxxxxxxxx\"}"

When I send this payload to AWS cognito using openssl s_client on a PC, I get the authentification token, but running on Thingy I just receive an empty reply from the server (zero bytes received, further reads produce an error: -1).
I substituted the certificate for the old one which is not in the verification chain of the cognito server and already the connect command fails, so I can rule out that the certificate is wrong.
I changed Content-Length to a value less than 149 and then I get a BAD REQUEST reply. If I change to something larger than 149, recv will block (which is to be expected as the server is still waiting for the missing payload).
I also tried to wait 2s between send and recv, but I still got an empty response from the server.
Any ideas what to do?

Parents
  • Hello, 

    Have you verified the connection to the server? While doing HTTP requests from servers, we have seen that servers respond with too many certificates causing an issue. The reason for this is that the nRF9160 only has 2k of RAM for certificates, while a web server might return 16k. This explains why you are successful on your PC. 

    Can you please provide a modem trace? This way we can see what actually happens in the communication between server and device.

    Thank you!

    Kind regards,
    Øyvind

  • The COM port disappears from time to time so Trace Collector loses its connection or cannot establish it in time. I have put the application in a reboot loop, but so far I could not capture a useful trace. Is there a possibility to buffer the trace locally on the device?

    I also extracted the server certificate from openssl s_client:

    -----BEGIN CERTIFICATE-----
    MIIFlTCCBH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KwYBBQUHMAGGIWh0dHA6Ly9vY3NwLnNjYTFiLmFtYXpvbnRy
    dXN0LmNvbTA2BggrBgEFBQcwAoYqaHR0cDovL2NydC5zY2ExYi5hbWF6b250cnVz
    dC5jb20vc2NhMWIuY3J0MAwGA1UdEwEB/wQCMAAwggEEBgorBgEEAdZ5AgQCBIH1
    BIHyAPAAdgC72d+8H4pxtZOUI5eqkntHOFeVCqtS6BqQlmQ2jh7RhQAAAWynPFdl
    AAAEAwBHMEUCIDmsmeFBC6oF4gYIjdkvUFYI3gCWb7F0zn318Je3HrHqAiEAv7UH
    aD4CtSZhCcrewbZ69W5gE1D/L8GUGXPzaGHRfTwAdgCHdb/nWXz4jEOZX73zbv9W
    jUdWNv9KtWDBtOr/XqCDDwAAAWynPFeYAAAEAwBHMEUCIEIhVFj9aq6fpihaBI84
    geykNXAf/WaOdYUkmOni3k8IAiEApCUwrn9AGtBqr/Nw5a7yxArueju0CLlFKHq9
    XHnro+swDQYJKoZIhvcNAQELBQADggEBAAG7nSk+LLXZVnD3yNdQIz3qnsfIUvBO
    W8cRJYWUXNM5NO/pPJlNXtSS0azdPTtnimZ3AUIXHQEoaYaawrBy7GIDpRDV7Wg/
    juopGN6AFApzG+2KvmV5vNQ2xM54frcBsJ2hm1gE8VEeZurs6iMe0q/D31FrJA1X
    hCveZ53tcixXs3XeyG4fGLX+jdvtCIf8lq+/4FBC1i2diqtUjaCaHEisD58GxuCZ
    T6JcVKNE3YwrsO7jfdcO6XbMtjqGFDVjWNK3vCHjovj7Z+SfOAqlW2oCDCra4c3M
    uSzRVJ1fYpcOmYS8Aaln/GwkqKiZbqirzh+w8VNm9Eihhd8m3RPeJn0=
    -----END CERTIFICATE-----

    So it should fit into the space constrains.

  • Christian A. said:
    The COM port disappears from time to time so Trace Collector loses its connection or cannot establish it in time.

     Does this happen only with your application? 

    It's difficult for me to tell from the information you have provided, and not having a modem trace. I will need to confer with our R&D team. As it is the AWS Root CA you are provisioning, it should not have any issues, as this is also used in the AWS_FOTA sample.

  • I tried some other examples (including applications/asset_tracker) but when CONFIG_BSD_LIBRARY_TRACE_ENABLED=y is set the COM port gets unstable; when deactivating this option COM communication works smoothly.

  • Please download the Thingy:91 FW package, and program images_full/thingy91_nrf52_connectivity_bridge_2020-04-29_bc7ade8b.hex on the nRF52840.  See here for more information

  • trace-2020-06-08T15-03-07.318Z.binThanks. I wrongly assumed the default firmware would be sufficient. After flashing the connectivity bridge fw I could now capture a trace which is attached.

Reply Children
Related