Skip to content

Commit 0f810df

Browse files
committed
Use additional OpensslCredentials_t parameter for hostname checking.
This will allow demos to disable hostname checking, allowing them to be used with Greengrass or other endpoints that do not have the hostname in their certificate subject.
1 parent 0b7db36 commit 0f810df

File tree

14 files changed

+33
-2
lines changed

14 files changed

+33
-2
lines changed

demos/defender/defender_demo_json/mqtt_operations.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ static bool connectToBrokerWithBackoffRetries( NetworkContext_t * pNetworkContex
370370
opensslCredentials.pClientCertPath = CLIENT_CERT_PATH;
371371
opensslCredentials.pPrivateKeyPath = CLIENT_PRIVATE_KEY_PATH;
372372
opensslCredentials.sniHostName = AWS_IOT_ENDPOINT;
373+
opensslCredentials.certHostName = AWS_IOT_ENDPOINT;
373374

374375
if( AWS_MQTT_PORT == 443 )
375376
{

demos/http/http_demo_basic_tls/http_demo_basic_tls.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ static int32_t connectToServer( NetworkContext_t * pNetworkContext )
234234
( void ) memset( &opensslCredentials, 0, sizeof( opensslCredentials ) );
235235
opensslCredentials.pRootCaPath = ROOT_CA_CERT_PATH;
236236
opensslCredentials.sniHostName = SERVER_HOST;
237+
opensslCredentials.certHostName = SERVER_HOST;
237238

238239
/* Initialize server information. */
239240
serverInfo.pHostName = SERVER_HOST;

demos/http/http_demo_mutual_auth/http_demo_mutual_auth.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ static int32_t connectToServer( NetworkContext_t * pNetworkContext )
181181
opensslCredentials.pPrivateKeyPath = CLIENT_PRIVATE_KEY_PATH;
182182
opensslCredentials.pRootCaPath = ROOT_CA_CERT_PATH;
183183
opensslCredentials.sniHostName = AWS_IOT_ENDPOINT;
184+
opensslCredentials.certHostName = AWS_IOT_ENDPOINT;
184185

185186
/* ALPN is required when communicating to AWS IoT Core over port 443 through HTTP. */
186187
if( AWS_HTTPS_PORT == 443 )

demos/http/http_demo_s3_download/http_demo_s3_download.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ static int32_t connectToIotServer( NetworkContext_t * pNetworkContext )
891891
/* Initialize TLS credentials. */
892892
opensslCredentials.pRootCaPath = ROOT_CA_CERT_PATH;
893893
opensslCredentials.sniHostName = serverHost;
894+
opensslCredentials.certHostName = serverHost;
894895
opensslCredentials.pClientCertPath = CLIENT_CERT_PATH;
895896
opensslCredentials.pPrivateKeyPath = CLIENT_PRIVATE_KEY_PATH;
896897

@@ -944,6 +945,7 @@ static int32_t connectToS3Server( NetworkContext_t * pNetworkContext )
944945
/* Initialize TLS credentials. */
945946
opensslCredentials.pRootCaPath = ROOT_CA_CERT_PATH;
946947
opensslCredentials.sniHostName = serverHost;
948+
opensslCredentials.certHostName = serverHost;
947949

948950
/* Initialize server information. */
949951
serverInfo.pHostName = serverHost;

demos/http/http_demo_s3_download_multithreaded/http_demo_s3_download_multithreaded.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ static int connectToServer( NetworkContext_t * pNetworkContext )
340340
/* Initialize TLS credentials. */
341341
opensslCredentials.pRootCaPath = ROOT_CA_CERT_PATH;
342342
opensslCredentials.sniHostName = serverHost;
343+
opensslCredentials.certHostName = serverHost;
343344

344345
/* serverHost should consist only of the host address located in S3_PRESIGNED_GET_URL. */
345346
memcpy( serverHost, pHost, hostLen );

demos/http/http_demo_s3_upload/http_demo_s3_upload.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ static int32_t connectToServer( NetworkContext_t * pNetworkContext )
285285
/* Initialize TLS credentials. */
286286
opensslCredentials.pRootCaPath = ROOT_CA_CERT_PATH;
287287
opensslCredentials.sniHostName = serverHost;
288+
opensslCredentials.certHostName = serverHost;
288289

289290
/* Initialize server information. */
290291
serverInfo.pHostName = serverHost;

demos/mqtt/mqtt_demo_basic_tls/mqtt_demo_basic_tls.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ static int connectToServerWithBackoffRetries( NetworkContext_t * pNetworkContext
480480
memset( &opensslCredentials, 0, sizeof( OpensslCredentials_t ) );
481481
opensslCredentials.pRootCaPath = ROOT_CA_CERT_PATH;
482482
opensslCredentials.sniHostName = BROKER_ENDPOINT;
483+
opensslCredentials.certHostName = BROKER_ENDPOINT;
483484

484485
/* Initialize reconnect attempts and interval */
485486
BackoffAlgorithm_InitializeParams( &reconnectParams,

demos/mqtt/mqtt_demo_mutual_auth/mqtt_demo_mutual_auth.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,9 @@ static int connectToServerWithBackoffRetries( NetworkContext_t * pNetworkContext
603603
* https://docs.aws.amazon.com/iot/latest/developerguide/transport-security.html */
604604
opensslCredentials.sniHostName = AWS_IOT_ENDPOINT;
605605

606+
/* Check that the server certificate matches the hostname */
607+
opensslCredentials.certHostName = AWS_IOT_ENDPOINT;
608+
606609
if( AWS_MQTT_PORT == 443 )
607610
{
608611
/* Pass the ALPN protocol name depending on the port being used.

demos/mqtt/mqtt_demo_subscription_manager/mqtt_demo_subscription_manager.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ static int connectToServerWithBackoffRetries( NetworkContext_t * pNetworkContext
542542
memset( &opensslCredentials, 0, sizeof( OpensslCredentials_t ) );
543543
opensslCredentials.pRootCaPath = ROOT_CA_CERT_PATH;
544544
opensslCredentials.sniHostName = BROKER_ENDPOINT;
545+
opensslCredentials.certHostName = BROKER_ENDPOINT;
545546

546547
/* Seed pseudo random number generator used in the demo for
547548
* backoff period calculation when retrying failed network operations

demos/ota/ota_demo_core_http/ota_demo_core_http.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,9 @@ static int connectToServerWithBackoffRetries( NetworkContext_t * pNetworkContext
10761076
* https://docs.aws.amazon.com/iot/latest/developerguide/transport-security.html */
10771077
opensslCredentials.sniHostName = AWS_IOT_ENDPOINT;
10781078

1079+
/* Check that the server certificate matches the hostname */
1080+
opensslCredentials.certHostName = AWS_IOT_ENDPOINT;
1081+
10791082
if( AWS_MQTT_PORT == 443 )
10801083
{
10811084
/* Pass the ALPN protocol name depending on the port being used.
@@ -1371,6 +1374,7 @@ static int32_t connectToS3Server( NetworkContext_t * pNetworkContext,
13711374
serverInfo.pHostName = serverHost;
13721375
serverInfo.hostNameLength = serverHostLength;
13731376
serverInfo.port = AWS_HTTPS_PORT;
1377+
opensslCredentials.certHostName = serverHost;
13741378

13751379
/* Establish a TLS session with the HTTP server. This example connects
13761380
* to the HTTP server as specified in SERVER_HOST and HTTPS_PORT in

0 commit comments

Comments
 (0)