Skip to content

Commit

Permalink
CMP app and app_http_tls_cb(): pick the right TLS hostname (also with…
Browse files Browse the repository at this point in the history
…out port)

Fixes #20031

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from #20034)

(cherry picked from commit 30b9a6e)
  • Loading branch information
DDvO authored and hlandau committed May 10, 2023
1 parent 259c7f6 commit 6ce19b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apps/cmp.c
Expand Up @@ -1956,7 +1956,7 @@ static int setup_client_ctx(OSSL_CMP_CTX *ctx, ENGINE *engine)
if ((info = OPENSSL_zalloc(sizeof(*info))) == NULL)
goto err;
(void)OSSL_CMP_CTX_set_http_cb_arg(ctx, info);
info->server = opt_server;
info->server = host;
info->port = server_port;
/* workaround for callback design flaw, see #17088: */
info->use_proxy = proxy_host != NULL;
Expand Down
8 changes: 6 additions & 2 deletions apps/lib/apps.c
Expand Up @@ -2474,6 +2474,10 @@ BIO *app_http_tls_cb(BIO *bio, void *arg, int connect, int detail)
if (connect) {
SSL *ssl;
BIO *sbio = NULL;
X509_STORE *ts = SSL_CTX_get_cert_store(ssl_ctx);
X509_VERIFY_PARAM *vpm = X509_STORE_get0_param(ts);
const char *host = vpm == NULL ? NULL :
X509_VERIFY_PARAM_get0_host(vpm, 0 /* first hostname */);

/* adapt after fixing callback design flaw, see #17088 */
if ((info->use_proxy
Expand All @@ -2488,8 +2492,8 @@ BIO *app_http_tls_cb(BIO *bio, void *arg, int connect, int detail)
return NULL;
}

/* adapt after fixing callback design flaw, see #17088 */
SSL_set_tlsext_host_name(ssl, info->server); /* not critical to do */
if (vpm != NULL)
SSL_set_tlsext_host_name(ssl, host /* may be NULL */);

SSL_set_connect_state(ssl);
BIO_set_ssl(sbio, ssl, BIO_CLOSE);
Expand Down

0 comments on commit 6ce19b7

Please sign in to comment.