OpenVPN 3 Core Library
Loading...
Searching...
No Matches
test_proto.cpp File Reference

Unit test for OpenVPN Protocol implementation (class ProtoContext) More...

#include "test_common.hpp"
#include <iostream>
#include <string>
#include <sstream>
#include <deque>
#include <algorithm>
#include <cstring>
#include <limits>
#include <thread>
#include <gmock/gmock.h>
#include <openvpn/common/platform.hpp>
#include <openvpn/ssl/sslchoose.hpp>
#include <openvpn/client/cliproto.hpp>
#include <filesystem>
#include <openvpn/common/exception.hpp>
#include <openvpn/common/file.hpp>
#include <openvpn/common/hexstr.hpp>
#include <openvpn/common/count.hpp>
#include <openvpn/time/time.hpp>
#include <openvpn/random/mtrandapi.hpp>
#include <openvpn/frame/frame.hpp>
#include <openvpn/ssl/proto.hpp>
#include <openvpn/init/initprocess.hpp>
#include <openvpn/crypto/cryptodcsel.hpp>
#include <openvpn/crypto/selftest.hpp>
Include dependency graph for test_proto.cpp:

Go to the source code of this file.

Classes

class  DroughtMeasure
 
class  TestProto
 
class  TestProtoClient
 
class  TestProtoServer
 
class  NoisyWire
 
class  MySessionStats
 
struct  proto_test
 
class  ProtoUnitTest
 
class  TlsCryptV2WkcUnwrapTest
 
class  MockCallback
 
class  EventQueueVector
 

Macros

#define OPENVPN_DEBUG
 
#define USE_TLS_CRYPT_V2
 
#define BF   0
 
#define TLS_TIMEOUT_CLIENT   2000
 
#define TLS_TIMEOUT_SERVER   2000
 
#define SIMULATE_OOO
 
#define SIMULATE_DROPPED
 
#define SIMULATE_CORRUPTED
 
#define RENEG   900
 
#define FEEDBACK   1
 
#define ITER   1000000
 
#define SITER   1
 
#define N_RETRIES   2
 
#define STRINGIZE1(x)   #x
 
#define STRINGIZE(x)   STRINGIZE1(x)
 
#define PROTO_CIPHER   "AES-128-CBC"
 
#define TLS_VER_MIN   TLSVersion::Type::UNDEF
 
#define PROTO_DIGEST   "SHA1"
 
#define COMP_METH   CompressContext::LZO_STUB
 

Functions

static auto create_client_ssl_config (Frame::Ptr frame, ClientRandomAPI::Ptr rng, bool tls_version_mismatch=false)
 
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="", bool tls_auth_only=false, bool use_dynamic_tls_crypt=false, const std::string &tls_crypt_v2_dir=TEST_KEYCERT_DIR)
 
int test (const struct proto_test &t)
 
int test_retry (const int n_retries, const struct proto_test &test_config)
 
 TEST_F (ProtoUnitTest, BaseSingleThreadTlsEkm)
 
 TEST_F (ProtoUnitTest, BaseSingleThreadNoTlsEkm)
 
 TEST_F (ProtoUnitTest, BaseSingleThreadTlsCryptV2WithEmbeddedServerkey)
 
 TEST_F (ProtoUnitTest, BaseSingleThreadTlsCryptV2WithMissingEmbeddedServerkey)
 
 TEST_F (ProtoUnitTest, BaseSingleThreadTlsCryptV2WithTlsAuthAlsoActive)
 
