Skip to content
Open
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
22 changes: 17 additions & 5 deletions port/posix/posix_transport_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ static int NonBlockingError(int err)
(err == WOLFSSL_ERROR_WANT_WRITE);
}

/* Load certificates and keys from config structure into SSL context */
/* Load certificates and keys from config structure into SSL context.
* is_server indicates the SSL context is for a server endpoint, which
* affects how peer verification is enforced. */
static int LoadTlsCertificates(WOLFSSL_CTX* ssl_ctx,
const posixTransportTlsConfig* cfg)
const posixTransportTlsConfig* cfg,
bool is_server)
{
int rc;

Expand Down Expand Up @@ -94,10 +97,19 @@ static int LoadTlsCertificates(WOLFSSL_CTX* ssl_ctx,
}
}

/* Set verification mode */
/* Set verification mode. For a server, WOLFSSL_VERIFY_PEER alone causes
* wolfSSL to request a client certificate but still accept the handshake
* if the client presents none, so OR in WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT
* to require mutual authentication when peer verification is enabled. */
if (cfg->disable_peer_verification) {
wolfSSL_CTX_set_verify(ssl_ctx, WOLFSSL_VERIFY_NONE, NULL);
}
else if (is_server) {
wolfSSL_CTX_set_verify(ssl_ctx,
WOLFSSL_VERIFY_PEER |
WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT,
NULL);
Comment on lines +107 to +111
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

disable_peer_verification already exists for this, and the intent of the change is to ensure peer validation is performed when that is not set.

}
else {
wolfSSL_CTX_set_verify(ssl_ctx, WOLFSSL_VERIFY_PEER, NULL);
}
Expand Down Expand Up @@ -144,7 +156,7 @@ int posixTransportTls_InitConnect(void* context, const void* config,
wolfSSL_CTX_SetDevId(ctx->ssl_ctx, INVALID_DEVID);

/* Load certificates from config structure */
rc = LoadTlsCertificates(ctx->ssl_ctx, cfg);
rc = LoadTlsCertificates(ctx->ssl_ctx, cfg, false /* is_server */);
if (rc != WH_ERROR_OK) {
wolfSSL_CTX_free(ctx->ssl_ctx);
ctx->ssl_ctx = NULL;
Expand Down Expand Up @@ -412,7 +424,7 @@ int posixTransportTls_InitListen(void* context, const void* config,
wolfSSL_CTX_SetDevId(ctx->ssl_ctx, INVALID_DEVID);

/* Load certificates from config structure */
rc = LoadTlsCertificates(ctx->ssl_ctx, cfg);
rc = LoadTlsCertificates(ctx->ssl_ctx, cfg, true /* is_server */);
if (rc != WH_ERROR_OK) {
wolfSSL_CTX_free(ctx->ssl_ctx);
ctx->ssl_ctx = NULL;
Expand Down
Loading