|
OpenVPN
|
#include "syshead.h"#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <string.h>#include <setjmp.h>#include <cmocka.h>#include "test_common.h"#include "tls_crypt.c"
Go to the source code of this file.
Data Structures | |
| struct | test_tls_crypt_context |
| struct | test_tls_crypt_v2_context |
Macros | |
| #define | TESTBUF_SIZE 128 |
| #define | PATH1 "/s p a c e" |
| #define | PATH2 "/foo bar/baz" |
| #define | PARAM1 "param1" |
| #define | PARAM2 "param two" |
Functions | |
| 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 TLS channel. | |
| int | __wrap_parse_line (const char *line, char **p, const int n, const char *file, const int line_num, msglvl_t msglevel, struct gc_arena *gc) |
| bool | __wrap_buffer_write_file (const char *filename, const struct buffer *buf) |
| struct buffer | __wrap_buffer_read_from_file (const char *filename, struct gc_arena *gc) |
| int | __wrap_rand_bytes (uint8_t *output, int len) |
| Predictable random for tests. | |
| static int | test_tls_crypt_setup (void **state) |
| static int | test_tls_crypt_teardown (void **state) |
| static void | skip_if_tls_crypt_not_supported (struct test_tls_crypt_context *ctx) |
| static void | tls_crypt_loopback (void **state) |
| Check that short messages are successfully wrapped-and-unwrapped. | |
| static void | test_tls_crypt_secure_reneg_key (void **state) |
| Test generating dynamic tls-crypt key. | |
| static void | tls_crypt_loopback_zero_len (void **state) |
| Check that zero-byte messages are successfully wrapped-and-unwrapped. | |
| static void | tls_crypt_loopback_max_len (void **state) |
| Check that max-length messages are successfully wrapped-and-unwrapped. | |
| static void | tls_crypt_fail_msg_too_long (void **state) |
| Check that too-long messages are gracefully rejected. | |
| static void | tls_crypt_fail_invalid_key (void **state) |
| Check that packets that were wrapped (or unwrapped) with a different key are not accepted. | |
| static void | tls_crypt_fail_replay (void **state) |
| Check that replayed packets are not accepted. | |
| static void | tls_crypt_ignore_replay (void **state) |
| Check that packet replays are accepted when CO_IGNORE_PACKET_ID is set. | |
| static int | test_tls_crypt_v2_setup (void **state) |
| static int | test_tls_crypt_v2_teardown (void **state) |
| static void | tls_crypt_v2_wrap_unwrap_no_metadata (void **state) |
| Check wrapping and unwrapping a tls-crypt-v2 client key without metadata. | |
| static void | tls_crypt_v2_wrap_unwrap_max_metadata (void **state) |
| Check wrapping and unwrapping a tls-crypt-v2 client key with maximum length metadata. | |
| static void | tls_crypt_v2_wrap_too_long_metadata (void **state) |
| Check that wrapping a tls-crypt-v2 client key with too long metadata fails as expected. | |
| static void | tls_crypt_v2_wrap_unwrap_wrong_key (void **state) |
| Check that unwrapping a tls-crypt-v2 client key with the wrong server key fails as expected. | |
| static void | tls_crypt_v2_wrap_unwrap_dst_too_small (void **state) |
| Check that unwrapping a tls-crypt-v2 client key to a too small metadata buffer fails as expected. | |
| static struct buffer | create_metadata_days_ago (struct gc_arena *gc, int days_ago) |
| static struct buffer | create_client_key_input (struct test_tls_crypt_v2_context *ctx, int days_ago) |
| Creates a minimal buffer that allows tls_crypt_v2_extract_client_key to extract the client key. | |
| static void | tls_crypt_v2_wrap_unwrap_invalid (void **state) |
| Check that unwrapping an invalid key fails as expected and does not leave extra memory around (via ASAN) | |
| static void | tls_crypt_v2_unwrap_checks (void **state) |
| static void | test_tls_crypt_v2_write_server_key_file (void **state) |
| static void | test_tls_crypt_v2_write_client_key_file (void **state) |
| static void | test_tls_crypt_v2_write_client_key_file_metadata (void **state) |
| int | main (void) |
Variables | |
| static const char * | test_server_key |
| static const char * | test_client_key |
| static const char * | test_client_key_metadata |
| #define PARAM1 "param1" |
Definition at line 55 of file test_tls_crypt.c.
| #define PARAM2 "param two" |
Definition at line 56 of file test_tls_crypt.c.
| #define PATH1 "/s p a c e" |
Definition at line 53 of file test_tls_crypt.c.
| #define PATH2 "/foo bar/baz" |
Definition at line 54 of file test_tls_crypt.c.
| #define TESTBUF_SIZE 128 |
Definition at line 50 of file test_tls_crypt.c.
Definition at line 141 of file test_tls_crypt.c.
References alloc_buf_gc(), buf_write(), gc, and buffer::len.
Referenced by test_tls_crypt_v2_write_client_key_file(), and test_tls_crypt_v2_write_client_key_file_metadata().
| bool __wrap_buffer_write_file | ( | const char * | filename, |
| const struct buffer * | buf | ||
| ) |
Definition at line 131 of file test_tls_crypt.c.
References BSTR.
Referenced by test_tls_crypt_v2_write_client_key_file(), test_tls_crypt_v2_write_client_key_file_metadata(), test_tls_crypt_v2_write_server_key_file(), and tls_crypt_v2_unwrap_checks().
| int __wrap_rand_bytes | ( | uint8_t * | output, |
| int | len | ||
| ) |
Predictable random for tests.
Definition at line 155 of file test_tls_crypt.c.
References buffer::len.
|
static |
Creates a minimal buffer that allows tls_crypt_v2_extract_client_key to extract the client key.
This will add metadata with a tls-crypt key created with the given days_ago.
Definition at line 649 of file test_tls_crypt.c.
References alloc_buf_gc(), buf_copy(), buf_len(), buf_reset_len(), buf_write_u8(), create_metadata_days_ago(), buffer::len, and tls_crypt_v2_wrap_client_key().
Referenced by tls_crypt_v2_unwrap_checks(), and tls_crypt_v2_wrap_unwrap_invalid().
Definition at line 627 of file test_tls_crypt.c.
References alloc_buf_gc(), ASSERT, buf_write(), gc, htonll, buffer::len, now, and TLS_CRYPT_METADATA_TYPE_TIMESTAMP.
Referenced by create_client_key_input(), and tls_crypt_v2_unwrap_checks().
| 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 TLS channel.
This exported keying material can then be used for a variety of purposes.
| session | The session associated with the given key_state |
| label | The label to use when exporting the key |
| label_size | The size of the label to use when exporting the key |
| ekm | Buffer to return the exported key material in |
| ekm_size | The size of ekm, in bytes |
Definition at line 42 of file test_tls_crypt.c.
References session::key, KS_PRIMARY, and secure_memzero().
Referenced by export_user_keying_material(), generate_key_expansion_tls_export(), p2p_ncp_set_options(), and tls_session_generate_dynamic_tls_crypt_key().
| int main | ( | void | ) |
Definition at line 823 of file test_tls_crypt.c.
References openvpn_unit_test_setup(), test_tls_crypt_secure_reneg_key(), test_tls_crypt_setup(), test_tls_crypt_teardown(), test_tls_crypt_v2_setup(), test_tls_crypt_v2_teardown(), test_tls_crypt_v2_write_client_key_file(), test_tls_crypt_v2_write_client_key_file_metadata(), test_tls_crypt_v2_write_server_key_file(), tls_crypt_fail_invalid_key(), tls_crypt_fail_msg_too_long(), tls_crypt_fail_replay(), tls_crypt_ignore_replay(), tls_crypt_loopback(), tls_crypt_loopback_max_len(), tls_crypt_loopback_zero_len(), tls_crypt_v2_unwrap_checks(), tls_crypt_v2_wrap_too_long_metadata(), tls_crypt_v2_wrap_unwrap_dst_too_small(), tls_crypt_v2_wrap_unwrap_invalid(), tls_crypt_v2_wrap_unwrap_max_metadata(), tls_crypt_v2_wrap_unwrap_no_metadata(), and tls_crypt_v2_wrap_unwrap_wrong_key().
|
static |
Definition at line 227 of file test_tls_crypt.c.
References key_type::cipher, key_type::digest, and test_tls_crypt_context::kt.
Referenced by tls_crypt_fail_invalid_key(), tls_crypt_fail_msg_too_long(), tls_crypt_fail_replay(), tls_crypt_ignore_replay(), tls_crypt_loopback(), tls_crypt_loopback_max_len(), and tls_crypt_loopback_zero_len().
|
static |
Test generating dynamic tls-crypt key.
Definition at line 257 of file test_tls_crypt.c.
References BLENZ, BPTR, frame::buf, buf_advance(), buf_len(), tls_options::frame, gc, gc_free(), gc_new(), tls_wrap_ctx::opt, frame::payload_size, tls_options::replay_time, tls_options::replay_window, test_tls_crypt_context::source, tls_crypt_wrap(), tls_session_generate_dynamic_tls_crypt_key(), tls_wrap_ctx::TLS_WRAP_CRYPT, tls_wrap_free(), and tls_wrap_ctx::work.
Referenced by main().
|
static |
Definition at line 175 of file test_tls_crypt.c.
References alloc_buf(), buf_write(), key_type::cipher, key::cipher, test_tls_crypt_context::ciphertext, test_tls_crypt_context::co, key_ctx_bi::decrypt, key_type::digest, key_ctx_bi::encrypt, init_key_ctx(), crypto_options::key_ctx_bi, test_tls_crypt_context::kt, MAX_CIPHER_KEY_LENGTH, MAX_HMAC_KEY_LENGTH, crypto_options::packet_id, packet_id_init(), test_tls_crypt_context::source, TESTBUF_SIZE, tls_crypt_kt(), and test_tls_crypt_context::unwrapped.
Referenced by main().
|
static |
Definition at line 211 of file test_tls_crypt.c.
References test_tls_crypt_context::ciphertext, test_tls_crypt_context::co, free_buf(), free_key_ctx_bi(), crypto_options::key_ctx_bi, test_tls_crypt_context::source, and test_tls_crypt_context::unwrapped.
Referenced by main().
|
static |
Definition at line 453 of file test_tls_crypt.c.
References alloc_buf_gc(), test_tls_crypt_v2_context::client_key2, test_tls_crypt_v2_context::gc, gc_new(), init_key_ctx_bi(), KEY_DIRECTION_BIDIRECTIONAL, key2::keys, test_tls_crypt_v2_context::metadata, key2::n, rand_bytes(), test_tls_crypt_v2_context::server_key2, test_tls_crypt_v2_context::server_keys, tls_crypt_kt(), TLS_CRYPT_V2_MAX_METADATA_LEN, TLS_CRYPT_V2_MAX_WKC_LEN, test_tls_crypt_v2_context::unwrapped_metadata, and test_tls_crypt_v2_context::wkc.
Referenced by main().
|
static |
Definition at line 480 of file test_tls_crypt.c.
References test_tls_crypt_v2_context::client_key, free_key_ctx_bi(), test_tls_crypt_v2_context::gc, gc_free(), now, and test_tls_crypt_v2_context::server_keys.
Referenced by main().
|
static |
Definition at line 787 of file test_tls_crypt.c.
References __wrap_buffer_read_from_file(), __wrap_buffer_write_file(), buffer::len, test_client_key, test_server_key, and tls_crypt_v2_write_client_key_file().
Referenced by main().
|
static |
Definition at line 804 of file test_tls_crypt.c.
References __wrap_buffer_read_from_file(), __wrap_buffer_write_file(), buffer::len, test_client_key_metadata, test_server_key, and tls_crypt_v2_write_client_key_file().
Referenced by main().
|
static |
Definition at line 775 of file test_tls_crypt.c.
References __wrap_buffer_write_file(), buffer::len, test_server_key, and tls_crypt_v2_write_server_key_file().
Referenced by main().
|
static |
Check that packets that were wrapped (or unwrapped) with a different key are not accepted.
Definition at line 381 of file test_tls_crypt.c.
References BLEN, key::cipher, test_tls_crypt_context::ciphertext, test_tls_crypt_context::co, key_ctx_bi::decrypt, free_key_ctx(), init_key_ctx(), crypto_options::key_ctx_bi, test_tls_crypt_context::kt, MAX_CIPHER_KEY_LENGTH, MAX_HMAC_KEY_LENGTH, skip_if_tls_crypt_not_supported(), test_tls_crypt_context::source, tls_crypt_unwrap(), tls_crypt_wrap(), and test_tls_crypt_context::unwrapped.
Referenced by main().
|
static |
Check that too-long messages are gracefully rejected.
Definition at line 364 of file test_tls_crypt.c.
References BLEN, buf_clear(), buf_write_alloc(), test_tls_crypt_context::ciphertext, test_tls_crypt_context::co, skip_if_tls_crypt_not_supported(), test_tls_crypt_context::source, TESTBUF_SIZE, tls_crypt_buf_overhead(), and tls_crypt_wrap().
Referenced by main().
|
static |
Check that replayed packets are not accepted.
Definition at line 404 of file test_tls_crypt.c.
References BLEN, buf_clear(), test_tls_crypt_context::ciphertext, test_tls_crypt_context::co, buffer::len, skip_if_tls_crypt_not_supported(), test_tls_crypt_context::source, tls_crypt_unwrap(), tls_crypt_wrap(), and test_tls_crypt_context::unwrapped.
Referenced by main().
|
static |
Check that packet replays are accepted when CO_IGNORE_PACKET_ID is set.
This is used for the first control channel packet that arrives, because we don't know the packet ID yet.
Definition at line 424 of file test_tls_crypt.c.
References BLEN, buf_clear(), test_tls_crypt_context::ciphertext, test_tls_crypt_context::co, CO_IGNORE_PACKET_ID, crypto_options::flags, buffer::len, skip_if_tls_crypt_not_supported(), test_tls_crypt_context::source, tls_crypt_unwrap(), tls_crypt_wrap(), and test_tls_crypt_context::unwrapped.
Referenced by main().
|
static |
Check that short messages are successfully wrapped-and-unwrapped.
Definition at line 239 of file test_tls_crypt.c.
References BLEN, BLENZ, BPTR, test_tls_crypt_context::ciphertext, test_tls_crypt_context::co, skip_if_tls_crypt_not_supported(), test_tls_crypt_context::source, tls_crypt_unwrap(), tls_crypt_wrap(), and test_tls_crypt_context::unwrapped.
Referenced by main().
|
static |
Check that max-length messages are successfully wrapped-and-unwrapped.
Definition at line 343 of file test_tls_crypt.c.
References BLEN, BLENZ, BPTR, buf_clear(), buf_write_alloc(), test_tls_crypt_context::ciphertext, test_tls_crypt_context::co, skip_if_tls_crypt_not_supported(), test_tls_crypt_context::source, TESTBUF_SIZE, tls_crypt_buf_overhead(), tls_crypt_unwrap(), tls_crypt_wrap(), and test_tls_crypt_context::unwrapped.
Referenced by main().
|
static |
Check that zero-byte messages are successfully wrapped-and-unwrapped.
Definition at line 324 of file test_tls_crypt.c.
References BLEN, BLENZ, BPTR, buf_clear(), test_tls_crypt_context::ciphertext, test_tls_crypt_context::co, skip_if_tls_crypt_not_supported(), test_tls_crypt_context::source, tls_crypt_unwrap(), tls_crypt_wrap(), and test_tls_crypt_context::unwrapped.
Referenced by main().
|
static |
Definition at line 692 of file test_tls_crypt.c.
References __wrap_buffer_write_file(), buf_advance(), buf_bptr(), buf_len(), create_client_key_input(), create_metadata_days_ago(), key_ctx_bi::encrypt, test_tls_crypt_v2_context::gc, get_random(), buffer::len, tls_wrap_ctx::mode, PACKAGE, script_security_set(), test_tls_crypt_v2_context::server_keys, tls_crypt_v2_extract_client_key(), tls_options::tls_crypt_v2_max_age, tls_wrap_ctx::tls_crypt_v2_server_key, tls_options::tls_crypt_v2_verify_script, tls_wrap_ctx::TLS_WRAP_CRYPT, tls_wrap_free(), tls_options::tmp_dir, and update_time().
Referenced by main().
|
static |
Check that wrapping a tls-crypt-v2 client key with too long metadata fails as expected.
Definition at line 564 of file test_tls_crypt.c.
References buf_inc_len(), test_tls_crypt_v2_context::client_key2, key_ctx_bi::encrypt, test_tls_crypt_v2_context::gc, test_tls_crypt_v2_context::metadata, test_tls_crypt_v2_context::server_keys, TLS_CRYPT_V2_MAX_METADATA_LEN, tls_crypt_v2_wrap_client_key(), and test_tls_crypt_v2_context::wkc.
Referenced by main().
|
static |
Check that unwrapping a tls-crypt-v2 client key to a too small metadata buffer fails as expected.
Definition at line 607 of file test_tls_crypt.c.
References alloc_buf_gc(), BLEN, buf_write_alloc(), test_tls_crypt_v2_context::client_key2, key_ctx_bi::decrypt, key_ctx_bi::encrypt, test_tls_crypt_v2_context::gc, buffer::len, test_tls_crypt_v2_context::metadata, rand_bytes(), test_tls_crypt_v2_context::server_keys, TLS_CRYPT_V2_MAX_METADATA_LEN, tls_crypt_v2_unwrap_client_key(), tls_crypt_v2_wrap_client_key(), test_tls_crypt_v2_context::unwrapped_metadata, and test_tls_crypt_v2_context::wkc.
Referenced by main().
|
static |
Check that unwrapping an invalid key fails as expected and does not leave extra memory around (via ASAN)
Definition at line 671 of file test_tls_crypt.c.
References buf_bptr(), buf_len(), create_client_key_input(), key_ctx_bi::encrypt, buffer::len, tls_wrap_ctx::mode, test_tls_crypt_v2_context::server_keys, tls_crypt_v2_extract_client_key(), tls_wrap_ctx::tls_crypt_v2_server_key, tls_wrap_ctx::TLS_WRAP_CRYPT, tls_wrap_free(), and update_time().
Referenced by main().
|
static |
Check wrapping and unwrapping a tls-crypt-v2 client key with maximum length metadata.
Definition at line 524 of file test_tls_crypt.c.
References alloc_buf_gc(), buf_copy(), buf_equal(), buf_len(), buf_write_alloc(), buf_write_u8(), test_tls_crypt_v2_context::client_key2, key_ctx_bi::decrypt, key_ctx_bi::encrypt, test_tls_crypt_v2_context::gc, key2::keys, buffer::len, test_tls_crypt_v2_context::metadata, tls_wrap_ctx::mode, rand_bytes(), test_tls_crypt_v2_context::server_keys, tls_crypt_v2_extract_client_key(), TLS_CRYPT_V2_MAX_METADATA_LEN, tls_wrap_ctx::tls_crypt_v2_server_key, tls_crypt_v2_unwrap_client_key(), tls_crypt_v2_wrap_client_key(), tls_wrap_ctx::TLS_WRAP_CRYPT, tls_wrap_free(), and test_tls_crypt_v2_context::wkc.
Referenced by main().
|
static |
Check wrapping and unwrapping a tls-crypt-v2 client key without metadata.
Definition at line 502 of file test_tls_crypt.c.
References alloc_buf_gc(), test_tls_crypt_v2_context::client_key2, key_ctx_bi::decrypt, key_ctx_bi::encrypt, test_tls_crypt_v2_context::gc, key2::keys, buffer::len, test_tls_crypt_v2_context::metadata, test_tls_crypt_v2_context::server_keys, TLS_CRYPT_V2_MAX_METADATA_LEN, TLS_CRYPT_V2_MAX_WKC_LEN, tls_crypt_v2_unwrap_client_key(), and tls_crypt_v2_wrap_client_key().
Referenced by main().
|
static |
Check that unwrapping a tls-crypt-v2 client key with the wrong server key fails as expected.
Definition at line 578 of file test_tls_crypt.c.
References BLEN, test_tls_crypt_v2_context::client_key2, key_ctx_bi::decrypt, key_ctx_bi::encrypt, free_key_ctx_bi(), test_tls_crypt_v2_context::gc, init_key_ctx_bi(), KEY_DIRECTION_BIDIRECTIONAL, key2::keys, test_tls_crypt_v2_context::metadata, test_tls_crypt_v2_context::server_key2, test_tls_crypt_v2_context::server_keys, tls_crypt_kt(), tls_crypt_v2_unwrap_client_key(), tls_crypt_v2_wrap_client_key(), test_tls_crypt_v2_context::unwrapped_metadata, and test_tls_crypt_v2_context::wkc.
Referenced by main().
|
static |
Definition at line 65 of file test_tls_crypt.c.
Referenced by test_tls_crypt_v2_write_client_key_file(), and tls_crypt_v2_write_client_key_file().
|
static |
Definition at line 83 of file test_tls_crypt.c.
Referenced by test_tls_crypt_v2_write_client_key_file_metadata().
|
static |
Definition at line 58 of file test_tls_crypt.c.
Referenced by test_tls_crypt_v2_write_client_key_file(), test_tls_crypt_v2_write_client_key_file_metadata(), and test_tls_crypt_v2_write_server_key_file().