static void write_generated_tls_crypt_v2_keys (const std::string &dir, const std::string &client_fn, const std::uint32_t k_id, const std::string &metadata)
 Mint a tls-crypt-v2 key pair the way the deployment tooling does.
 
 TEST_F (ProtoUnitTest, BaseSingleThreadTlsCryptV2WithGeneratedKeys)
 
 TEST_F (ProtoUnitTest, BaseSingleThreadTlsCryptV2WithGeneratedKeysAndTlsAuth)
 
 TEST_F (ProtoUnitTest, TlsAuthSessionSurvivesSpoofedTlsCryptV2Opcode)
 
 TEST_F (ProtoUnitTest, DynamicTlsCryptRekeysTlsCryptV2WithServerkeyInConfig)
 
 TEST_F (ProtoUnitTest, DynamicTlsCryptRekeysTlsCryptV2WithServerkeyId)
 
 TEST_F (ProtoUnitTest, DynamicTlsCryptRekeysTlsCryptV2OnTlsAuthServerWithServerkeyInConfig)
 
 TEST_F (ProtoUnitTest, DynamicTlsCryptRekeysTlsCryptV2OnTlsAuthServerWithServerkeyId)
 
 TEST_F (ProtoUnitTest, TlsCryptV2WkcRidesFirstControlPacket)
 
 TEST_F (ProtoUnitTest, TlsCryptV2WkcLargerThanControlPayload)
 
 TEST_F (ProtoUnitTest, TlsCryptV2ControlPacketCapHonored)
 
 TEST_F (TlsCryptV2WkcUnwrapTest, RejectsWkcLenLargerThanPacket)
 
 TEST_F (TlsCryptV2WkcUnwrapTest, RejectsWkcLenSmallerThanAuthTag)
 
 TEST_F (TlsCryptV2WkcUnwrapTest, UnknownServerKeyIdIsAnErrorAndNotAnException)
 
 TEST_F (TlsCryptV2WkcUnwrapTest, StripsResentWkc)
 
 TEST_F (TlsCryptV2WkcUnwrapTest, StripRejectsWkcLenLargerThanPacket)
 
 TEST_F (TlsCryptV2WkcUnwrapTest, StripRejectsWkcLenSmallerThanClientKey)
 
 TEST_F (TlsCryptV2WkcUnwrapTest, StripRejectsWkcLeavingNoTlsCryptFrame)
 
 TEST_F (TlsCryptV2WkcUnwrapTest, StripRejectsPacketShorterThanAFrame)
 
 TEST_F (TlsCryptV2WkcUnwrapTest, StripAccountsForServerKeyId)
 
 TEST_F (ProtoUnitTest, BaseMultipleThread)
 
 TEST (Proto, IvCiphersAead)
 
 TEST (Proto, IvCiphersNonPreferred)
 
 TEST (Proto, IvCiphersLegacy)
 
 TEST (Proto, ControlmessageInvalidchar)
 
 TEST (Proto, ClientProtoCheckCcMsg)
 

Variables

const char message []
 

Detailed Description

Unit test for OpenVPN Protocol implementation (class ProtoContext)

Definition in file test_proto.cpp.

Macro Definition Documentation

◆ BF

#define BF   0

Definition at line 44 of file test_proto.cpp.

◆ COMP_METH

#define COMP_METH   CompressContext::LZO_STUB

Definition at line 162 of file test_proto.cpp.

◆ FEEDBACK

#define FEEDBACK   1

Definition at line 101 of file test_proto.cpp.

◆ ITER

#define ITER   1000000

Definition at line 110 of file test_proto.cpp.

◆ N_RETRIES

#define N_RETRIES   2

Definition at line 122 of file test_proto.cpp.

◆ OPENVPN_DEBUG

#define OPENVPN_DEBUG

Definition at line 34 of file test_proto.cpp.

◆ PROTO_CIPHER

#define PROTO_CIPHER   "AES-128-CBC"

Definition at line 144 of file test_proto.cpp.

◆ PROTO_DIGEST

#define PROTO_DIGEST   "SHA1"

Definition at line 151 of file test_proto.cpp.

◆ RENEG

#define RENEG   900

Definition at line 96 of file test_proto.cpp.

◆ SIMULATE_CORRUPTED

#define SIMULATE_CORRUPTED

Definition at line 89 of file test_proto.cpp.

◆ SIMULATE_DROPPED

#define SIMULATE_DROPPED

Definition at line 88 of file test_proto.cpp.

◆ SIMULATE_OOO

#define SIMULATE_OOO

Definition at line 87 of file test_proto.cpp.

◆ SITER

#define SITER   1

Definition at line 117 of file test_proto.cpp.

◆ STRINGIZE

#define STRINGIZE (   x)    STRINGIZE1(x)

Definition at line 136 of file test_proto.cpp.

◆ STRINGIZE1

#define STRINGIZE1 (   x)    #x

Definition at line 135 of file test_proto.cpp.

◆ TLS_TIMEOUT_CLIENT

#define TLS_TIMEOUT_CLIENT   2000

Definition at line 79 of file test_proto.cpp.

◆ TLS_TIMEOUT_SERVER

