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

Fix expectation and use of SocketsConfig_t::pAlpnProtos #3533

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion demos/common/mqtt_demo_helpers/mqtt_demo_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ static TransportSocketStatus_t prvConnectToServerWithBackoffRetries( NetworkCont
BaseType_t xBackoffStatus = pdPASS;
ServerInfo_t xServerInfo = { 0 };
SocketsConfig_t xSocketConfig = { 0 };
char * ppcAlpnProtocols[] = { socketsAWS_IOT_ALPN_MQTT };

/* Initialize information to connect to the MQTT broker. */
xServerInfo.pHostName = democonfigMQTT_BROKER_ENDPOINT;
Expand All @@ -435,7 +436,8 @@ static TransportSocketStatus_t prvConnectToServerWithBackoffRetries( NetworkCont
*/
if( xServerInfo.port == 443 )
{
xSocketConfig.pAlpnProtos = socketsAWS_IOT_ALPN_MQTT;
xSocketConfig.ppcAlpnProtos = ppcAlpnProtocols;
xSocketConfig.ulAlpnProtosCount = sizeof(ppcAlpnProtocols) / sizeof( char * );
}

xSocketConfig.maxFragmentLength = 0;
Expand Down
2 changes: 1 addition & 1 deletion demos/coreHTTP/http_demo_mutual_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ static BaseType_t prvConnectToServer( NetworkContext_t * pxNetworkContext )

/* Configure credentials for TLS mutual authenticated session. */
xSocketsConfig.enableTls = true;
xSocketsConfig.pAlpnProtos = NULL;
xSocketsConfig.ppcAlpnProtos = NULL;
xSocketsConfig.maxFragmentLength = 0;
xSocketsConfig.disableSni = false;
xSocketsConfig.pRootCa = democonfigROOT_CA_PEM;
Expand Down
2 changes: 1 addition & 1 deletion demos/coreHTTP/http_demo_s3_download.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ static BaseType_t prvConnectToServer( NetworkContext_t * pxNetworkContext )

/* Configure credentials for TLS server-authenticated session. */
xSocketsConfig.enableTls = true;
xSocketsConfig.pAlpnProtos = NULL;
xSocketsConfig.ppcAlpnProtos = NULL;
xSocketsConfig.maxFragmentLength = 0;
xSocketsConfig.disableSni = false;
xSocketsConfig.pRootCa = democonfigROOT_CA_PEM;
Expand Down
2 changes: 1 addition & 1 deletion demos/coreHTTP/http_demo_s3_download_multithreaded.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ static BaseType_t prvConnectToServer( NetworkContext_t * pxNetworkContext )

/* Configure credentials for TLS server-authenticated session. */
xSocketsConfig.enableTls = true;
xSocketsConfig.pAlpnProtos = NULL;
xSocketsConfig.ppcAlpnProtos = NULL;
xSocketsConfig.maxFragmentLength = 0;
xSocketsConfig.disableSni = false;
xSocketsConfig.pRootCa = democonfigROOT_CA_PEM;
Expand Down
2 changes: 1 addition & 1 deletion demos/coreHTTP/http_demo_s3_upload.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ static BaseType_t prvConnectToServer( NetworkContext_t * pxNetworkContext )

/* Configure credentials for TLS server-authenticated session. */
xSocketsConfig.enableTls = true;
xSocketsConfig.pAlpnProtos = NULL;
xSocketsConfig.ppcAlpnProtos = NULL;
xSocketsConfig.maxFragmentLength = 0;
xSocketsConfig.disableSni = false;
xSocketsConfig.pRootCa = democonfigROOT_CA_PEM;
Expand Down
2 changes: 1 addition & 1 deletion demos/coreMQTT/mqtt_demo_mutual_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ static BaseType_t prvConnectToServerWithBackoffRetries( NetworkContext_t * pxNet

/* Configure credentials for TLS mutual authenticated session. */
xSocketsConfig.enableTls = true;
xSocketsConfig.pAlpnProtos = NULL;
xSocketsConfig.ppcAlpnProtos = NULL;
xSocketsConfig.maxFragmentLength = 0;
xSocketsConfig.disableSni = false;
xSocketsConfig.pRootCa = democonfigROOT_CA_PEM;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ static BaseType_t prvConnectToServerWithBackoffRetries( GGD_HostAddressData_t *

/* Configure credentials for TLS mutual authenticated session. */
xSocketsConfig.enableTls = true;
xSocketsConfig.pAlpnProtos = NULL;
xSocketsConfig.ppcAlpnProtos = NULL;
xSocketsConfig.maxFragmentLength = 0;
xSocketsConfig.disableSni = false;
xSocketsConfig.pRootCa = pxHostAddressData->pcCertificate;
Expand Down
4 changes: 2 additions & 2 deletions demos/ota/ota_demo_core_http/ota_demo_core_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ static BaseType_t prvCreateSocketConnectionToMQTTBroker( NetworkContext_t * pxNe

/* Configure credentials for TLS mutual authenticated session. */
xSocketsConfig.enableTls = true;
xSocketsConfig.pAlpnProtos = NULL;
xSocketsConfig.ppcAlpnProtos = NULL;
xSocketsConfig.maxFragmentLength = 0;
xSocketsConfig.disableSni = false;
xSocketsConfig.pRootCa = democonfigROOT_CA_PEM;
Expand Down Expand Up @@ -1605,7 +1605,7 @@ static int32_t prvConnectToS3Server( NetworkContext_t * pxNetworkContext,

/* Configure credentials for TLS mutual authenticated session. */
xSocketsConfig.enableTls = true;
xSocketsConfig.pAlpnProtos = NULL;
xSocketsConfig.ppcAlpnProtos = NULL;
xSocketsConfig.maxFragmentLength = 0;
xSocketsConfig.disableSni = false;
xSocketsConfig.pRootCa = democonfigHTTPS_ROOT_CA_PEM;
Expand Down
2 changes: 1 addition & 1 deletion demos/ota/ota_demo_core_mqtt/ota_demo_core_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ static BaseType_t prvCreateSocketConnectionToMQTTBroker( NetworkContext_t * pxNe

/* Configure credentials for TLS mutual authenticated session. */
xSocketsConfig.enableTls = true;
xSocketsConfig.pAlpnProtos = NULL;
xSocketsConfig.ppcAlpnProtos = NULL;
xSocketsConfig.maxFragmentLength = 0;
xSocketsConfig.disableSni = false;
xSocketsConfig.pRootCa = democonfigROOT_CA_PEM;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,13 @@ static int32_t tlsSetup( const SocketsConfig_t * pSocketsConfig,
}

/* Set ALPN option. */
if( ( secureSocketStatus == SOCKETS_ERROR_NONE ) && ( pSocketsConfig->pAlpnProtos != NULL ) )
if( ( secureSocketStatus == SOCKETS_ERROR_NONE ) && ( pSocketsConfig->ppcAlpnProtos != NULL ) )
{
secureSocketStatus = SOCKETS_SetSockOpt( tcpSocket,
0,
SOCKETS_SO_ALPN_PROTOCOLS,
pSocketsConfig->pAlpnProtos,
sizeof( pSocketsConfig->pAlpnProtos ) );
pSocketsConfig->ppcAlpnProtos,
pSocketsConfig->ulAlpnProtosCount );

if( secureSocketStatus != ( int32_t ) SOCKETS_ERROR_NONE )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,14 @@ typedef struct SocketsConfig
uint32_t recvTimeoutMs; /**< @brief Timeout for transport recv. */

/**
* @brief Set this to a non-NULL value to use ALPN.
*
* This string must be NULL-terminated.
* @brief Set this to a non-NULL value to use ALPN as an array of char pointers ex. {"h2", "ftp" }
*
* See [this link]
* (https://aws.amazon.com/blogs/iot/mqtt-with-tls-client-authentication-on-port-443-why-it-is-useful-and-how-it-works/)
* for more information.
*/
const char * pAlpnProtos;
const char ** ppcAlpnProtos;
uint32_t ulAlpnProtosCount;

/**
* @brief Disable server name indication (SNI) for a TLS session.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

/* Configuration parameters for the TLS connection. */
#define MFLN ( 42 )
#define ALPN_PROTOS "x-amzn-mqtt-ca"
#define ALPN_PROTOS {"x-amzn-mqtt-ca"}

#define MOCK_ROOT_CA "mockRootCA"
#define MOCK_SERVER_ADDRESS ( 100 )
Expand Down Expand Up @@ -92,10 +92,12 @@ static ServerInfo_t serverInfo =
.hostNameLength = strlen( HOSTNAME ),
.port = PORT
};

static SocketsConfig_t socketsConfig =
{
.enableTls = true,
.pAlpnProtos = ALPN_PROTOS,
.ppcAlpnProtos = (char * [])ALPN_PROTOS,
.ulAlpnProtosCount = 0,
.maxFragmentLength = MFLN,
.disableSni = false,
.pRootCa = NULL,
Expand Down Expand Up @@ -262,7 +264,7 @@ void test_SecureSocketsTransport_Connect_Invalid_Credentials_AlpnProtos( void )
SocketsConfig_t localSocketsConfig =
{
.enableTls = true,
.pAlpnProtos = ALPN_PROTOS,
.ppcAlpnProtos = (char * [])ALPN_PROTOS,
.maxFragmentLength = MFLN,
.disableSni = false,
.pRootCa = NULL,
Expand Down Expand Up @@ -311,7 +313,7 @@ void test_SecureSocketsTransport_Connect_Invalid_Credentials_SNI( void )
SocketsConfig_t localSocketsConfig =
{
.enableTls = true,
.pAlpnProtos = NULL,
.ppcAlpnProtos = NULL,
.maxFragmentLength = MFLN,
.disableSni = false,
.pRootCa = NULL,
Expand Down Expand Up @@ -360,7 +362,7 @@ void test_SecureSocketsTransport_Connect_Invalid_Credentials_RootCA( void )
SocketsConfig_t localSocketsConfig =
{
.enableTls = true,
.pAlpnProtos = NULL,
.ppcAlpnProtos = NULL,
.maxFragmentLength = MFLN,
.disableSni = false,
.pRootCa = MOCK_ROOT_CA,
Expand Down Expand Up @@ -409,7 +411,7 @@ void test_SecureSocketsTransport_Connect_Dns_Failure( void )
SocketsConfig_t localSocketsConfig =
{
.enableTls = false,
.pAlpnProtos = NULL,
.ppcAlpnProtos = NULL,
.maxFragmentLength = MFLN,
.disableSni = false,
.pRootCa = NULL,
Expand Down Expand Up @@ -444,7 +446,7 @@ void test_SecureSocketsTransport_Connect_Fail_to_Connect( void )
SocketsConfig_t localSocketsConfig =
{
.enableTls = false,
.pAlpnProtos = NULL,
.ppcAlpnProtos = NULL,
.maxFragmentLength = MFLN,
.disableSni = false,
.pRootCa = NULL,
Expand Down Expand Up @@ -484,7 +486,7 @@ void test_SecureSocketsTransport_Connect_TimeOutSetup_Failure_Send( void )
SocketsConfig_t localSocketsConfig =
{
.enableTls = false,
.pAlpnProtos = NULL,
.ppcAlpnProtos = NULL,
.maxFragmentLength = MFLN,
.disableSni = false,
.pRootCa = NULL,
Expand Down Expand Up @@ -540,7 +542,7 @@ void test_SecureSocketsTransport_Connect_TimeOutSetup_Failure_Recv( void )
SocketsConfig_t localSocketsConfig =
{
.enableTls = false,
.pAlpnProtos = NULL,
.ppcAlpnProtos = NULL,
.maxFragmentLength = MFLN,
.disableSni = false,
.pRootCa = NULL,
Expand Down Expand Up @@ -587,7 +589,7 @@ void test_SecureSocketsTransport_Connect_Succeeds_without_TLS( void )
SocketsConfig_t localSocketsConfig =
{
.enableTls = false,
.pAlpnProtos = NULL,
.ppcAlpnProtos = NULL,
.maxFragmentLength = MFLN,
.disableSni = false,
.pRootCa = NULL,
Expand Down Expand Up @@ -641,7 +643,7 @@ void test_SecureSocketsTransport_Connect_Succeeds_Set_Timeout_Zero( void )
SocketsConfig_t localSocketsConfig =
{
.enableTls = false,
.pAlpnProtos = NULL,
.ppcAlpnProtos = NULL,
.maxFragmentLength = MFLN,
.disableSni = false,
.pRootCa = NULL,
Expand Down Expand Up @@ -694,7 +696,7 @@ void test_SecureSocketsTransport_Connect_Succeeds_with_TLS( void )
SocketsConfig_t localSocketsConfig =
{
.enableTls = true,
.pAlpnProtos = ALPN_PROTOS,
.ppcAlpnProtos = (char * [])LPN_PROTOS,
.maxFragmentLength = MFLN,
.disableSni = false,
.pRootCa = MOCK_ROOT_CA,
Expand Down Expand Up @@ -780,7 +782,7 @@ void test_SecureSocketsTransport_Connect_Credentials_NotSet( void )
SocketsConfig_t localSocketsConfig =
{
.enableTls = true,
.pAlpnProtos = NULL,
.ppcAlpnProtos = NULL,
.maxFragmentLength = MFLN,
.disableSni = false,
.pRootCa = NULL,
Expand Down
24 changes: 12 additions & 12 deletions tests/include/iot_config_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,23 +265,23 @@ typedef struct IotNetworkCredentials IotTestNetworkCredentials_t;
/* Define the credentials initializer based on the server port. Use ALPN if on
* 443, otherwise disable ALPN. */
#if clientcredentialMQTT_BROKER_PORT == 443
#define IOT_TEST_NETWORK_CREDENTIALS_INITIALIZER \
{ \
.disableSni = false, \
.pAlpnProtos = socketsAWS_IOT_ALPN_MQTT, \
.maxFragmentLength = 0, \
.pRootCa = NULL, \
.pClientCert = keyCLIENT_CERTIFICATE_PEM, \
.pPrivateKey = keyCLIENT_PRIVATE_KEY_PEM, \
.rootCaSize = 0, \
.clientCertSize = sizeof( keyCLIENT_CERTIFICATE_PEM ), \
.privateKeySize = sizeof( keyCLIENT_PRIVATE_KEY_PEM ) \
#define IOT_TEST_NETWORK_CREDENTIALS_INITIALIZER \
{ \
.disableSni = false, \
.ppcAlpnProtos = ( char *[] ) { socketsAWS_IOT_ALPN_MQTT }, \
.maxFragmentLength = 0, \
.pRootCa = NULL, \
.pClientCert = keyCLIENT_CERTIFICATE_PEM, \
.pPrivateKey = keyCLIENT_PRIVATE_KEY_PEM, \
.rootCaSize = 0, \
.clientCertSize = sizeof( keyCLIENT_CERTIFICATE_PEM ), \
.privateKeySize = sizeof( keyCLIENT_PRIVATE_KEY_PEM ) \
}
#else /* if clientcredentialMQTT_BROKER_PORT == 443 */
#define IOT_TEST_NETWORK_CREDENTIALS_INITIALIZER \
{ \
.disableSni = false, \
.pAlpnProtos = NULL, \
.ppcAlpnProtos = NULL, \
.pRootCa = NULL, \
.pClientCert = keyCLIENT_CERTIFICATE_PEM, \
.pPrivateKey = keyCLIENT_PRIVATE_KEY_PEM, \
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_test/core_http_system_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ static void connectToServerWithBackoffRetries( NetworkContext_t * pNetworkContex

/* Configure credentials for TLS server-authenticated session. */
socketsConfig.enableTls = true;
socketsConfig.pAlpnProtos = NULL;
socketsConfig.ppcAlpnProtos = NULL;
socketsConfig.maxFragmentLength = 0;
socketsConfig.disableSni = false;
socketsConfig.pRootCa = ROOT_CA_CERT;
Expand Down
3 changes: 2 additions & 1 deletion tests/integration_test/core_mqtt_system_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,8 @@ static bool connectToServerWithBackoffRetries( NetworkContext_t * pNetworkContex

/* Initialize SocketsConfig. */
socketsConfig.enableTls = true;
socketsConfig.pAlpnProtos = NULL;
socketsConfig.ppcAlpnProtos = NULL;
socketsConfig.ulAlpnProtosCount = 0;
socketsConfig.maxFragmentLength = 0;
#if ( testConfigDISABLE_SNI == 1 )
socketsConfig.disableSni = true;
Expand Down
3 changes: 2 additions & 1 deletion tests/integration_test/shadow_system_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,8 @@ static bool connectToServerWithBackoffRetries( NetworkContext_t * pNetworkContex

/* Initialize SocketsConfig. */
socketsConfig.enableTls = true;
socketsConfig.pAlpnProtos = NULL;
socketsConfig.ppcAlpnProtos = NULL;
socketsConfig.ulAlpnProtosCount = 0;
socketsConfig.maxFragmentLength = 0;
socketsConfig.disableSni = false;
socketsConfig.pRootCa = SERVER_ROOT_CA_CERT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
*
* @note Port 443 requires use of the ALPN TLS extension with the ALPN protocol
* name. Using ALPN with this demo would require additional changes, including
* setting the `pAlpnProtos` member of the `NetworkCredentials_t` struct before
* setting the `ppcAlpnProtos` member of the `NetworkCredentials_t` struct before
* forming the TLS connection. When using port 8883, ALPN is not required.
*
* #define democonfigMQTT_BROKER_PORT ( insert here. )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
*
* @note Port 443 requires use of the ALPN TLS extension with the ALPN protocol
* name. Using ALPN with this demo would require additional changes, including
* setting the `pAlpnProtos` member of the `NetworkCredentials_t` struct before
* setting the `ppcAlpnProtos` member of the `NetworkCredentials_t` struct before
* forming the TLS connection. When using port 8883, ALPN is not required.
*
* #define democonfigMQTT_BROKER_PORT ( insert here. )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
*
* @note Port 443 requires use of the ALPN TLS extension with the ALPN protocol
* name. Using ALPN with this demo would require additional changes, including
* setting the `pAlpnProtos` member of the `NetworkCredentials_t` struct before
* setting the `ppcAlpnProtos` member of the `NetworkCredentials_t` struct before
* forming the TLS connection. When using port 8883, ALPN is not required.
*
* #define democonfigMQTT_BROKER_PORT ( insert here. )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
*
* @note Port 443 requires use of the ALPN TLS extension with the ALPN protocol
* name. Using ALPN with this demo would require additional changes, including
* setting the `pAlpnProtos` member of the `NetworkCredentials_t` struct before
* setting the `ppcAlpnProtos` member of the `NetworkCredentials_t` struct before
* forming the TLS connection. When using port 8883, ALPN is not required.
*
* #define democonfigMQTT_BROKER_PORT ( insert here. )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
*
* @note Port 443 requires use of the ALPN TLS extension with the ALPN protocol
* name. Using ALPN with this demo would require additional changes, including
* setting the `pAlpnProtos` member of the `NetworkCredentials_t` struct before
* setting the `ppcAlpnProtos` member of the `NetworkCredentials_t` struct before
* forming the TLS connection. When using port 8883, ALPN is not required.
*
* #define democonfigMQTT_BROKER_PORT ( insert here. )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
*
* @note Port 443 requires use of the ALPN TLS extension with the ALPN protocol
* name. Using ALPN with this demo would require additional changes, including
* setting the `pAlpnProtos` member of the `NetworkCredentials_t` struct before
* setting the `ppcAlpnProtos` member of the `NetworkCredentials_t` struct before
* forming the TLS connection. When using port 8883, ALPN is not required.
*
* #define democonfigMQTT_BROKER_PORT ( insert here. )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
*
* @note Port 443 requires use of the ALPN TLS extension with the ALPN protocol
* name. Using ALPN with this demo would require additional changes, including
* setting the `pAlpnProtos` member of the `NetworkCredentials_t` struct before
* setting the `ppcAlpnProtos` member of the `NetworkCredentials_t` struct before
* forming the TLS connection. When using port 8883, ALPN is not required.
*
* #define democonfigMQTT_BROKER_PORT ( insert here. )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
*
* @note Port 443 requires use of the ALPN TLS extension with the ALPN protocol
* name. Using ALPN with this demo would require additional changes, including
* setting the `pAlpnProtos` member of the `NetworkCredentials_t` struct before
* setting the `ppcAlpnProtos` member of the `NetworkCredentials_t` struct before
* forming the TLS connection. When using port 8883, ALPN is not required.
*
* #define democonfigMQTT_BROKER_PORT ( insert here. )
Expand Down
Loading