Update unused headers and NULL checks for platform wrappers (#367)

- Remove unused headers in the plaintext FreeRTOS sockets wrapper
- Update MFLN even though the preceding optional configuration returned an mbedTLS error
- Remove an unused `NULL` check in a private method that is already checked by the public connect method
- Add a `NULL` check to the public disconnect method

Co-authored-by: Joseph Julicher <jjulicher@mac.com>
pull/366/head^2
Oscar Michael Abrina 4 years ago committed by GitHub
parent ca9dcdad7f
commit 559772a4db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -24,8 +24,6 @@
/* FreeRTOS includes. */ /* FreeRTOS includes. */
#include "FreeRTOS.h" #include "FreeRTOS.h"
#include "atomic.h"
#include "semphr.h"
/* FreeRTOS+TCP includes. */ /* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h" #include "FreeRTOS_IP.h"

@ -328,12 +328,9 @@ static int32_t setCredentials( SSLContext_t * pSslContext,
mbedtls_ssl_conf_cert_profile( &( pSslContext->config ), mbedtls_ssl_conf_cert_profile( &( pSslContext->config ),
&( pSslContext->certProfile ) ); &( pSslContext->certProfile ) );
if( pNetworkCredentials->pRootCa != NULL )
{
mbedtlsError = setRootCa( pSslContext, mbedtlsError = setRootCa( pSslContext,
pNetworkCredentials->pRootCa, pNetworkCredentials->pRootCa,
pNetworkCredentials->rootCaSize ); pNetworkCredentials->rootCaSize );
}
if( ( pNetworkCredentials->pClientCert != NULL ) && if( ( pNetworkCredentials->pClientCert != NULL ) &&
( pNetworkCredentials->pPrivateKey != NULL ) ) ( pNetworkCredentials->pPrivateKey != NULL ) )
@ -405,8 +402,7 @@ static void setOptionalConfigurations( SSLContext_t * pSslContext,
/* Set Maximum Fragment Length if enabled. */ /* Set Maximum Fragment Length if enabled. */
#ifdef MBEDTLS_SSL_MAX_FRAGMENT_LENGTH #ifdef MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
if( 0 == mbedtlsError )
{
/* Enable the max fragment extension. 4096 bytes is currently the largest fragment size permitted. /* Enable the max fragment extension. 4096 bytes is currently the largest fragment size permitted.
* See RFC 8449 https://tools.ietf.org/html/rfc8449 for more information. * See RFC 8449 https://tools.ietf.org/html/rfc8449 for more information.
* *
@ -420,9 +416,7 @@ static void setOptionalConfigurations( SSLContext_t * pSslContext,
mbedtlsHighLevelCodeOrDefault( mbedtlsError ), mbedtlsHighLevelCodeOrDefault( mbedtlsError ),
mbedtlsLowLevelCodeOrDefault( mbedtlsError ) ) ); mbedtlsLowLevelCodeOrDefault( mbedtlsError ) ) );
} }
} #endif /* ifdef MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
#endif
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -671,15 +665,17 @@ TlsTransportStatus_t TLS_FreeRTOS_Connect( NetworkContext_t * pNetworkContext,
/* Clean up on failure. */ /* Clean up on failure. */
if( returnStatus != TLS_TRANSPORT_SUCCESS ) if( returnStatus != TLS_TRANSPORT_SUCCESS )
{
if( pNetworkContext != NULL )
{ {
sslContextFree( &( pNetworkContext->sslContext ) ); sslContextFree( &( pNetworkContext->sslContext ) );
if( ( pNetworkContext != NULL ) && if( pNetworkContext->tcpSocket != FREERTOS_INVALID_SOCKET )
( pNetworkContext->tcpSocket != FREERTOS_INVALID_SOCKET ) )
{ {
( void ) FreeRTOS_closesocket( pNetworkContext->tcpSocket ); ( void ) FreeRTOS_closesocket( pNetworkContext->tcpSocket );
} }
} }
}
else else
{ {
LogInfo( ( "(Network connection %p) Connection to %s established.", LogInfo( ( "(Network connection %p) Connection to %s established.",
@ -695,6 +691,8 @@ void TLS_FreeRTOS_Disconnect( NetworkContext_t * pNetworkContext )
{ {
BaseType_t tlsStatus = 0; BaseType_t tlsStatus = 0;
if( pNetworkContext != NULL )
{
/* Attempting to terminate TLS connection. */ /* Attempting to terminate TLS connection. */
tlsStatus = ( BaseType_t ) mbedtls_ssl_close_notify( &( pNetworkContext->sslContext.context ) ); tlsStatus = ( BaseType_t ) mbedtls_ssl_close_notify( &( pNetworkContext->sslContext.context ) );
@ -729,6 +727,7 @@ void TLS_FreeRTOS_Disconnect( NetworkContext_t * pNetworkContext )
/* Free mbed TLS contexts. */ /* Free mbed TLS contexts. */
sslContextFree( &( pNetworkContext->sslContext ) ); sslContextFree( &( pNetworkContext->sslContext ) );
}
/* Clear the mutex functions for mbed TLS thread safety. */ /* Clear the mutex functions for mbed TLS thread safety. */
mbedtls_threading_free_alt(); mbedtls_threading_free_alt();

@ -412,7 +412,7 @@ static TlsTransportStatus_t tlsSetup( NetworkContext_t * pNetworkContext,
returnStatus = TLS_TRANSPORT_INTERNAL_ERROR; returnStatus = TLS_TRANSPORT_INTERNAL_ERROR;
} }
} }
#endif #endif /* ifdef MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
if( returnStatus == TLS_TRANSPORT_SUCCESS ) if( returnStatus == TLS_TRANSPORT_SUCCESS )
{ {
@ -853,6 +853,8 @@ void TLS_FreeRTOS_Disconnect( NetworkContext_t * pNetworkContext )
{ {
BaseType_t tlsStatus = 0; BaseType_t tlsStatus = 0;
if( pNetworkContext != NULL )
{
/* Attempting to terminate TLS connection. */ /* Attempting to terminate TLS connection. */
tlsStatus = ( BaseType_t ) mbedtls_ssl_close_notify( &( pNetworkContext->sslContext.context ) ); tlsStatus = ( BaseType_t ) mbedtls_ssl_close_notify( &( pNetworkContext->sslContext.context ) );
@ -887,6 +889,7 @@ void TLS_FreeRTOS_Disconnect( NetworkContext_t * pNetworkContext )
/* Free mbed TLS contexts. */ /* Free mbed TLS contexts. */
sslContextFree( &( pNetworkContext->sslContext ) ); sslContextFree( &( pNetworkContext->sslContext ) );
}
/* Clear the mutex functions for mbed TLS thread safety. */ /* Clear the mutex functions for mbed TLS thread safety. */
mbedtls_threading_free_alt(); mbedtls_threading_free_alt();

Loading…
Cancel
Save