50 void *ekm,
size_t ekm_size)
58#if defined(ENABLE_DCO)
62 return "AES-192-GCM:AES-128-CBC:AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305";
83 if (have_chacha && have_blowfish)
115 bool have_chacha_mixed_case =
cipher_valid(
"ChaCha20-Poly1305");
116 if (have_chacha_mixed_case)
127 "ChaCha20-Poly1305:ChaCha20-Poly1305:ChaCha20-Poly1305:"
132#ifdef ENABLE_CRYPTO_OPENSSL
134 "AES-128-GCM:AES-256-GCM");
148 const char *client_peer_info;
149 const char *peer_list;
151 client_peer_info =
"foo=bar\nIV_foo=y\nIV_NCP=2";
156 client_peer_info =
"foo=bar\nIV_foo=y\nIV_NCP=2\nIV_CIPHERS=BF-CBC";
158 assert_string_equal(
"BF-CBC", peer_list);
161 client_peer_info =
"IV_NCP=2\nIV_CIPHERS=BF-CBC:FOO-BAR\nIV_BAR=7";
163 assert_string_equal(
"BF-CBC:FOO-BAR", peer_list);
166 client_peer_info =
"IV_CIPHERS=BF-CBC:FOO-BAR\nIV_BAR=7";
168 assert_string_equal(
"BF-CBC:FOO-BAR", peer_list);
171 client_peer_info =
"IV_YOLO=NO\nIV_BAR=7";
173 assert_string_equal(
"", peer_list);
177 assert_string_equal(
"", peer_list);
189 const char *serverlist =
"CHACHA20_POLY1305:AES-128-GCM";
190 const char *serverlistbfcbc =
"CHACHA20_POLY1305:AES-128-GCM:BF-CBC:none";
194 assert_ptr_equal(best_cipher, NULL);
199 assert_string_equal(best_cipher,
"BF-CBC");
204 assert_string_equal(best_cipher,
"AES-128-GCM");
208 assert_string_equal(best_cipher,
"AES-128-GCM");
211 assert_ptr_equal(best_cipher, NULL);
214 assert_string_equal(best_cipher,
"none");
217 assert_ptr_equal(best_cipher, NULL);
229 const char *serverlist =
"CHACHA20_POLY1305:AES-128-GCM:AES-256-GCM";
233 assert_string_equal(best_cipher,
"AES-128-GCM");
238 assert_string_equal(best_cipher,
"CHACHA20_POLY1305");
244 assert_string_equal(best_cipher,
"AES-128-GCM");
247 best_cipher =
ncp_get_best_cipher(serverlist,
"IV_FOO=7\nIV_CIPHERS=AES-256-GCM\nIV_NCP=2",
250 assert_string_equal(best_cipher,
"AES-256-GCM");
271 assert_string_equal(o.
ncp_ciphers,
"AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305");
275 assert_string_equal(o.
ncp_ciphers,
"AES-256-GCM:AES-128-GCM");
282 o.
ncp_ciphers =
"AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305";
293 o.
ncp_ciphers =
"BF-CBC:DEFAULT:AES-128-CBC:AES-256-CBC";
300 "BF-CBC:AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305:AES-128-CBC:AES-256-CBC");
305 "BF-CBC:AES-256-GCM:AES-128-GCM:AES-128-CBC:AES-256-CBC");
307 assert_string_equal(o.
ncp_ciphers_conf,
"BF-CBC:DEFAULT:AES-128-CBC:AES-256-CBC");
316 "AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305:AES-128-CBC:AES-192-CBC");
320 assert_string_equal(o.
ncp_ciphers,
"AES-256-GCM:AES-128-GCM:AES-128-CBC:AES-192-CBC");
331 "AES-192-GCM:AES-128-CBC:AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305");
335 assert_string_equal(o.
ncp_ciphers,
"AES-192-GCM:AES-128-CBC:AES-256-GCM:AES-128-GCM");
364 assert_string_equal(expanded,
" (AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305)");
365 assert_string_equal(expanded2,
" (AES-192-GCM:AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305)");
369 assert_string_equal(expanded,
" (AES-256-GCM:AES-128-GCM)");
370 assert_string_equal(expanded2,
" (AES-192-GCM:AES-256-GCM:AES-128-GCM)");
397#if defined(ENABLE_CRYPTO_OPENSSL)
398 OpenSSL_add_all_algorithms();
400 return cmocka_run_group_tests(
ncp_tests, NULL, NULL);
static void gc_free(struct gc_arena *a)
static struct gc_arena gc_new(void)
static bool cipher_valid(const char *ciphername)
Returns if the cipher is valid, based on the given cipher name.
static const char * dco_get_supported_ciphers(void)
Control Channel SSL/Data dynamic negotiation Module This file is split from ssl.c to be able to unit ...
char * ncp_get_best_cipher(const char *server_list, const char *peer_info, const char *remote_cipher, struct gc_arena *gc)
Iterates through the ciphers in server_list and return the first cipher that is also supported by the...
const char * tls_peer_ncp_list(const char *peer_info, struct gc_arena *gc)
Returns the support cipher list from the peer according to the IV_NCP and IV_CIPHER values in peer_in...
void options_postprocess_setdefault_ncpciphers(struct options *o)
Checks for availibility of Chacha20-Poly1305 and sets the ncp_cipher to either AES-256-GCM:AES-128-GC...
const char * ncp_expanded_ciphers(struct options *o, struct gc_arena *gc)
returns the o->ncp_ciphers in brackets, e.g.
bool tls_peer_supports_ncp(const char *peer_info)
Returns whether the client supports NCP either by announcing IV_NCP>=2 or the IV_CIPHERS list.
char * mutate_ncp_cipher_list(const char *list, struct gc_arena *gc)
Check whether the ciphers in the supplied list are supported.
Garbage collection arena used to keep track of dynamically allocated memory.
const char * ncp_ciphers_conf
The original ncp_ciphers specified by the user in the configuration.
Security parameter state of a single session within a VPN tunnel.
static void openvpn_unit_test_setup(void)
Sets up the environment for unit tests like making both stderr and stdout non-buffered to avoid messa...
bool key_state_export_keying_material(struct tls_session *session, const char *label, size_t label_size, void *ekm, size_t ekm_size)
Keying Material Exporters [RFC 5705] allows additional keying material to be derived from existing TL...
static void test_extract_client_ciphers(void **state)
static void test_ncp_default(void **state)
static void test_ncp_expand(void **state)
static void test_check_ncp_ciphers_list(void **state)
static void test_poor_man(void **state)
static void test_ncp_best(void **state)
const struct CMUnitTest ncp_tests[]