From 1fae071b68b495189993e64466cd6135dd1eb20d Mon Sep 17 00:00:00 2001 From: Christian Spielberger Date: Sun, 11 Oct 2020 19:53:40 +0200 Subject: [PATCH] openssl: remove obsolete function tls_set_hostname() - Wrong pointer notation in first parameter (char * instead of char **). But the function can be removed for simplicity. - Renames also http_cli.tls_hostname to http_cli.tlshn which might be more libre conform naming style. --- include/re_tls.h | 1 - src/http/client.c | 16 ++++++++++------ src/tls/openssl/tls.c | 22 ---------------------- 3 files changed, 10 insertions(+), 29 deletions(-) diff --git a/include/re_tls.h b/include/re_tls.h index 87de9bcf3..83090f145 100644 --- a/include/re_tls.h +++ b/include/re_tls.h @@ -52,7 +52,6 @@ int tls_peer_fingerprint(const struct tls_conn *tc, enum tls_fingerprint type, int tls_peer_common_name(const struct tls_conn *tc, char *cn, size_t size); int tls_peer_set_verify_host(struct tls_conn *tc, const char *hostname); int tls_set_verify_purpose(struct tls *tls, const char *purpose); -int tls_set_hostname(char *tls_hostname, const struct pl *hostname); int tls_peer_verify(const struct tls_conn *tc); int tls_srtp_keyinfo(const struct tls_conn *tc, enum srtp_suite *suite, uint8_t *cli_key, size_t cli_key_size, diff --git a/src/http/client.c b/src/http/client.c index 6c37ffd5e..173dcb255 100644 --- a/src/http/client.c +++ b/src/http/client.c @@ -42,7 +42,7 @@ struct http_cli { struct hash *ht_conn; struct dnsc *dnsc; struct tls *tls; - char *tls_hostname; + char *tlshn; char *cert; char *key; struct sa laddr; @@ -113,7 +113,7 @@ static void cli_destructor(void *arg) mem_deref(cli->key); mem_deref(cli->dnsc); mem_deref(cli->tls); - mem_deref(cli->tls_hostname); + mem_deref(cli->tlshn); } @@ -472,9 +472,9 @@ static int conn_connect(struct http_req *req) if (err) goto out; - if (req->cli->tls_hostname) + if (req->cli->tlshn) err = tls_peer_set_verify_host(conn->sc, - req->cli->tls_hostname); + req->cli->tlshn); if (err) goto out; @@ -945,10 +945,14 @@ int http_client_set_keypem(struct http_cli *cli, const char *pem) int http_client_set_tls_hostname(struct http_cli *cli, const struct pl *hostname) { - if (!cli || !hostname) + if (!cli) return EINVAL; - return tls_set_hostname(cli->tls_hostname, hostname); + cli->tlshn = mem_deref(cli->tlshn); + if (!hostname) + return 0; + + return pl_strdup(&cli->tlshn, hostname); } #endif diff --git a/src/tls/openssl/tls.c b/src/tls/openssl/tls.c index ca7ba9e26..f3ca1be71 100644 --- a/src/tls/openssl/tls.c +++ b/src/tls/openssl/tls.c @@ -333,28 +333,6 @@ int tls_peer_set_verify_host(struct tls_conn *tc, const char *hostname) } -/** - * Convert string hostname to pl hostname - * - * @param tls_hostname Certificate hostname as string - * @param hostname Certificate hostname as pl - * - * @return int 0 if success, errorcode otherwise - */ -int tls_set_hostname(char *tls_hostname, const struct pl *hostname) -{ - if (!tls_hostname || !hostname) - return EINVAL; - -#if OPENSSL_VERSION_NUMBER < 0x10100000L - DEBUG_WARNING("verify hostname needs openssl version 1.1.0\n"); - return ENOSYS; -#endif - - return pl_strdup(&tls_hostname, hostname); -} - - /** * Generate and set selfsigned certificate on TLS context *