Go to the documentation of this file.
71 "MIIBuTCCAUCgAwIBAgIUTLtjSBzx53qZRvZ6Ur7D9kgoOHkwCgYIKoZIzj0EAwIw\n"
72 "EzERMA8GA1UEAwwIdW5pdHRlc3QwIBcNMjMxMTIxMDk1NDQ3WhgPMjA3ODA4MjQw\n"
73 "OTU0NDdaMBMxETAPBgNVBAMMCHVuaXR0ZXN0MHYwEAYHKoZIzj0CAQYFK4EEACID\n"
74 "YgAEHYB2hn2xx3f4lClXDtdi36P19pMZA+kI1Dkv/Vn10vBZ/j9oa+P99T8duz/e\n"
75 "QlPeHpesNJO4fX8iEDj6+vMeWejOT7jAQ4MmG5EZjpcBKxCfwFooEvzu8bVujUcu\n"
76 "wTQEo1MwUTAdBgNVHQ4EFgQUPcgBEVXjF5vYfDsInoE3dF6UfQswHwYDVR0jBBgw\n"
77 "FoAUPcgBEVXjF5vYfDsInoE3dF6UfQswDwYDVR0TAQH/BAUwAwEB/zAKBggqhkjO\n"
78 "PQQDAgNnADBkAjBLPAGrQAyinigqiu0RomoV8TVaknVLFSq6H6A8jgvzfsFCUK1O\n"
79 "dvNZhFPM6idKB+oCME2JLOBANCSV8o7aJzq7SYHKwPyb1J4JFlwKe/0Jpv7oh9b1\n"
80 "IJbuaM9Z/VSKbrIXGg==\n"
81 "-----END CERTIFICATE-----\n";
109 #ifdef ENABLE_CRYPTO_OPENSSL
110 cert = SSL_CTX_get0_certificate(
ctx.ctx);
111 #elif defined(ENABLE_CRYPTO_MBEDTLS)
112 cert =
ctx.crt_chain;
219 memcpy(buf_p,
BPTR(&src),
BLEN(&src));
231 assert_int_equal(buf.
len, src.
len);
232 assert_memory_equal(
BPTR(&src),
BPTR(&buf), i);
341 const struct CMUnitTest tests[] = {
353 #if defined(ENABLE_CRYPTO_OPENSSL)
357 int ret = cmocka_run_group_tests_name(
"ssl tests", tests, NULL, NULL);
359 #if defined(ENABLE_CRYPTO_OPENSSL)
struct buffer buffer_read_from_file(const char *filename, struct gc_arena *gc)
buffer_read_from_file - copy the content of a file into a buffer
void tls_ctx_load_cert_file(struct tls_root_ctx *ctx, const char *cert_file, bool cert_file_inline)
Load certificate file into the given TLS context.
static bool cipher_valid(const char *ciphername)
Returns if the cipher is valid, based on the given cipher name.
int n
The number of key objects stored in the key2.keys array.
int cipher_ctx_iv_length(const cipher_ctx_t *ctx)
Returns the size of the IV used by the cipher, in bytes, or 0 if no IV is used.
static struct gc_arena gc_new(void)
void tls_init_lib(void)
Perform any static initialisation necessary by the library.
#define OPENVPN_AEAD_MIN_IV_LEN
Minimal IV length for AEAD mode ciphers (in bytes): 4-byte packet id + 8 bytes implicit IV.
#define RELIABLE_ACK_SIZE
The maximum number of packet IDs waiting to be acknowledged which can be stored in one reliable_ack s...
int len
Length in bytes of the actual content within the allocated memory.
void packet_id_init(struct packet_id *p, int seq_backtrack, int time_backtrack, const char *name, int unit)
static void test_data_channel_roundtrip_bf_cbc(void **state)
#define buf_init(buf, offset)
static void test_data_channel_roundtrip_aes_128_gcm(void **state)
void tls_ctx_client_new(struct tls_root_ctx *ctx)
Initialises a library-specific TLS context for a client.
int capacity
Size in bytes of memory allocated by malloc().
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
void throw_signal(const int signum)
Throw a hard signal.
cipher_ctx_t * cipher
Generic cipher context.
int tailroom
the tailroom in the buffer.
struct key_ctx encrypt
Cipher and/or HMAC contexts for sending direction.
void tls_free_lib(void)
Free any global SSL library-specific data structures.
static struct buffer clear_buf(void)
Return an empty struct buffer.
uint8_t hmac[MAX_HMAC_KEY_LENGTH]
Key material for HMAC operations.
struct crypto_options init_crypto_options(const char *cipher, const char *auth)
Packet geometry parameters.
result_t backend_x509_write_pem(openvpn_x509_cert_t *cert, const char *filename)
static void crypto_pem_encode_certificate(void **state)
static const char * get_tmp_dir(void)
void init_key_ctx_bi(struct key_ctx_bi *ctx, const struct key2 *key2, int key_direction, const struct key_type *kt, const char *name)
static void test_data_channel_roundtrip_aes_192_gcm(void **state)
void free_key_ctx_bi(struct key_ctx_bi *ctx)
const char * unittest_cert
int payload_size
the maximum size that a payload that our buffers can hold from either tun device or network link.
static void update_time(void)
static void test_data_channel_roundtrip_aes_256_cbc(void **state)
mbedtls_cipher_context_t cipher_ctx_t
Generic cipher context.
void openvpn_encrypt(struct buffer *buf, struct buffer work, struct crypto_options *opt)
Encrypt and HMAC sign a packet so that it can be sent as a data channel VPN tunnel packet to a remote...
static void test_data_channel_roundtrip_chacha20_poly1305(void **state)
struct signal_info siginfo_static
void tls_ctx_free(struct tls_root_ctx *ctx)
Frees the library-specific TLSv1 context.
bool openvpn_decrypt(struct buffer *buf, struct buffer work, struct crypto_options *opt, const struct frame *frame, const uint8_t *ad_start)
HMAC verify and decrypt a data channel packet received from a remote OpenVPN peer.
bool cipher_ctx_mode_aead(const cipher_ctx_t *ctx)
Check if the supplied cipher is a supported AEAD mode cipher.
Wrapper structure for dynamically allocated memory.
#define OPENVPN_MAX_IV_LENGTH
Maximum length of an IV.
static void test_data_channel_roundtrip_aes_256_gcm(void **state)
size_t implicit_iv_len
The length of implicit_iv.
int rand_bytes(uint8_t *output, int len)
Wrapper for secure random number generator.
static void init_implicit_iv(struct crypto_options *co)
const char * strerror_win32(DWORD errnum, struct gc_arena *gc)
uint8_t implicit_iv[OPENVPN_MAX_IV_LENGTH]
The implicit part of the IV.
static struct key_type create_kt(const char *cipher, const char *md, const char *optname)
Creates and validates an instance of struct key_type with the provided algs.
Garbage collection arena used to keep track of dynamically allocated memory.
const char * cipher
const name of the cipher
static void init_frame_parameters(struct frame *frame)
static void do_data_channel_round_trip(struct crypto_options *co)
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...
Structure that wraps the TLS context.
static void gc_free(struct gc_arena *a)
const char * win_get_tempdir(void)
uint8_t cipher[MAX_CIPHER_KEY_LENGTH]
Key material for cipher operations.
struct key_ctx_bi key_ctx_bi
OpenSSL cipher and HMAC contexts for both sending and receiving directions.
static uint8_t * buf_write_alloc(struct buffer *buf, size_t size)
static void run_data_channel_with_cipher(const char *cipher, const char *auth)
static void test_data_channel_roundtrip_aes_128_cbc(void **state)
static void test_data_channel_roundtrip_aes_192_cbc(void **state)
Container for bidirectional cipher and HMAC key material.
struct packet_id packet_id
Current packet ID state for both sending and receiving directions.
struct key keys[2]
Two unidirectional sets of key material.
void packet_id_free(struct packet_id *p)
static void uninit_crypto_options(struct crypto_options *co)
int tun_mtu
the (user) configured tun-mtu.
struct key_ctx decrypt
cipher and/or HMAC contexts for receiving direction.
int headroom
the headroom in the buffer, this is choosen to allow all potential header to be added before the pack...
Security parameter state for processing data channel packets.