#define TLS_TIMEOUT_SERVER   2000

Definition at line 82 of file test_proto.cpp.

◆ TLS_VER_MIN

#define TLS_VER_MIN   TLSVersion::Type::UNDEF

Definition at line 145 of file test_proto.cpp.

◆ USE_TLS_CRYPT_V2

#define USE_TLS_CRYPT_V2

Definition at line 39 of file test_proto.cpp.

Function Documentation

◆ create_client_proto_context()

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 = "",
bool  tls_auth_only = false,
bool  use_dynamic_tls_crypt = false,
const std::string &  tls_crypt_v2_dir = TEST_KEYCERT_DIR 
)
static

Definition at line 904 of file test_proto.cpp.

Here is the caller graph for this function:

◆ create_client_ssl_config()

static auto create_client_ssl_config ( Frame::Ptr  frame,
ClientRandomAPI::Ptr  rng,
bool  tls_version_mismatch = false 
)
static

Create a client ssl config for testing.

Returns

Definition at line 880 of file test_proto.cpp.

Here is the caller graph for this function:

◆ test()

int test ( const struct proto_test t)

Definition at line 1027 of file test_proto.cpp.

◆ TEST() [1/5]

TEST ( Proto  ,
ClientProtoCheckCcMsg   
)

Definition at line 1943 of file test_proto.cpp.

◆ TEST() [2/5]

TEST ( Proto  ,
ControlmessageInvalidchar   
)

Definition at line 1884 of file test_proto.cpp.

◆ TEST() [3/5]

TEST ( Proto  ,
IvCiphersAead   
)

Definition at line 1800 of file test_proto.cpp.

◆ TEST() [4/5]

TEST ( Proto  ,
IvCiphersLegacy   
)

Definition at line 1838 of file test_proto.cpp.

◆ TEST() [5/5]

TEST ( Proto  ,
IvCiphersNonPreferred   
)

Definition at line 1819 of file test_proto.cpp.

◆ TEST_F() [1/25]

TEST_F ( ProtoUnitTest  ,
BaseMultipleThread   
)

Definition at line 1770 of file test_proto.cpp.

◆ TEST_F() [2/25]

TEST_F ( ProtoUnitTest  ,
BaseSingleThreadNoTlsEkm   
)

Definition at line 1377 of file test_proto.cpp.

◆ TEST_F() [3/25]

TEST_F ( ProtoUnitTest  ,
BaseSingleThreadTlsCryptV2WithEmbeddedServerkey   
)

Definition at line 1398 of file test_proto.cpp.

◆ TEST_F() [4/25]

TEST_F ( ProtoUnitTest  ,
BaseSingleThreadTlsCryptV2WithGeneratedKeys   
)

Definition at line 1455 of file test_proto.cpp.

◆ TEST_F() [5/25]

TEST_F ( ProtoUnitTest  ,
BaseSingleThreadTlsCryptV2WithGeneratedKeysAndTlsAuth   
)

Definition at line 1471 of file test_proto.cpp.

◆ TEST_F() [6/25]

TEST_F ( ProtoUnitTest  ,
BaseSingleThreadTlsCryptV2WithMissingEmbeddedServerkey   
)

Definition at line 1404 of file test_proto.cpp.

◆ TEST_F() [7/25]

TEST_F ( ProtoUnitTest  ,
BaseSingleThreadTlsCryptV2WithTlsAuthAlsoActive   
)

Definition at line 1410 of file test_proto.cpp.

◆ TEST_F() [8/25]

TEST_F ( ProtoUnitTest  ,
BaseSingleThreadTlsEkm   
)

Definition at line 1365 of file test_proto.cpp.

◆ TEST_F() [9/25]

TEST_F ( ProtoUnitTest  ,
DynamicTlsCryptRekeysTlsCryptV2OnTlsAuthServerWithServerkeyId   
)

Definition at line 1546 of file test_proto.cpp.

◆ TEST_F() [10/25]

TEST_F ( ProtoUnitTest  ,
DynamicTlsCryptRekeysTlsCryptV2OnTlsAuthServerWithServerkeyInConfig   
)

Definition at line 1535 of file test_proto.cpp.

◆ TEST_F() [11/25]

TEST_F ( ProtoUnitTest  ,
DynamicTlsCryptRekeysTlsCryptV2WithServerkeyId   
)

