OpenVPN
Data Structures | Macros | Functions | Variables
test_tls_crypt.c File Reference
#include "syshead.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <setjmp.h>
#include <cmocka.h>
#include "tls_crypt.c"
#include "mock_msg.h"
Include dependency graph for test_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

int __wrap_parse_line (const char *line, char **p, const int n, const char *file, const int line_num, int 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. More...
 
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. More...
 
static void tls_crypt_loopback_zero_len (void **state)
 Check that zero-byte messages are successfully wrapped-and-unwrapped. More...
 
static void tls_crypt_loopback_max_len (void **state)
 Check that max-length messages are successfully wrapped-and-unwrapped. More...
 
static void tls_crypt_fail_msg_too_long (void **state)
 Check that too-long messages are gracefully rejected. More...
 
static void tls_crypt_fail_invalid_key (void **state)
 Check that packets that were wrapped (or unwrapped) with a different key are not accepted. More...
 
static void tls_crypt_fail_replay (void **state)
 Check that replayed packets are not accepted. More...
 
static void tls_crypt_ignore_replay (void **state)
 Check that packet replays are accepted when CO_IGNORE_PACKET_ID is set. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
static void test_tls_crypt_v2_write_server_key_file (void **state)
 
static void test_tls_crypt_v2_write_client_key_file (void **state)
 
int main (void)
 

Variables

static const char * test_server_key
 
static const char * test_client_key
 

Macro Definition Documentation

◆ PARAM1

#define PARAM1   "param1"

Definition at line 49 of file test_tls_crypt.c.

Referenced by __wrap_parse_line().

◆ PARAM2

#define PARAM2   "param two"

Definition at line 50 of file test_tls_crypt.c.

Referenced by __wrap_parse_line().

◆ PATH1

#define PATH1   "/s p a c e"

Definition at line 47 of file test_tls_crypt.c.

Referenced by __wrap_parse_line().

◆ PATH2

#define PATH2   "/foo bar/baz"

Definition at line 48 of file test_tls_crypt.c.

Referenced by __wrap_parse_line().

◆ TESTBUF_SIZE

#define TESTBUF_SIZE   128

Function Documentation

◆ __wrap_buffer_read_from_file()

struct buffer __wrap_buffer_read_from_file ( const char *  filename,
struct gc_arena gc 
)

Definition at line 96 of file test_tls_crypt.c.

References alloc_buf_gc(), buf_write(), check_expected, and mock.

Referenced by test_tls_crypt_v2_write_client_key_file().

◆ __wrap_buffer_write_file()

bool __wrap_buffer_write_file ( const char *  filename,
const struct buffer buf 
)

◆ __wrap_parse_line()

int __wrap_parse_line ( const char *  line,
char **  p,
const int  n,
const char *  file,
const int  line_num,
int  msglevel,
struct gc_arena gc 
)

Definition at line 76 of file test_tls_crypt.c.

References PARAM1, PARAM2, PATH1, and PATH2.

◆ __wrap_rand_bytes()

int __wrap_rand_bytes ( uint8_t output,
int  len 
)

Predictable random for tests.

Definition at line 110 of file test_tls_crypt.c.

References buffer::len.

◆ main()

int main ( void  )

◆ skip_if_tls_crypt_not_supported()

static void skip_if_tls_crypt_not_supported ( struct test_tls_crypt_context ctx)
static

◆ test_tls_crypt_setup()

static int test_tls_crypt_setup ( void **  state)
static

◆ test_tls_crypt_teardown()

static int test_tls_crypt_teardown ( void **  state)
static

◆ test_tls_crypt_v2_setup()

static int test_tls_crypt_v2_setup ( void **  state)
static

◆ test_tls_crypt_v2_teardown()

static int test_tls_crypt_v2_teardown ( void **  state)
static

◆ test_tls_crypt_v2_write_client_key_file()

static void test_tls_crypt_v2_write_client_key_file ( void **  state)
static

◆ test_tls_crypt_v2_write_server_key_file()

static void test_tls_crypt_v2_write_server_key_file ( void **  state)
static

◆ tls_crypt_fail_invalid_key()

static void tls_crypt_fail_invalid_key ( void **  state)
static

◆ tls_crypt_fail_msg_too_long()

static void tls_crypt_fail_msg_too_long ( void **  state)
static

◆ tls_crypt_fail_replay()

static void tls_crypt_fail_replay ( void **  state)
static

◆ tls_crypt_ignore_replay()

static void tls_crypt_ignore_replay ( void **  state)
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 298 of file test_tls_crypt.c.

References assert_true, BLEN, buf_clear(), test_tls_crypt_context::ciphertext, test_tls_crypt_context::co, CO_IGNORE_PACKET_ID, crypto_options::flags, 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().

◆ tls_crypt_loopback()

static void tls_crypt_loopback ( void **  state)
static

◆ tls_crypt_loopback_max_len()

static void tls_crypt_loopback_max_len ( void **  state)
static

◆ tls_crypt_loopback_zero_len()

static void tls_crypt_loopback_zero_len ( void **  state)
static

◆ tls_crypt_v2_wrap_too_long_metadata()

static void tls_crypt_v2_wrap_too_long_metadata ( void **  state)
static

◆ tls_crypt_v2_wrap_unwrap_dst_too_small()

static void tls_crypt_v2_wrap_unwrap_dst_too_small ( void **  state)
static

◆ tls_crypt_v2_wrap_unwrap_max_metadata()

static void tls_crypt_v2_wrap_unwrap_max_metadata ( void **  state)
static

◆ tls_crypt_v2_wrap_unwrap_no_metadata()

static void tls_crypt_v2_wrap_unwrap_no_metadata ( void **  state)
static

◆ tls_crypt_v2_wrap_unwrap_wrong_key()

static void tls_crypt_v2_wrap_unwrap_wrong_key ( void **  state)
static

Variable Documentation

◆ test_client_key

const char* test_client_key
static
Initial value:
=
"-----BEGIN OpenVPN tls-crypt-v2 client key-----\n"
"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4v\n"
"MDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5f\n"
"YGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6P\n"
"kJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/\n"
"wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v\n"
"8PHy8/T19vf4+fr7/P3+/xd9pcB0qUYZsWvkrLcfGmzPJPM8a7r0mEWdXwbDadSV\n"
"LHg5bv2TwlmPR3HgaMr8o9LTh9hxUTkrH3S0PfKRNwcso86ua/dBFTyXsM9tg4aw\n"
"3dS6ogH9AkaT+kRRDgNcKWkQCbwmJK2JlfkXHBwbAtmn78AkNuho6QCFqCdqGab3\n"
"zh2vheFqGMPdGpukbFrT3rcO3VLxUeG+RdzXiMTCpJSovFBP1lDkYwYJPnz6daEh\n"
"j0TzJ3BVru9W3CpotdNt7u09knxAfpCxjtrP3semsDew/gTBtcfQ/OoTFyFHnN5k\n"
"RZ+q17SC4nba3Pp8/Fs0+hSbv2tJozoD8SElFq7SIWJsciTYh8q8f5yQxjdt4Wxu\n"
"/Z5wtPCAZ0tOzj4ItTI77fBOYRTfEayzHgEr\n"
"-----END OpenVPN tls-crypt-v2 client key-----\n"

Definition at line 59 of file test_tls_crypt.c.

Referenced by test_tls_crypt_v2_write_client_key_file().

◆ test_server_key

const char* test_server_key
static
Initial value:
=
"-----BEGIN OpenVPN tls-crypt-v2 server key-----\n"
"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4v\n"
"MDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5f\n"
"YGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn8=\n"
"-----END OpenVPN tls-crypt-v2 server key-----\n"

Definition at line 52 of file test_tls_crypt.c.

Referenced by test_tls_crypt_v2_write_client_key_file(), and test_tls_crypt_v2_write_server_key_file().