]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_http_websocket.c: Set hostname on client for certificate validation.
authorSean Bright <sean@seanbright.com>
Thu, 9 Nov 2023 22:59:19 +0000 (17:59 -0500)
committerAsterisk Development Team <asteriskteam@digium.com>
Fri, 12 Jan 2024 18:32:13 +0000 (18:32 +0000)
Additionally add a `assert()` to in the TLS client setup code to
ensure that hostname is set when it is supposed to be.

Fixes #433

(cherry picked from commit 40a9f5a88c96bfcfac28a7eb210a562f2490fe3d)

main/tcptls.c
res/res_http_websocket.c

index e51e70ef0d7cd43656a24c6600b8f3aa5adc376e..73a165726c17c86b2833a214e187a627ad451ba9 100644 (file)
@@ -680,6 +680,10 @@ struct ast_tcptls_session_instance *ast_tcptls_client_create(struct ast_tcptls_s
        int fd, x = 1;
        struct ast_tcptls_session_instance *tcptls_session = NULL;
 
+       ast_assert(!desc->tls_cfg
+                       || ast_test_flag(&desc->tls_cfg->flags, AST_SSL_DONT_VERIFY_SERVER)
+                       || !ast_strlen_zero(desc->hostname));
+
        /* Do nothing if nothing has changed */
        if (!ast_sockaddr_cmp(&desc->old_address, &desc->remote_address)) {
                ast_debug(1, "Nothing changed in %s\n", desc->name);
index f8da4878284fcd22bfac2c2af08ad1e5ed1ae75a..0339c7982328c4d15596df12593237f0806ac91c 100644 (file)
@@ -1163,6 +1163,12 @@ static struct ast_tcptls_session_args *websocket_client_args_create(
        }
        ast_sockaddr_copy(&args->remote_address, addr);
        ast_free(addr);
+
+       /* We need to save off the hostname but it may contain a port spec */
+       snprintf(args->hostname, sizeof(args->hostname),
+               "%.*s",
+               (int) strcspn(host, ":"), host);
+
        return args;
 }