Skip to content

Latest commit

 

History

History
36 lines (21 loc) · 3.01 KB

core-http-ma-demo.md

File metadata and controls

36 lines (21 loc) · 3.01 KB

coreHTTP mutual authentication demo

Introduction

The coreHTTP (Mutual Authentication) demo project shows you how to establish a connection to an HTTP server using TLS with mutual authentication between the client and the server. This demo uses an mbedTLS-based transport interface implementation to establish a server- and client-authenticated TLS connection, and demonstrates a request response workflow in HTTP.

Note
To set up and run the FreeRTOS demos, follow the steps in Getting Started with FreeRTOS.

Functionality

This demo creates a single application task with examples that show how to complete the following:

  • Connect to the HTTP server on the AWS IoT endpoint.
  • Send a POST request.
  • Receive the response.
  • Disconnect from the server.

After you complete these steps, the demo generates output similar to the following screenshot.

[Image NOT FOUND]

The AWS IoT console generates output similar to the following screenshot.

[Image NOT FOUND]

Source code organization

The demo source file is named http_demo_mutual_auth.c and can be found in the freertos/demos/coreHTTP/ directory and on the GitHub website.

Connecting to the AWS IoT HTTP server

The connectToServerWithBackoffRetries function attempts to make a mutually authenticated TLS connection to the AWS IoT HTTP server. If the connection fails, it retries after a timeout. The timeout value exponentially increases until the maximum number of attempts is reached or the maximum timeout value is reached. The RetryUtils_BackoffAndSleep function provides exponentially increasing timeout values and returns RetryUtilsRetriesExhausted when the maximum number of attempts have been reached. The connectToServerWithBackoffRetries function returns a failure status if the TLS connection to the broker can't be established after the configured number of attempts.

Sending an HTTP request and receiving the response

The prvSendHttpRequest function demonstrates how to send a POST request to the AWS IoT HTTP server. For more information on making a request to the REST API in AWS IoT, see Device communication protocols - HTTPS. The response is received with the same coreHTTP API call, HTTPClient_Send.