2022-07-26 13:03:48 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
|
|
|
*/
|
|
|
|
|
2023-05-18 15:12:23 +02:00
|
|
|
#include <inttypes.h>
|
2022-07-26 13:03:48 +02:00
|
|
|
#include <sched.h> /* IWYU pragma: keep */
|
|
|
|
#include <setjmp.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2023-04-06 13:18:04 +00:00
|
|
|
/*
|
|
|
|
* As a workaround, include an OpenSSL header file before including cmocka.h,
|
|
|
|
* because OpenSSL 3.1.0 uses __attribute__(malloc), conflicting with a
|
|
|
|
* redefined malloc in cmocka.h.
|
|
|
|
*/
|
|
|
|
#include <openssl/err.h>
|
|
|
|
|
2022-07-26 13:03:48 +02:00
|
|
|
#define UNIT_TESTING
|
|
|
|
#include <cmocka.h>
|
|
|
|
|
|
|
|
#include <isc/async.h>
|
2025-02-04 13:17:31 +01:00
|
|
|
#include <isc/lib.h>
|
2022-07-26 13:03:48 +02:00
|
|
|
#include <isc/loop.h>
|
|
|
|
#include <isc/nonce.h>
|
|
|
|
#include <isc/os.h>
|
|
|
|
#include <isc/quota.h>
|
|
|
|
#include <isc/refcount.h>
|
|
|
|
#include <isc/sockaddr.h>
|
|
|
|
#include <isc/thread.h>
|
|
|
|
#include <isc/util.h>
|
|
|
|
#include <isc/uv.h>
|
|
|
|
|
|
|
|
#include "uv_wrap.h"
|
|
|
|
#define KEEP_BEFORE
|
|
|
|
|
|
|
|
#include "netmgr_common.h"
|
|
|
|
|
|
|
|
#include <tests/isc.h>
|
|
|
|
|
|
|
|
static void
|
|
|
|
start_listening(uint32_t nworkers, isc_nm_accept_cb_t accept_cb,
|
|
|
|
isc_nm_recv_cb_t recv_cb) {
|
2022-11-08 16:43:01 +02:00
|
|
|
isc_result_t result = isc_nm_listenstreamdns(
|
2025-07-14 17:12:35 +02:00
|
|
|
nworkers, &tcp_listen_addr, recv_cb, NULL, accept_cb, NULL, 128,
|
|
|
|
NULL, tcp_listen_tlsctx, get_proxy_type(), &listen_sock);
|
2022-07-26 13:03:48 +02:00
|
|
|
assert_int_equal(result, ISC_R_SUCCESS);
|
|
|
|
|
2025-07-14 10:50:21 +02:00
|
|
|
isc_loop_teardown(isc_loop_main(), stop_listening, listen_sock);
|
2022-07-26 13:03:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2025-07-14 17:12:35 +02:00
|
|
|
tlsdns_connect(void) {
|
2023-05-09 15:13:05 +03:00
|
|
|
isc_nm_streamdnsconnect(
|
2025-07-14 17:12:35 +02:00
|
|
|
&tcp_connect_addr, &tcp_listen_addr, connect_connect_cb,
|
2024-12-17 15:52:18 +02:00
|
|
|
tlsdns_connect, T_CONNECT, tcp_connect_tlsctx, NULL,
|
2023-05-25 18:22:55 +03:00
|
|
|
tcp_tlsctx_client_sess_cache, get_proxy_type(), NULL);
|
2022-07-26 13:03:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ISC_LOOP_TEST_IMPL(tlsdns_noop) {
|
|
|
|
start_listening(ISC_NM_LISTEN_ONE, noop_accept_cb, noop_recv_cb);
|
|
|
|
|
|
|
|
connect_readcb = NULL;
|
|
|
|
isc_refcount_increment0(&active_cconnects);
|
2025-07-14 17:12:35 +02:00
|
|
|
isc_nm_streamdnsconnect(
|
|
|
|
&tcp_connect_addr, &tcp_listen_addr, connect_success_cb,
|
|
|
|
tlsdns_connect, T_CONNECT, tcp_connect_tlsctx, NULL,
|
|
|
|
tcp_tlsctx_client_sess_cache, get_proxy_type(), NULL);
|
2022-07-26 13:03:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ISC_LOOP_TEST_IMPL(tlsdns_noresponse) {
|
|
|
|
start_listening(ISC_NM_LISTEN_ALL, noop_accept_cb, noop_recv_cb);
|
|
|
|
|
|
|
|
isc_refcount_increment0(&active_cconnects);
|
2025-07-14 17:12:35 +02:00
|
|
|
isc_nm_streamdnsconnect(
|
|
|
|
&tcp_connect_addr, &tcp_listen_addr, connect_connect_cb,
|
|
|
|
tlsdns_connect, T_CONNECT, tcp_connect_tlsctx, NULL,
|
|
|
|
tcp_tlsctx_client_sess_cache, get_proxy_type(), NULL);
|
2022-07-26 13:03:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ISC_LOOP_TEST_IMPL(tlsdns_timeout_recovery) {
|
|
|
|
/*
|
|
|
|
* Accept connections but don't send responses, forcing client
|
|
|
|
* reads to time out.
|
|
|
|
*/
|
|
|
|
noanswer = true;
|
|
|
|
start_listening(ISC_NM_LISTEN_ONE, listen_accept_cb, listen_read_cb);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* timeout_retry_cb() will give up after five timeouts.
|
|
|
|
*/
|
|
|
|
connect_readcb = timeout_retry_cb;
|
2025-03-11 12:10:51 +00:00
|
|
|
|
2022-07-26 13:03:48 +02:00
|
|
|
isc_refcount_increment0(&active_cconnects);
|
2023-05-09 15:13:05 +03:00
|
|
|
isc_nm_streamdnsconnect(
|
2025-07-14 17:12:35 +02:00
|
|
|
&tcp_connect_addr, &tcp_listen_addr, connect_connect_cb,
|
|
|
|
tlsdns_connect, T_SOFT, tcp_connect_tlsctx, NULL,
|
|
|
|
tcp_tlsctx_client_sess_cache, get_proxy_type(), NULL);
|
2022-07-26 13:03:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ISC_LOOP_TEST_IMPL(tlsdns_recv_one) {
|
|
|
|
start_listening(ISC_NM_LISTEN_ONE, listen_accept_cb, listen_read_cb);
|
|
|
|
|
|
|
|
isc_refcount_increment0(&active_cconnects);
|
2025-07-14 17:12:35 +02:00
|
|
|
tlsdns_connect();
|
2022-07-26 13:03:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ISC_LOOP_TEST_IMPL(tlsdns_recv_two) {
|
|
|
|
start_listening(ISC_NM_LISTEN_ONE, listen_accept_cb, listen_read_cb);
|
|
|
|
|
|
|
|
isc_refcount_increment0(&active_cconnects);
|
2025-07-14 17:12:35 +02:00
|
|
|
tlsdns_connect();
|
2022-07-26 13:03:48 +02:00
|
|
|
|
|
|
|
isc_refcount_increment0(&active_cconnects);
|
2025-07-14 17:12:35 +02:00
|
|
|
tlsdns_connect();
|
2022-07-26 13:03:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ISC_LOOP_TEST_IMPL(tlsdns_recv_send) {
|
|
|
|
start_listening(ISC_NM_LISTEN_ALL, listen_accept_cb, listen_read_cb);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < workers; i++) {
|
2025-07-14 10:50:21 +02:00
|
|
|
isc_async_run(isc_loop_get(i), stream_recv_send_connect,
|
|
|
|
tlsdns_connect);
|
2022-07-26 13:03:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-09 20:49:38 +03:00
|
|
|
/* PROXY tests */
|
|
|
|
|
|
|
|
ISC_LOOP_TEST_IMPL(proxy_tlsdns_noop) { loop_test_tlsdns_noop(arg); }
|
|
|
|
|
|
|
|
ISC_LOOP_TEST_IMPL(proxy_tlsdns_noresponse) {
|
|
|
|
loop_test_tlsdns_noresponse(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
ISC_LOOP_TEST_IMPL(proxy_tlsdns_timeout_recovery) {
|
|
|
|
loop_test_tlsdns_timeout_recovery(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
ISC_LOOP_TEST_IMPL(proxy_tlsdns_recv_one) { loop_test_tlsdns_recv_one(arg); }
|
|
|
|
|
|
|
|
ISC_LOOP_TEST_IMPL(proxy_tlsdns_recv_two) { loop_test_tlsdns_recv_two(arg); }
|
|
|
|
|
|
|
|
ISC_LOOP_TEST_IMPL(proxy_tlsdns_recv_send) { loop_test_tlsdns_recv_send(arg); }
|
|
|
|
|
2023-06-21 18:35:42 +03:00
|
|
|
/* PROXY over TLS tests */
|
|
|
|
|
|
|
|
ISC_LOOP_TEST_IMPL(proxytls_tlsdns_noop) { loop_test_tlsdns_noop(arg); }
|
|
|
|
|
|
|
|
ISC_LOOP_TEST_IMPL(proxytls_tlsdns_noresponse) {
|
|
|
|
loop_test_tlsdns_noresponse(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
ISC_LOOP_TEST_IMPL(proxytls_tlsdns_timeout_recovery) {
|
|
|
|
loop_test_tlsdns_timeout_recovery(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
ISC_LOOP_TEST_IMPL(proxytls_tlsdns_recv_one) { loop_test_tlsdns_recv_one(arg); }
|
|
|
|
|
|
|
|
ISC_LOOP_TEST_IMPL(proxytls_tlsdns_recv_two) { loop_test_tlsdns_recv_two(arg); }
|
|
|
|
|
|
|
|
ISC_LOOP_TEST_IMPL(proxytls_tlsdns_recv_send) {
|
|
|
|
loop_test_tlsdns_recv_send(arg);
|
|
|
|
}
|
|
|
|
|
2022-07-26 13:03:48 +02:00
|
|
|
ISC_TEST_LIST_START
|
|
|
|
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(tlsdns_noop, stream_noop_setup, stream_noop_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(tlsdns_noresponse, stream_noresponse_setup,
|
|
|
|
stream_noresponse_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(tlsdns_timeout_recovery, stream_timeout_recovery_setup,
|
|
|
|
stream_timeout_recovery_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(tlsdns_recv_one, stream_recv_one_setup,
|
|
|
|
stream_recv_one_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(tlsdns_recv_two, stream_recv_two_setup,
|
|
|
|
stream_recv_two_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(tlsdns_recv_send, stream_recv_send_setup,
|
|
|
|
stream_recv_send_teardown)
|
|
|
|
|
|
|
|
/* FIXME: Re-add the noalpn tests */
|
|
|
|
|
2023-05-09 20:49:38 +03:00
|
|
|
/* PROXY */
|
|
|
|
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(proxy_tlsdns_noop, proxystream_noop_setup,
|
|
|
|
proxystream_noop_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(proxy_tlsdns_noresponse, proxystream_noresponse_setup,
|
|
|
|
proxystream_noresponse_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(proxy_tlsdns_timeout_recovery,
|
|
|
|
proxystream_timeout_recovery_setup,
|
|
|
|
proxystream_timeout_recovery_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(proxy_tlsdns_recv_one, proxystream_recv_one_setup,
|
|
|
|
proxystream_recv_one_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(proxy_tlsdns_recv_two, proxystream_recv_two_setup,
|
|
|
|
proxystream_recv_two_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(proxy_tlsdns_recv_send, proxystream_recv_send_setup,
|
|
|
|
proxystream_recv_send_teardown)
|
|
|
|
|
2023-06-21 18:35:42 +03:00
|
|
|
/* PROXY over TLS */
|
|
|
|
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(proxytls_tlsdns_noop, proxystreamtls_noop_setup,
|
|
|
|
proxystreamtls_noop_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(proxytls_tlsdns_noresponse,
|
|
|
|
proxystreamtls_noresponse_setup,
|
|
|
|
proxystreamtls_noresponse_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(proxytls_tlsdns_timeout_recovery,
|
|
|
|
proxystreamtls_timeout_recovery_setup,
|
|
|
|
proxystreamtls_timeout_recovery_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(proxytls_tlsdns_recv_one, proxystreamtls_recv_one_setup,
|
|
|
|
proxystreamtls_recv_one_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(proxytls_tlsdns_recv_two, proxystreamtls_recv_two_setup,
|
|
|
|
proxystreamtls_recv_two_teardown)
|
|
|
|
ISC_TEST_ENTRY_CUSTOM(proxytls_tlsdns_recv_send, proxystreamtls_recv_send_setup,
|
|
|
|
proxystreamtls_recv_send_teardown)
|
|
|
|
|
2022-07-26 13:03:48 +02:00
|
|
|
ISC_TEST_LIST_END
|
2022-10-11 12:03:17 +02:00
|
|
|
|
|
|
|
static int
|
2023-01-10 10:20:44 +01:00
|
|
|
tlsdns_setup(void **state ISC_ATTR_UNUSED) {
|
2022-10-26 15:41:30 +03:00
|
|
|
stream_port = TLSDNS_TEST_PORT;
|
2022-10-11 12:03:17 +02:00
|
|
|
|
2024-11-19 10:38:03 +01:00
|
|
|
return 0;
|
2022-10-11 12:03:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ISC_TEST_MAIN_CUSTOM(tlsdns_setup, NULL)
|