Definition at line 1519 of file test_proto.cpp.

◆ TEST_F() [12/25]

TEST_F ( ProtoUnitTest  ,
DynamicTlsCryptRekeysTlsCryptV2WithServerkeyInConfig   
)

Definition at line 1510 of file test_proto.cpp.

◆ TEST_F() [13/25]

TEST_F ( ProtoUnitTest  ,
TlsAuthSessionSurvivesSpoofedTlsCryptV2Opcode   
)

Definition at line 1493 of file test_proto.cpp.

◆ TEST_F() [14/25]

TEST_F ( ProtoUnitTest  ,
TlsCryptV2ControlPacketCapHonored   
)

Definition at line 1586 of file test_proto.cpp.

◆ TEST_F() [15/25]

TEST_F ( ProtoUnitTest  ,
TlsCryptV2WkcLargerThanControlPayload   
)

Definition at line 1576 of file test_proto.cpp.

◆ TEST_F() [16/25]

TEST_F ( ProtoUnitTest  ,
TlsCryptV2WkcRidesFirstControlPacket   
)

Definition at line 1564 of file test_proto.cpp.

◆ TEST_F() [17/25]

TEST_F ( TlsCryptV2WkcUnwrapTest  ,
RejectsWkcLenLargerThanPacket   
)

Definition at line 1663 of file test_proto.cpp.

◆ TEST_F() [18/25]

TEST_F ( TlsCryptV2WkcUnwrapTest  ,
RejectsWkcLenSmallerThanAuthTag   
)

Definition at line 1674 of file test_proto.cpp.

◆ TEST_F() [19/25]

TEST_F ( TlsCryptV2WkcUnwrapTest  ,
StripAccountsForServerKeyId   
)

Definition at line 1754 of file test_proto.cpp.

◆ TEST_F() [20/25]

TEST_F ( TlsCryptV2WkcUnwrapTest  ,
StripRejectsPacketShorterThanAFrame   
)

Definition at line 1746 of file test_proto.cpp.

◆ TEST_F() [21/25]

TEST_F ( TlsCryptV2WkcUnwrapTest  ,
StripRejectsWkcLeavingNoTlsCryptFrame   
)

Definition at line 1737 of file test_proto.cpp.

◆ TEST_F() [22/25]

TEST_F ( TlsCryptV2WkcUnwrapTest  ,
StripRejectsWkcLenLargerThanPacket   
)

Definition at line 1720 of file test_proto.cpp.

◆ TEST_F() [23/25]

TEST_F ( TlsCryptV2WkcUnwrapTest  ,
StripRejectsWkcLenSmallerThanClientKey   
)

Definition at line 1728 of file test_proto.cpp.

◆ TEST_F() [24/25]

TEST_F ( TlsCryptV2WkcUnwrapTest  ,
StripsResentWkc   
)

Definition at line 1712 of file test_proto.cpp.

◆ TEST_F() [25/25]

TEST_F ( TlsCryptV2WkcUnwrapTest  ,
UnknownServerKeyIdIsAnErrorAndNotAnException   
)

Definition at line 1694 of file test_proto.cpp.

◆ test_retry()

int test_retry ( const int  n_retries,
const struct proto_test test_config 
)

Definition at line 1322 of file test_proto.cpp.

Here is the caller graph for this function:

◆ write_generated_tls_crypt_v2_keys()

static void write_generated_tls_crypt_v2_keys ( const std::string &  dir,
const std::string &  client_fn,
const std::uint32_t  k_id,
const std::string &  metadata 
)
static

Mint a tls-crypt-v2 key pair the way the deployment tooling does.

Parameters
dirDirectory to write both keys to; created if absent.
client_fnBasename for the client key file.
k_idServer key ID to name the server key by.
metadataMetadata to embed in the client key's WKc.

Definition at line 1424 of file test_proto.cpp.

Here is the caller graph for this function:

Variable Documentation

◆ message

const char message[]
Initial value:
= "Message _->_ 0000000000 It was a bright cold day in April, and the clocks\n"
"were striking thirteen. Winston Smith, his chin nuzzled\n"
"into his breast in an effort to escape the vile wind,\n"
"slipped quickly through the glass doors of Victory\n"
"Mansions, though not quickly enough to prevent a\n"
"swirl of gritty dust from entering along with him.\n"

Definition at line 237 of file test_proto.cpp.