28#include <gmock/gmock.h>
36#if !defined(USE_TLS_AUTH) && !defined(USE_TLS_CRYPT)
39#define USE_TLS_CRYPT_V2
47#define PROTO_CIPHER "BF-CBC"
48#define TLS_VER_MIN TLSVersion::UNDEF
49#define HANDSHAKE_WINDOW 60
50#define BECOME_PRIMARY_CLIENT 5
51#define BECOME_PRIMARY_SERVER 5
52#define TLS_TIMEOUT_CLIENT 1000
53#define TLS_TIMEOUT_SERVER 1000
56#define PROTO_CIPHER "BF-CBC"
57#define TLS_VER_MIN TLSVersion::UNDEF
58#define HANDSHAKE_WINDOW 10
59#define BECOME_PRIMARY_CLIENT 10
60#define BECOME_PRIMARY_SERVER 10
61#define TLS_TIMEOUT_CLIENT 2000
62#define TLS_TIMEOUT_SERVER 1000
65#define PROTO_CIPHER "BF-CBC"
66#define TLS_VER_MIN TLSVersion::UNDEF
67#define HANDSHAKE_WINDOW 60
68#define BECOME_PRIMARY_CLIENT 60
69#define BECOME_PRIMARY_SERVER 10
70#define TLS_TIMEOUT_CLIENT 2000
71#define TLS_TIMEOUT_SERVER 1000
74#error unknown BF value
78#ifndef TLS_TIMEOUT_CLIENT
79#define TLS_TIMEOUT_CLIENT 2000
81#ifndef TLS_TIMEOUT_SERVER
82#define TLS_TIMEOUT_SERVER 2000
88#define SIMULATE_DROPPED
89#define SIMULATE_CORRUPTED
94#define RENEG PROTO_RENEG
108#define ITER PROTO_ITER
115#define SITER PROTO_SITER
131#if !defined(PROTO_VERBOSE) && !defined(QUIET) && ITER <= 10000
135#define STRINGIZE1(x) #x
136#define STRINGIZE(x) STRINGIZE1(x)
141#define PROTO_CIPHER "AES-256-GCM"
142#define TLS_VER_MIN TLSVersion::Type::V1_2
144#define PROTO_CIPHER "AES-128-CBC"
145#define TLS_VER_MIN TLSVersion::Type::UNDEF
151#define PROTO_DIGEST "SHA1"
157#define COMP_METH CompressContext::LZ4v2
159#define COMP_METH CompressContext::COMP_STUBv2
162#define COMP_METH CompressContext::LZO_STUB
176#if defined(USE_MBEDTLS_APPLE_HYBRID)
180#if !(defined(USE_OPENSSL) || defined(USE_MBEDTLS) || defined(USE_APPLE_SSL))
181#error Must define one or more of USE_OPENSSL, USE_MBEDTLS, USE_APPLE_SSL.
184#if defined(USE_OPENSSL) && (defined(USE_MBEDTLS) || defined(USE_APPLE_SSL))
186#define USE_OPENSSL_SERVER
187#elif !defined(USE_OPENSSL) && defined(USE_MBEDTLS)
188#define USE_MBEDTLS_SERVER
189#elif defined(USE_OPENSSL) && !defined(USE_MBEDTLS)
190#define USE_OPENSSL_SERVER
192#error no server setup
195#if defined(USE_OPENSSL) || defined(USE_OPENSSL_SERVER)
204#if defined(USE_APPLE_SSL) || defined(USE_MBEDTLS_APPLE_HYBRID)
210#if defined(USE_MBEDTLS) || defined(USE_MBEDTLS_SERVER)
214#include <mbedtls/debug.h>
222#if defined(USE_MBEDTLS_SERVER)
226#elif defined(USE_OPENSSL_SERVER)
231#error No server SSL implementation defined
235#if defined(USE_MBEDTLS)
236#if defined(USE_MBEDTLS_APPLE_HYBRID)
243#elif defined(USE_APPLE_SSL)
247#elif defined(USE_OPENSSL)
252#error No client SSL implementation defined
255const char message[] =
"Message _->_ 0000000000 It was a bright cold day in April, and the clocks\n"
256 "were striking thirteen. Winston Smith, his chin nuzzled\n"
257 "into his breast in an effort to escape the vile wind,\n"
258 "slipped quickly through the glass doors of Victory\n"
259 "Mansions, though not quickly enough to prevent a\n"
260 "swirl of gritty dust from entering along with him.\n"
262 "It was a bright cold day in April, and the clocks\n"
263 "were striking thirteen. Winston Smith, his chin nuzzled\n"
264 "into his breast in an effort to escape the vile wind,\n"
265 "slipped quickly through the glass doors of Victory\n"
266 "Mansions, though not quickly enough to prevent a\n"
267 "swirl of gritty dust from entering along with him.\n"
268 "It was a bright cold day in April, and the clocks\n"
269 "were striking thirteen. Winston Smith, his chin nuzzled\n"
270 "into his breast in an effort to escape the vile wind,\n"
271 "slipped quickly through the glass doors of Victory\n"
272 "Mansions, though not quickly enough to prevent a\n"
273 "swirl of gritty dust from entering along with him.\n"
274 "It was a bright cold day in April, and the clocks\n"
275 "were striking thirteen. Winston Smith, his chin nuzzled\n"
276 "into his breast in an effort to escape the vile wind,\n"
277 "slipped quickly through the glass doors of Victory\n"
278 "Mansions, though not quickly enough to prevent a\n"
279 "swirl of gritty dust from entering along with him.\n"
280 "It was a bright cold day in April, and the clocks\n"
281 "were striking thirteen. Winston Smith, his chin nuzzled\n"
282 "into his breast in an effort to escape the vile wind,\n"
283 "slipped quickly through the glass doors of Victory\n"
284 "Mansions, though not quickly enough to prevent a\n"
285 "swirl of gritty dust from entering along with him.\n"
310#if defined(VERBOSE) || defined(DROUGHT_LIMIT)
314 std::cout <<
"*** Drought " <<
name <<
" has reached " << r << std::endl;
317 if (r > DROUGHT_LIMIT)
318 throw drought_limit_exceeded();
376 const size_t msglen = std::strlen(
msg) + 1;
386 const size_t msglen = std::strlen(
msg) + 1;
394 if (
bool(iteration++ & 1) == is_server())
432 bp->write((
unsigned char *)
str, std::strlen(
str));
515 if (
work->size() >= 23)
520 const ssize_t trunc = 64;
521 const std::string show((
char *)
work->data(), trunc);
522 std::cout << now().raw() <<
" " << mode().str() <<
" " << show << std::endl;
541 char *
msg = (
char *)buf->data();
554 for (
int i = 22; i >= 13; i--)
574 size_t iteration = 0;
594 const std::string username(
"foo");
595 const std::string password(
"bar");
622 const std::string &peer_info,
626 std::cout <<
"**** AUTHENTICATE " << username <<
'/' << password <<
" PEER INFO:" << std::endl;
627 std::cout << peer_info;
629 if (username !=
"foo" || password !=
"bar")
642 const unsigned int reorder_prob_arg,
643 const unsigned int drop_prob_arg,
644 const unsigned int corrupt_prob_arg)
656 template <
typename T1,
typename T2>
660 a.check_invalidated();
661 b.check_invalidated();
664 if (a.do_housekeeping())
667 std::cout << now->raw() <<
" " <<
title <<
" Housekeeping" << std::endl;
675 if (a.proto_context.data_channel_ready())
677 BufferPtr bp = a.data_encrypt_string(
"Waiting for godot A... Waiting for godot B... Waiting for godot C... Waiting for godot D... Waiting for godot E... Waiting for godot F... Waiting for godot G... Waiting for godot H... Waiting for godot I... Waiting for godot J...");
682 while (!a.net_out.empty())
686 std::cout << now->raw() <<
" " <<
title <<
" " << a.dump_packet(*bp) << std::endl;
688 a.net_out.pop_front();
702 if (!b.control_net_validate(pt, *bp))
703 std::cout << now->raw() <<
" " <<
title <<
" CONTROL PACKET VALIDATION FAILED" << std::endl;
705 b.proto_context.control_net_recv(pt, std::move(bp));
711 b.data_decrypt(pt, *bp);
715 const std::string show((
char *)bp->data(), std::min(bp->size(),
size_t(40)));
716 std::cout << now->raw() <<
" " <<
title <<
" DATA CHANNEL DECRYPT: " << show << std::endl;
720 catch ([[maybe_unused]]
const std::exception &e)
723 std::cout << now->raw() <<
" " <<
title <<
" Exception on data channel decrypt: " << e.what() << std::endl;
730 std::cout << now->raw() <<
" " <<
title <<
" KEY_STATE_ERROR" << std::endl;
735#ifdef SIMULATE_UDP_AMPLIFY_ATTACK
736 if (b.proto_context.is_state_client_wait_reset_ack())
740 std::cout << now->raw() <<
" " <<
title <<
" SIMULATE_UDP_AMPLIFY_ATTACK disable client xmit" << std::endl;
745 b.proto_context.flush(
true);
757 std::cout << now->raw() <<
" " <<
title <<
" Simulating packet reordering " << i <<
" -> 0" << std::endl;
769 std::cout << now->raw() <<
" " <<
title <<
" Received packet, size=" << bp->size() << std::endl;
772#ifdef SIMULATE_DROPPED
777 std::cout << now->raw() <<
" " <<
title <<
" Simulating a dropped packet" << std::endl;
783#ifdef SIMULATE_CORRUPTED
788 std::cout << now->raw() <<
" " <<
title <<
" Simulating a corrupted packet" << std::endl;
791 const unsigned char value =
random.
randrange(std::numeric_limits<unsigned char>::max());
801 unsigned int rand(
const unsigned int prob)
830 void error(
const size_t err_type,
const std::string *text =
nullptr)
override
850 std::cerr <<
Error::name(i) <<
" : " << c << std::endl;
864 const std::string client_crt =
read_text(TEST_KEYCERT_DIR
"client.crt");
865 const std::string client_key =
read_text(TEST_KEYCERT_DIR
"client.key");
866 const std::string ca_crt =
read_text(TEST_KEYCERT_DIR
"ca.crt");
869 ClientSSLAPI::Config::Ptr cc(
new ClientSSLAPI::Config());
871 cc->set_frame(frame);
874 cc->load_identity(
"etest");
876 cc->load_ca(ca_crt,
true);
877 cc->load_cert(client_crt);
878 cc->load_private_key(client_key);
880 if (tls_version_mismatch)
881 cc->set_tls_version_max(TLSVersion::Type::V1_2);
885 cc->set_debug_level(1);
893 const std::string tls_auth_key =
read_text(TEST_KEYCERT_DIR
"tls-auth.key");
894 const std::string tls_crypt_v2_client_key = tls_crypt_v2_key_fn.empty()
895 ?
read_text(TEST_KEYCERT_DIR
"tls-crypt-v2-client.key")
896 :
read_text(TEST_KEYCERT_DIR + tls_crypt_v2_key_fn);
900 ClientProtoContext::ProtoConfig::Ptr cp(
new ClientProtoContext::ProtoConfig);
901 cp->ssl_factory = cc->new_factory();
902 CryptoAlgs::allow_default_dc_algs<ClientCryptoAPI>(cp->ssl_factory->libctx(),
false,
false);
905 cp->frame = std::move(frame);
912 cp->enable_op32 =
true;
913 cp->remote_peer_id = 100;
921 cp->tls_auth_key.parse(tls_auth_key);
923 cp->key_direction = 0;
927 cp->tls_crypt_key.parse(tls_auth_key);
928 cp->set_tls_crypt_algs();
929 cp->tls_crypt_ = ProtoContext::ProtoConfig::TLSCrypt::V1;
931#ifdef USE_TLS_CRYPT_V2
933 cp->set_tls_crypt_algs();
936 tls_crypt_v2_key.
parse(tls_crypt_v2_client_key);
940 cp->tls_crypt_ = ProtoContext::ProtoConfig::TLSCrypt::V2;
942#if defined(HANDSHAKE_WINDOW)
943 cp->handshake_window = Time::Duration::seconds(HANDSHAKE_WINDOW);
945 cp->handshake_window = Time::Duration::seconds(30);
947 cp->handshake_window = Time::Duration::seconds(18);
949#ifdef BECOME_PRIMARY_CLIENT
950 cp->become_primary = Time::Duration::seconds(BECOME_PRIMARY_CLIENT);
952 cp->become_primary = cp->handshake_window;
955#if defined(CLIENT_NO_RENEG)
958 cp->renegotiate = Time::Duration::seconds(
RENEG);
960 cp->expire = cp->renegotiate + cp->renegotiate;
961 cp->keepalive_ping = Time::Duration::seconds(5);
962 cp->keepalive_timeout = Time::Duration::seconds(60);
963 cp->keepalive_timeout_early = cp->keepalive_timeout;
966 std::cout <<
"CLIENT OPTIONS: " << cp->options_string() << std::endl;
967 std::cout <<
"CLIENT PEER INFO:" << std::endl;
968 std::cout << cp->peer_info_string();
976 bool tls_version_mismatch,
977 const std::string &tls_crypt_v2_key_fn =
"",
978 bool use_tls_auth_with_tls_crypt_v2 =
false)
986 ClientRandomAPI::Ptr prng_cli(
new ClientRandomAPI());
987 ServerRandomAPI::Ptr prng_serv(
new ServerRandomAPI());
992 const Time::Duration time_step = Time::Duration::binary_ms(100);
995 const std::string ca_crt =
read_text(TEST_KEYCERT_DIR
"ca.crt");
996 const std::string server_crt =
read_text(TEST_KEYCERT_DIR
"server.crt");
997 const std::string server_key =
read_text(TEST_KEYCERT_DIR
"server.key");
998 const std::string dh_pem =
read_text(TEST_KEYCERT_DIR
"dh.pem");
999 const std::string tls_auth_key =
read_text(TEST_KEYCERT_DIR
"tls-auth.key");
1000 const std::string tls_crypt_v2_server_key = tls_crypt_v2_key_fn.empty()
1001 ?
read_text(TEST_KEYCERT_DIR
"tls-crypt-v2-server.key")
1010 cp->dc.set_key_derivation(CryptoAlgs::KeyDerivation::TLS_EKM);
1015 ServerSSLAPI::Config::Ptr sc(
new ClientSSLAPI::Config());
1017 sc->set_frame(frame);
1018 sc->set_rng(prng_serv);
1019 sc->load_ca(ca_crt,
true);
1020 sc->load_cert(server_crt);
1021 sc->load_private_key(server_key);
1022 sc->load_dh(dh_pem);
1023 sc->set_tls_version_min(tls_version_mismatch ? TLSVersion::Type::V1_3 :
TLS_VER_MIN);
1025 sc->set_debug_level(1);
1030 ServerProtoContext::ProtoConfig::Ptr sp(
new ServerProtoContext::ProtoConfig);
1031 sp->ssl_factory = sc->new_factory();
1036 sp->rng = prng_serv;
1037 sp->prng = prng_serv;
1041 sp->enable_op32 =
true;
1042 sp->remote_peer_id = 101;
1048 sp->dc.set_key_derivation(CryptoAlgs::KeyDerivation::TLS_EKM);
1051 sp->tls_auth_key.parse(tls_auth_key);
1053 sp->key_direction = 1;
1055#if defined(USE_TLS_CRYPT)
1057 sp->tls_crypt_key.parse(tls_auth_key);
1058 sp->set_tls_crypt_algs();
1059 cp->tls_crypt_ = ProtoContext::ProtoConfig::TLSCrypt::V1;
1061#ifdef USE_TLS_CRYPT_V2
1064 if (tls_crypt_v2_key_fn.empty())
1067 tls_crypt_v2_key.
parse(tls_crypt_v2_server_key);
1071 sp->set_tls_crypt_algs();
1073 sp->tls_crypt_ = ProtoContext::ProtoConfig::TLSCrypt::V2;
1074 sp->tls_crypt_v2_serverkey_id = !tls_crypt_v2_key_fn.empty();
1075 sp->tls_crypt_v2_serverkey_dir = TEST_KEYCERT_DIR;
1077 if (use_tls_auth_with_tls_crypt_v2)
1080 sp->tls_auth_key.parse(tls_auth_key);
1082 sp->key_direction = 1;
1085#if defined(HANDSHAKE_WINDOW)
1086 sp->handshake_window = Time::Duration::seconds(HANDSHAKE_WINDOW);
1088 sp->handshake_window = Time::Duration::seconds(30);
1090 sp->handshake_window = Time::Duration::seconds(17) + Time::Duration::binary_ms(512);
1092#ifdef BECOME_PRIMARY_SERVER
1093 sp->become_primary = Time::Duration::seconds(BECOME_PRIMARY_SERVER);
1095 sp->become_primary = sp->handshake_window;
1098#if defined(SERVER_NO_RENEG)
1107 sp->renegotiate = Time::Duration::seconds(
RENEG) + sp->handshake_window;
1109 sp->expire = sp->renegotiate + sp->renegotiate;
1110 sp->keepalive_ping = Time::Duration::seconds(5);
1111 sp->keepalive_timeout = Time::Duration::seconds(60);
1112 sp->keepalive_timeout_early = Time::Duration::seconds(10);
1115 std::cout <<
"SERVER OPTIONS: " << sp->options_string() << std::endl;
1116 std::cout <<
"SERVER PEER INFO:" << std::endl;
1117 std::cout << sp->peer_info_string();
1123 for (
int i = 0; i <
SITER; ++i)
1126 std::cout <<
"***** SITER " << i << std::endl;
1131 NoisyWire client_to_server(
"Client -> Server", &time, rng_noncrypto, 8, 16, 32);
1132 NoisyWire server_to_client(
"Server -> Client", &time, rng_noncrypto, 8, 16, 32);
1147 for (j = 0; j <
ITER; ++j)
1149 client_to_server.
xfer(cli_proto, serv_proto);
1150 server_to_client.
xfer(serv_proto, cli_proto);
1154 catch (
const std::exception &e)
1156 std::cerr <<
"Exception[" << i <<
'/' << j <<
"]: " << e.what() << std::endl;
1168 std::cerr <<
"*** app bytes=" << ab
1169 <<
" net_bytes=" << nb
1170 <<
" data_bytes=" << db
1182 std::cerr <<
"-------- CLIENT STATS --------" << std::endl;
1184 std::cerr <<
"-------- SERVER STATS --------" << std::endl;
1187#ifdef OPENVPN_MAX_DATALIMIT_BYTES
1188 std::cerr <<
"------------------------------" << std::endl;
1189 std::cerr <<
"MAX_DATALIMIT_BYTES=" << DataLimit::max_bytes() << std::endl;
1192 catch (
const std::exception &e)
1194 std::cerr <<
"Exception: " << e.what() << std::endl;
1201 const int n_retries,
1203 bool tls_version_mismatch =
false,
1204 const std::string &tls_crypt_v2_key_fn =
"",
1205 bool use_tls_auth_with_tls_crypt_v2 =
false)
1208 for (
int i = 0; i < n_retries; ++i)
1210 ret =
test(thread_num, use_tls_ekm, tls_version_mismatch, tls_crypt_v2_key_fn, use_tls_auth_with_tls_crypt_v2);
1213 std::cout <<
"Retry " << (i + 1) <<
'/' << n_retries << std::endl;
1215 std::cout <<
"Failed" << std::endl;
1224#if defined(USE_MBEDTLS)
1225 mbedtls_debug_set_threshold(1);
1240#if defined(USE_MBEDTLS)
1241 mbedtls_debug_set_threshold(4);
1250 if (!openvpn::SSLLib::SSLAPI::support_key_material_export())
1251 GTEST_SKIP_(
"our mbed TLS implementation does not support TLS EKM");
1275 int ret =
test(1,
false,
true);
1280#ifdef USE_TLS_CRYPT_V2
1289 int ret =
test(1,
false,
false,
"tls-crypt-v2-client-with-missing-serverkey.key");
1302 unsigned int num_threads = std::thread::hardware_concurrency();
1303#if defined(PROTO_N_THREADS) && PROTO_N_THREADS >= 1
1304 num_threads = PROTO_N_THREADS;
1307 std::vector<std::thread> running_threads{};
1308 std::vector<int> results(num_threads, -777);
1310 for (
unsigned int i = 0; i < num_threads; ++i)
1312 running_threads.emplace_back([i, &results]()
1315 const bool use_ekm = openvpn::SSLLib::SSLAPI::support_key_material_export() && (i % 2 == 0);
1318 for (
unsigned int i = 0; i < num_threads; ++i)
1320 running_threads[i].join();
1325 const std::vector<int> expected_results(num_threads, 0);
1327 EXPECT_THAT(expected_results, ::testing::ContainerEq(results));
1332 CryptoAlgs::allow_default_dc_algs<SSLLib::CryptoAPI>(
nullptr,
true,
false);
1336 auto infostring = protoConf.peer_info_string(
false);
1338 auto ivciphers = infostring.substr(infostring.find(
"IV_CIPHERS="));
1339 ivciphers = ivciphers.substr(0, ivciphers.find(
"\n"));
1342 std::string expectedstr{
"IV_CIPHERS=AES-128-GCM:AES-192-GCM:AES-256-GCM"};
1344 expectedstr +=
":CHACHA20-POLY1305";
1346 EXPECT_EQ(ivciphers, expectedstr);
1349TEST(proto, iv_ciphers_non_preferred)
1351 CryptoAlgs::allow_default_dc_algs<SSLLib::CryptoAPI>(
nullptr,
false,
false);
1355 auto infostring = protoConf.peer_info_string(
true);
1357 auto ivciphers = infostring.substr(infostring.find(
"IV_CIPHERS="));
1358 ivciphers = ivciphers.substr(0, ivciphers.find(
"\n"));
1361 std::string expectedstr{
"IV_CIPHERS=AES-128-CBC:AES-192-CBC:AES-256-CBC:AES-128-GCM:AES-192-GCM:AES-256-GCM"};
1363 expectedstr +=
":CHACHA20-POLY1305";
1365 EXPECT_EQ(ivciphers, expectedstr);
1372 SSLLib::SSLAPI::Config::Ptr
config =
new SSLLib::SSLAPI::Config;
1380 config->set_local_cert_enabled(
false);
1381 config->enable_legacy_algorithms(
true);
1383 auto factory_client =
config->new_factory();
1384 EXPECT_TRUE(factory_client);
1386 auto client = factory_client->ssl();
1387 auto libctx = factory_client->libctx();
1390 CryptoAlgs::allow_default_dc_algs<SSLLib::CryptoAPI>(libctx,
false,
true);
1394 auto infostring = protoConf.peer_info_string(
false);
1396 auto ivciphers = infostring.substr(infostring.find(
"IV_CIPHERS="));
1397 ivciphers = ivciphers.substr(0, ivciphers.find(
"\n"));
1401 std::string expectedstr{
"IV_CIPHERS=none:AES-128-CBC:AES-192-CBC:AES-256-CBC:DES-CBC:DES-EDE3-CBC"};
1404 expectedstr +=
":BF-CBC";
1406 expectedstr +=
":AES-128-GCM:AES-192-GCM:AES-256-GCM";
1409 expectedstr +=
":CHACHA20-POLY1305";
1411 EXPECT_EQ(ivciphers, expectedstr);
1414TEST(proto, controlmessage_invalidchar)
1416 std::string valid_auth_fail{
"AUTH_FAILED: go away"};
1417 std::string valid_auth_fail_newline_end{
"AUTH_FAILED: go away\n"};
1418 std::string invalid_auth_fail{
"AUTH_FAILED: go\n away\n"};
1419 std::string lot_of_whitespace{
"AUTH_FAILED: a lot of white space\n\n\r\n\r\n\r\n"};
1420 std::string only_whitespace{
"\n\n\r\n\r\n\r\n"};
1421 std::string empty{
""};
1430 auto msg = ProtoContext::read_control_string<std::string>(valid_auth_fail_buf);
1431 EXPECT_EQ(
msg, valid_auth_fail);
1434 auto msg2 = ProtoContext::read_control_string<std::string>(valid_auth_fail_newline_end_buf);
1435 EXPECT_EQ(msg2, valid_auth_fail);
1438 auto msg3 = ProtoContext::read_control_string<std::string>(invalid_auth_fail_buf);
1439 EXPECT_EQ(msg3,
"AUTH_FAILED: go\n away");
1442 auto msg4 = ProtoContext::read_control_string<std::string>(lot_of_whitespace_buf);
1443 EXPECT_EQ(msg4,
"AUTH_FAILED: a lot of white space");
1446 auto msg5 = ProtoContext::read_control_string<std::string>(only_whitespace_buf);
1447 EXPECT_EQ(msg5,
"");
1450 auto msg6 = ProtoContext::read_control_string<std::string>(empty_buf);
1451 EXPECT_EQ(msg6,
"");
1470 std::vector<openvpn::ClientEvent::Base::Ptr>
events;
1473TEST(proto, client_proto_check_cc_msg)
1475 asio::io_context io_context;
1476 ClientRandomAPI::Ptr rng_cli(
new ClientRandomAPI());
1492 std::move(cli_stats),
1494 clisessconf.cli_events = std::move(eqv_ptr);
1497 clisession->validate_and_post_cc_msg(
"valid message");
1500 EXPECT_TRUE(eqv->
events.empty());
1502 clisession->validate_and_post_cc_msg(
"invalid\nmessage");
1503 EXPECT_EQ(eqv->
events.size(), 1);
1504 auto ev = eqv->
events.back();
1508 EXPECT_EQ(uf->name,
"Invalid chars in control message");
1509 EXPECT_EQ(uf->reason,
"Control channel message with invalid characters not allowed to be send with post_cc_msg");
Time::Duration operator()() const
DroughtMeasure(const std::string &name_arg, TimePtr now_arg)
OPENVPN_SIMPLE_EXCEPTION(drought_limit_exceeded)
void add_event(openvpn::ClientEvent::Base::Ptr event) override
std::vector< openvpn::ClientEvent::Base::Ptr > events
void client_proto_terminate()
count_t errors[Error::N_ERRORS]
void error(const size_t err_type, const std::string *text=nullptr) override
count_t get_error_count(const Error::Type type) const
RCPtr< MySessionStats > Ptr
void show_error_counts() const
NoisyWire(const std::string title_arg, TimePtr now_arg, RandomAPI &rand_arg, const unsigned int reorder_prob_arg, const unsigned int drop_prob_arg, const unsigned int corrupt_prob_arg)
std::deque< BufferPtr > wire
unsigned int rand(const unsigned int prob)
unsigned int reorder_prob
unsigned int corrupt_prob
TestProtoClient(const ProtoContext::ProtoConfig::Ptr &config, const SessionStats::Ptr &stats)
void client_auth(Buffer &buf) override
void server_auth(const std::string &username, const SafeString &password, const std::string &peer_info, const AuthCert::Ptr &auth_cert) override
TestProtoServer(const ProtoContext::ProtoConfig::Ptr &config, const SessionStats::Ptr &stats)
OPENVPN_SIMPLE_EXCEPTION(auth_failed)
TestProto(const ProtoContext::ProtoConfig::Ptr &config, const SessionStats::Ptr &stats)
void control_recv(BufferPtr &&app_bp) override
DroughtMeasure data_drought
void modmsg(BufferPtr &buf)
void data_decrypt(const ProtoContext::PacketType &type, BufferAllocated &in_out)
void control_send(BufferPtr &&app_bp)
void data_encrypt(BufferAllocated &in_out)
void initial_app_send(const char *msg)
const char * progress() const
void control_send(BufferAllocated &&app_buf)
ProtoContext proto_context
void active(bool primary) override
Called when KeyContext transitions to ACTIVE state.
size_t n_control_recv() const
DroughtMeasure control_drought
BufferPtr data_encrypt_string(const char *str)
size_t n_control_send() const
OPENVPN_EXCEPTION(session_invalidated)
void app_send_templ_init(const char *msg)
void control_net_send(const Buffer &net_buf) override
bool supports_epoch_data() override
size_t data_bytes() const
void copy_progress(Buffer &buf)
std::deque< BufferPtr > net_out
size_t size() const
Returns the size of the buffer in T objects.
T * data()
Get a mutable pointer to the start of the array.
size_t prepare(const unsigned int context, Buffer &buf) const
const Time::Duration & slowest_handshake()
void flush(const bool control_channel)
void control_send(BufferPtr &&app_bp)
void data_encrypt(BufferAllocated &in_out)
static void write_auth_string(const S &str, Buffer &buf)
bool data_decrypt(const PacketType &type, BufferAllocated &in_out)
Error::Type invalidation_reason() const
unsigned int negotiations() const
Time next_housekeeping() const
void reset(const ProtoSessionID cookie_psid=ProtoSessionID())
Resets ProtoContext *this to it's initial state.
void start(const ProtoSessionID cookie_psid=ProtoSessionID())
Initialize the state machine and start protocol negotiation.
const ProtoConfig & conf() const
void swap(RCPtr &rhs) noexcept
swaps the contents of two RCPtr<T>
T * get() const noexcept
Returns the raw pointer to the object T, or nullptr.
Abstract base class for random number generators.
T randrange(const T end)
Return a uniformly distributed random number in the range [0, end)
static Ptr Create(ArgsT &&...args)
Creates a new instance of RcEnable with the given arguments.
@ LF_ALLOW_CLIENT_CERT_NOT_REQUIRED
A string-like type that clears the buffer contents on delete.
void parse(const std::string &key_text)
void extract_wkc(BufferAllocated &wkc_out) const
void extract_key(OpenVPNStaticKey &tls_key)
void extract_key(OpenVPNStaticKey &tls_key)
void parse(const std::string &key_text)
static TimeType infinite()
static constexpr int default_log_level
static void set_log_level(int level)
set the log level for all loggigng
void work(openvpn_io::io_context &io_context, ThreadCommon &tc, MyRunContext &runctx, const unsigned int unit)
constexpr BufferFlags GROW(1u<< 2)
if enabled, buffer will grow (otherwise buffer_full exception will be thrown)
constexpr BufferFlags NO_FLAGS(0u)
no flags set
Type lookup(const std::string &name)
const char * name(const size_t type)
bool is_valid_utf8(const STRING &str, const size_t max_len_flags=0)
std::string read_text(const std::string &filename, const std::uint64_t max_size=0)
RCPtr< BufferAllocatedRc > BufferPtr
ProtoContext::ProtoConfig::Ptr proto_context_config
os<< "Session Name: "<< tbc-> session_name<< '\n';os<< "Layer: "<< tbc-> layer str()<< '\n'
static const char config[]
#define TLS_TIMEOUT_CLIENT
int test_retry(const int thread_num, const int n_retries, bool use_tls_ekm, bool tls_version_mismatch=false, const std::string &tls_crypt_v2_key_fn="", bool use_tls_auth_with_tls_crypt_v2=false)
#define TLS_TIMEOUT_SERVER
static auto create_client_proto_context(ClientSSLAPI::Config::Ptr cc, Frame::Ptr frame, ClientRandomAPI::Ptr rng, MySessionStats::Ptr cli_stats, Time &time, const std::string &tls_crypt_v2_key_fn="")
TEST_F(ProtoUnitTest, base_single_thread_tls_ekm)
TEST(proto, iv_ciphers_aead)
static auto create_client_ssl_config(Frame::Ptr frame, ClientRandomAPI::Ptr rng, bool tls_version_mismatch=false)