Skip to content
Open
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
5 changes: 5 additions & 0 deletions platform/posix/transport/include/openssl_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ typedef struct OpensslCredentials
*/
const char * sniHostName;

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sniHostName == NULL should result in SNI being disabled rather than an explicit disableHostnameCheck.

* @brief If non-zero, don't compare hostname to server certificate subject.
*/
uint8_t disableHostnameCheck;

/**
* @brief Set the value for the TLS max fragment length (TLS MFLN)
*
Expand Down
13 changes: 8 additions & 5 deletions platform/posix/transport/src/openssl_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,15 @@ static OpensslStatus_t tlsHandshake( const ServerInfo_t * pServerInfo,
int32_t sslStatus = -1, verifyPeerCertStatus = X509_V_OK;

/* Validate the hostname against the server's certificate. */
sslStatus = SSL_set1_host( pOpensslParams->pSsl, pServerInfo->pHostName );

if( sslStatus != 1 )
if( pOpensslCredentials->disableHostnameCheck == 0U )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer that we add a separate connect() function which takes a sockaddr_in rather than a hostname.

This would encourage the use of SNI whenever possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I think just checking for pOpensslCredentials->sniHostName != NULL should be sufficient here.

{
LogError( ( "SSL_set1_host failed to set the hostname to validate." ) );
returnStatus = OPENSSL_API_ERROR;
sslStatus = SSL_set1_host( pOpensslParams->pSsl, pServerInfo->pHostName );

if( sslStatus != 1 )
{
LogError( ( "SSL_set1_host failed to set the hostname to validate." ) );
returnStatus = OPENSSL_API_ERROR;
}
}

/* Enable SSL peer verification. */
Expand Down