Skip to content

Commit

Permalink
vtls: deduplicate some DISABLE_PROXY ifdefs (continue curl#5735)
Browse files Browse the repository at this point in the history
- using SSL_HOST_NAME, SSL_HOST_DISPNAME, SSL_PINNED_PUB_KEY for other tls backend
- create SSL_HOST_PORT
  • Loading branch information
MAntoniak committed Apr 12, 2021
1 parent 0409c12 commit 9855155
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 111 deletions.
20 changes: 4 additions & 16 deletions lib/curl_sasl.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,8 @@ CURLcode Curl_sasl_start(struct SASL *sasl, struct Curl_easy *data,
size_t len = 0;
saslstate state1 = SASL_STOP;
saslstate state2 = SASL_FINAL;
#ifndef CURL_DISABLE_PROXY
const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
conn->host.name;
const long int port = SSL_IS_PROXY() ? conn->port : conn->remote_port;
#else
const char * const hostname = conn->host.name;
const long int port = conn->remote_port;
#endif
const char * const hostname = SSL_HOST_NAME();
const long int port = SSL_HOST_PORT();
#if defined(USE_KERBEROS5) || defined(USE_NTLM)
const char *service = data->set.str[STRING_SERVICE_NAME] ?
data->set.str[STRING_SERVICE_NAME] :
Expand Down Expand Up @@ -465,14 +459,8 @@ CURLcode Curl_sasl_continue(struct SASL *sasl, struct Curl_easy *data,
CURLcode result = CURLE_OK;
saslstate newstate = SASL_FINAL;
char *resp = NULL;
#ifndef CURL_DISABLE_PROXY
const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
conn->host.name;
const long int port = SSL_IS_PROXY() ? conn->port : conn->remote_port;
#else
const char * const hostname = conn->host.name;
const long int port = conn->remote_port;
#endif
const char * const hostname = SSL_HOST_NAME();
const long int port = SSL_HOST_PORT();
#if !defined(CURL_DISABLE_CRYPTO_AUTH)
char *chlg = NULL;
size_t chlglen = 0;
Expand Down
7 changes: 1 addition & 6 deletions lib/vtls/bearssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,7 @@ static CURLcode bearssl_connect_step1(struct Curl_easy *data,
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
struct ssl_backend_data *backend = connssl->backend;
const char * const ssl_cafile = SSL_CONN_CONFIG(CAfile);
#ifndef CURL_DISABLE_PROXY
const char *hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
conn->host.name;
#else
const char *hostname = conn->host.name;
#endif
const char * const hostname = SSL_HOST_NAME();
const bool verifypeer = SSL_CONN_CONFIG(verifypeer);
const bool verifyhost = SSL_CONN_CONFIG(verifyhost);
CURLcode ret;
Expand Down
6 changes: 2 additions & 4 deletions lib/vtls/gskit.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,7 @@ static CURLcode gskit_connect_step1(struct Curl_easy *data,
const char * const keyringlabel = SSL_SET_OPTION(primary.clientcert);
const long int ssl_version = SSL_CONN_CONFIG(version);
const bool verifypeer = SSL_CONN_CONFIG(verifypeer);
const char * const hostname = SSL_IS_PROXY()? conn->http_proxy.host.name:
conn->host.name;
const char * const hostname = SSL_HOST_NAME();
const char *sni;
unsigned int protoflags = 0;
Qso_OverlappedIO_t commarea;
Expand Down Expand Up @@ -1035,8 +1034,7 @@ static CURLcode gskit_connect_step3(struct Curl_easy *data,
}

/* Check pinned public key. */
ptr = SSL_IS_PROXY() ? data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY] :
data->set.str[STRING_SSL_PINNEDPUBLICKEY];
ptr = SSL_PINNED_PUB_KEY();
if(!result && ptr) {
curl_X509certificate x509;
curl_asn1Element *p;
Expand Down
3 changes: 1 addition & 2 deletions lib/vtls/gtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1178,8 +1178,7 @@ gtls_connect_step3(struct Curl_easy *data,
infof(data, "\t server certificate activation date OK\n");
}

ptr = SSL_IS_PROXY() ? data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY] :
data->set.str[STRING_SSL_PINNEDPUBLICKEY];
ptr = SSL_PINNED_PUB_KEY();
if(ptr) {
result = pkp_pin_peer_pubkey(data, x509_cert, ptr);
if(result != CURLE_OK) {
Expand Down
19 changes: 3 additions & 16 deletions lib/vtls/mbedtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,8 @@ mbed_connect_step1(struct Curl_easy *data, struct connectdata *conn,
const char * const ssl_capath = SSL_CONN_CONFIG(CApath);
char * const ssl_cert = SSL_SET_OPTION(primary.clientcert);
const char * const ssl_crlfile = SSL_SET_OPTION(CRLfile);
#ifndef CURL_DISABLE_PROXY
const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
conn->host.name;
const long int port = SSL_IS_PROXY() ? conn->port : conn->remote_port;
#else
const char * const hostname = conn->host.name;
const long int port = conn->remote_port;
#endif
const char * const hostname = SSL_HOST_NAME();
const long int port = SSL_HOST_PORT();
int ret = -1;
char errorbuf[128];
errorbuf[0] = 0;
Expand Down Expand Up @@ -549,14 +543,7 @@ mbed_connect_step2(struct Curl_easy *data, struct connectdata *conn,
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
struct ssl_backend_data *backend = connssl->backend;
const mbedtls_x509_crt *peercert;
#ifndef CURL_DISABLE_PROXY
const char * const pinnedpubkey = SSL_IS_PROXY() ?
data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY] :
data->set.str[STRING_SSL_PINNEDPUBLICKEY];
#else
const char * const pinnedpubkey =
data->set.str[STRING_SSL_PINNEDPUBLICKEY];
#endif
const char * const pinnedpubkey = SSL_PINNED_PUB_KEY();

conn->recv[sockindex] = mbed_recv;
conn->send[sockindex] = mbed_send;
Expand Down
3 changes: 1 addition & 2 deletions lib/vtls/mesalink.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ mesalink_connect_step1(struct Curl_easy *data,
#ifdef ENABLE_IPV6
struct in6_addr addr6;
#endif
const char *const hostname =
SSL_IS_PROXY() ? conn->http_proxy.host.name : conn->host.name;
const char * const hostname = SSL_HOST_NAME();
size_t hostname_len = strlen(hostname);

SSL_METHOD *req_method = NULL;
Expand Down
9 changes: 2 additions & 7 deletions lib/vtls/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3366,11 +3366,7 @@ static CURLcode ossl_connect_step2(struct Curl_easy *data,
*/
if(CURLE_SSL_CONNECT_ERROR == result && errdetail == 0) {
const char * const hostname = SSL_HOST_NAME();
#ifndef CURL_DISABLE_PROXY
const long int port = SSL_IS_PROXY() ? conn->port : conn->remote_port;
#else
const long int port = conn->remote_port;
#endif
const long int port = SSL_HOST_PORT();
char extramsg[80]="";
int sockerr = SOCKERRNO;
if(sockerr && detail == SSL_ERROR_SYSCALL)
Expand Down Expand Up @@ -3983,8 +3979,7 @@ static CURLcode servercert(struct Curl_easy *data,
/* when not strict, we don't bother about the verify cert problems */
result = CURLE_OK;

ptr = SSL_IS_PROXY() ? data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY] :
data->set.str[STRING_SSL_PINNEDPUBLICKEY];
ptr = SSL_PINNED_PUB_KEY();
if(!result && ptr) {
result = pkp_pin_peer_pubkey(data, backend->server_cert, ptr);
if(result)
Expand Down
29 changes: 8 additions & 21 deletions lib/vtls/schannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,12 +428,7 @@ schannel_connect_step1(struct Curl_easy *data, struct connectdata *conn,
#endif
TCHAR *host_name;
CURLcode result;
#ifndef CURL_DISABLE_PROXY
char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
conn->host.name;
#else
char * const hostname = conn->host.name;
#endif
char * const hostname = SSL_HOST_NAME();

DEBUGF(infof(data,
"schannel: SSL/TLS connection with %s port %hu (step 1/3)\n",
Expand Down Expand Up @@ -997,12 +992,7 @@ schannel_connect_step2(struct Curl_easy *data, struct connectdata *conn,
SECURITY_STATUS sspi_status = SEC_E_OK;
CURLcode result;
bool doread;
#ifndef CURL_DISABLE_PROXY
char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
conn->host.name;
#else
char * const hostname = conn->host.name;
#endif
char * const hostname = SSL_HOST_NAME();
const char *pubkey_ptr;

doread = (connssl->connecting_state != ssl_connect_2_writing) ? TRUE : FALSE;
Expand Down Expand Up @@ -1251,9 +1241,7 @@ schannel_connect_step2(struct Curl_easy *data, struct connectdata *conn,
DEBUGF(infof(data, "schannel: SSL/TLS handshake complete\n"));
}

pubkey_ptr = SSL_IS_PROXY() ?
data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY] :
data->set.str[STRING_SSL_PINNEDPUBLICKEY];
pubkey_ptr = SSL_PINNED_PUB_KEY();
if(pubkey_ptr) {
result = pkp_pin_peer_pubkey(data, conn, sockindex, pubkey_ptr);
if(result) {
Expand Down Expand Up @@ -1340,8 +1328,12 @@ schannel_connect_step3(struct Curl_easy *data, struct connectdata *conn,
CERT_CONTEXT *ccert_context = NULL;
bool isproxy = SSL_IS_PROXY();
#ifdef DEBUGBUILD
<<<<<<< HEAD
const char * const hostname = isproxy ? conn->http_proxy.host.name :
conn->host.name;
=======
const char * const hostname = SSL_HOST_NAME();
>>>>>>> 82695ae9f (vtls: deduplicate some DISABLE_PROXY ifdefs (continue #5735))
#endif
#ifdef HAS_ALPN
SecPkgContext_ApplicationProtocol alpn_result;
Expand Down Expand Up @@ -2128,12 +2120,7 @@ static int schannel_shutdown(struct Curl_easy *data, struct connectdata *conn,
* Shutting Down an Schannel Connection
*/
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
#ifndef CURL_DISABLE_PROXY
char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
conn->host.name;
#else
char * const hostname = conn->host.name;
#endif
char * const hostname = SSL_HOST_NAME();

DEBUGASSERT(data);

Expand Down
8 changes: 1 addition & 7 deletions lib/vtls/schannel_verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,7 @@ CURLcode Curl_verify_certificate(struct Curl_easy *data,
const CERT_CHAIN_CONTEXT *pChainContext = NULL;
HCERTCHAINENGINE cert_chain_engine = NULL;
HCERTSTORE trust_store = NULL;
#ifndef CURL_DISABLE_PROXY
const char * const conn_hostname = SSL_IS_PROXY() ?
conn->http_proxy.host.name :
conn->host.name;
#else
const char * const conn_hostname = conn->host.name;
#endif
const char * const conn_hostname = SSL_HOST_NAME();

sspi_status =
s_pSecFn->QueryContextAttributes(&BACKEND->ctxt->ctxt_handle,
Expand Down
12 changes: 6 additions & 6 deletions lib/vtls/sectransp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,7 @@ static CURLcode sectransp_connect_step1(struct Curl_easy *data,
const bool verifypeer = SSL_CONN_CONFIG(verifypeer);
char * const ssl_cert = SSL_SET_OPTION(primary.clientcert);
const struct curl_blob *ssl_cert_blob = SSL_SET_OPTION(primary.cert_blob);
<<<<<<< HEAD
#ifndef CURL_DISABLE_PROXY
bool isproxy = SSL_IS_PROXY();
const char * const hostname = isproxy ? conn->http_proxy.host.name :
Expand All @@ -1409,6 +1410,10 @@ static CURLcode sectransp_connect_step1(struct Curl_easy *data,
const char * const hostname = conn->host.name;
const long int port = conn->remote_port;
#endif
=======
const char * const hostname = SSL_HOST_NAME();
const long int port = SSL_HOST_PORT();
>>>>>>> 82695ae9f (vtls: deduplicate some DISABLE_PROXY ifdefs (continue #5735))
#ifdef ENABLE_IPV6
struct in6_addr addr;
#else
Expand Down Expand Up @@ -2389,12 +2394,7 @@ sectransp_connect_step2(struct Curl_easy *data, struct connectdata *conn,
OSStatus err;
SSLCipherSuite cipher;
SSLProtocol protocol = 0;
#ifndef CURL_DISABLE_PROXY
const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
conn->host.name;
#else
const char * const hostname = conn->host.name;
#endif
const char * const hostname = SSL_HOST_NAME();

DEBUGASSERT(ssl_connect_2 == connssl->connecting_state
|| ssl_connect_2_reading == connssl->connecting_state
Expand Down
3 changes: 3 additions & 0 deletions lib/vtls/vtls.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ bool Curl_ssl_tls13_ciphersuites(void);
(SSL_IS_PROXY() ? conn->http_proxy.host.name : conn->host.name)
#define SSL_HOST_DISPNAME() \
(SSL_IS_PROXY() ? conn->http_proxy.host.dispname : conn->host.dispname)
#define SSL_HOST_PORT() \
(SSL_IS_PROXY() ? conn->port : conn->remote_port)
#define SSL_PINNED_PUB_KEY() (SSL_IS_PROXY() \
? data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY] \
: data->set.str[STRING_SSL_PINNEDPUBLICKEY])
Expand All @@ -158,6 +160,7 @@ bool Curl_ssl_tls13_ciphersuites(void);
#define SSL_CONN_CONFIG(var) conn->ssl_config.var
#define SSL_HOST_NAME() conn->host.name
#define SSL_HOST_DISPNAME() conn->host.dispname
#define SSL_HOST_PORT() conn->remote_port
#define SSL_PINNED_PUB_KEY() \
data->set.str[STRING_SSL_PINNEDPUBLICKEY]
#endif
Expand Down
24 changes: 4 additions & 20 deletions lib/vtls/wolfssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,7 @@ wolfssl_connect_step1(struct Curl_easy *data, struct connectdata *conn,
#ifdef ENABLE_IPV6
struct in6_addr addr6;
#endif
#ifndef CURL_DISABLE_PROXY
const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
conn->host.name;
#else
const char * const hostname = conn->host.name;
#endif
const char * const hostname = SSL_HOST_NAME();
size_t hostname_len = strlen(hostname);
if((hostname_len < USHRT_MAX) &&
(0 == Curl_inet_pton(AF_INET, hostname, &addr4)) &&
Expand Down Expand Up @@ -552,20 +547,9 @@ wolfssl_connect_step2(struct Curl_easy *data, struct connectdata *conn,
int ret = -1;
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
struct ssl_backend_data *backend = connssl->backend;
#ifndef CURL_DISABLE_PROXY
const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
conn->host.name;
const char * const dispname = SSL_IS_PROXY() ?
conn->http_proxy.host.dispname : conn->host.dispname;
const char * const pinnedpubkey = SSL_IS_PROXY() ?
data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY] :
data->set.str[STRING_SSL_PINNEDPUBLICKEY];
#else
const char * const hostname = conn->host.name;
const char * const dispname = conn->host.dispname;
const char * const pinnedpubkey =
data->set.str[STRING_SSL_PINNEDPUBLICKEY];
#endif
const char * const hostname = SSL_HOST_NAME();
const char * const dispname = SSL_HOST_DISPNAME();
const char * const pinnedpubkey = SSL_PINNED_PUB_KEY();

conn->recv[sockindex] = wolfssl_recv;
conn->send[sockindex] = wolfssl_send;
Expand Down
6 changes: 2 additions & 4 deletions lib/x509asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -1145,10 +1145,8 @@ CURLcode Curl_verifyhost(struct Curl_easy *data, struct connectdata *conn,
int matched = -1;
size_t addrlen = (size_t) -1;
ssize_t len;
const char *const hostname = SSL_IS_PROXY()?
conn->http_proxy.host.name : conn->host.name;
const char *const dispname = SSL_IS_PROXY()?
conn->http_proxy.host.dispname : conn->host.dispname;
const char * const hostname = SSL_HOST_NAME();
const char * const dispname = SSL_HOST_DISPNAME();
#ifdef ENABLE_IPV6
struct in6_addr addr;
#else
Expand Down

0 comments on commit 9855155

Please sign in to comment.