Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
Modify iot_tls.c to allow for basic TLS connections. (#2984)
Browse files Browse the repository at this point in the history
* Allow for TLS basic connections by squashing PKCS #11 errors when looking for client credentials.
* Improved error message.
* Added changelog snippet.
* Add comment to describe the reason behind the change necessary for basic TLS.

Co-authored-by: Archit Aggarwal <architag@amazon.com>
  • Loading branch information
lundinc2 and aggarw13 authored Feb 11, 2021
1 parent 8c0daaa commit deee8ce
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ This repository contains the `FreeRTOS AWS Reference Integrations`, which are pr
- Update FreeRTOS Test Runner to support either a configurable delay (in [PR](https://github.com/aws/amazon-freertos/pull/2950)) or a FreeRTOS+CLI based serial prompt input command (in [PR](https://github.com/aws/amazon-freertos/pull/2955)) to being executing tests.
- Upgrade of ESP-IDF SDK v4.2 for Espressif boards (in [PR](https://github.com/aws/amazon-freertos/pull/2893)). Refer to the instructions in [Getting Started Guide](https://docs.aws.amazon.com/freertos/latest/userguide/getting_started_espressif.html#setup-espressif-idf42) for using ESP-IDF v4.2.

#### TLS Shim Layer V1.3.0

- Added logic to support connecting to a TLS server that does not require mutual verification.


## 202012.00 December 2020

### New Features
Expand Down Expand Up @@ -256,7 +261,7 @@ The MQTT library in this release, coreMQTT, supports backward compatibility with
#### FreeRTOS+TCP V2.3.0

- Added ability to cache multiple IP addresses per DNS entry.
- Defensive security improvements:
- Defensive security improvements:
- In compliance with the UDP protocol specification, prior versions of FreeRTOS+TCP accepted UDP packets that had their checksum set to 0. FreeRTOS+TCP V2.3.0 adds a new configuration parameter, `ipconfigUDP_PASS_ZERO_CHECKSUM_PACKETS`, that enables users to opt to drop UDP packets that have their checksum set to 0. **Note:** This new setting defaults to 0, so it defaults to dropping UDP packets that have their checksum set to 0.
- Prior versions of FreeRTOS+TCP accept IP packets that contain IP options, although those options are not processed. FreeRTOS+TCP V2.3.0 adds a new configuration parameter, `ipconfigIP_PASS_PACKETS_WITH_IP_OPTIONS`, that enables users to opt to drop IP packets that contain IP options.
- Setting configuration parameter, `ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM`, to 1 offloads IP checksum and length checking to the hardware. From FreeRTOS+TCP V2.3.0, the length is checked in software even when it has already been checked in hardware.
Expand Down
34 changes: 29 additions & 5 deletions libraries/freertos_plus/standard/tls/src/iot_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ BaseType_t TLS_Init( void ** ppvContext,
BaseType_t TLS_Connect( void * pvContext )
{
BaseType_t xResult = 0;
CK_RV xPKCSResult = CKR_OK;
TLSContext_t * pxCtx = ( TLSContext_t * ) pvContext; /*lint !e9087 !e9079 Allow casting void* to other types. */

/* Initialize mbedTLS structures. */
Expand Down Expand Up @@ -879,8 +880,15 @@ BaseType_t TLS_Connect( void * pvContext )
/* Set issuer certificate. */
mbedtls_ssl_conf_ca_chain( &pxCtx->xMbedSslConfig, &pxCtx->xMbedX509CA, NULL );

/* Configure the SSL context for the device credentials. */
xResult = prvInitializeClientCredential( pxCtx );
/* Configure the SSL context to contain device credentials (eg device cert
* and private key) obtained from the PKCS #11 layer. The result of
* loading device key and certificate is placed in a separate variable
* (xPKCSResult instead of xResult). The reason is that we want to
* attempt TLS handshake, even if the device key and certificate
* are not loaded. This allows the TLS layer to still connect to servers
* that do not require mutual authentication. If the server does
* require mutual authentication, the handshake will fail. */
xPKCSResult = prvInitializeClientCredential( pxCtx );
}

if( ( 0 == xResult ) && ( NULL != pxCtx->ppcAlpnProtocols ) )
Expand Down Expand Up @@ -943,9 +951,25 @@ BaseType_t TLS_Connect( void * pvContext )
* ensure that upstream clean-up code doesn't accidentally use
* a context that failed the handshake. */
prvFreeContext( pxCtx );
TLS_PRINT( ( "ERROR: Handshake failed with error code %s : %s \r\n",
mbedtlsHighLevelCodeOrDefault( xResult ),
mbedtlsLowLevelCodeOrDefault( xResult ) ) );

if( xPKCSResult != CKR_OK )
{
TLS_PRINT( ( "ERROR: The handshake failed and it is likely "
"due to a failure in PKCS #11. Consider enabling "
"error logging in PKCS #11 or checking if your device "
"is properly provisioned with client credentials. "
"PKCS #11 error=0x(%0X). TLS handshake error=%s : %s \r\n",
xPKCSResult,
mbedtlsHighLevelCodeOrDefault( xResult ),
mbedtlsLowLevelCodeOrDefault( xResult ) ) );
}
else
{
TLS_PRINT( ( "ERROR: TLS handshake failed trying to connect. %s : %s \r\n",
mbedtlsHighLevelCodeOrDefault( xResult ),
mbedtlsLowLevelCodeOrDefault( xResult ) ) );
}

break;
}
}
Expand Down

0 comments on commit deee8ce

Please sign in to comment.