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 <openvpn/common/exception.hpp>
#include <openvpn/common/file.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)
 
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)
 
 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 
)
static

Definition at line 923 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 895 of file test_proto.cpp.

Here is the caller graph for this function:

◆ test()

int test ( const struct proto_test t)

Definition at line 1042 of file test_proto.cpp.

◆ TEST() [1/5]

TEST ( Proto  ,
ClientProtoCheckCcMsg   
)

Definition at line 1886 of file test_proto.cpp.

◆ TEST() [2/5]

TEST ( Proto  ,
ControlmessageInvalidchar   
)

Definition at line 1827 of file test_proto.cpp.

◆ TEST() [3/5]

TEST ( Proto  ,
IvCiphersAead   
)

Definition at line 1743 of file test_proto.cpp.

◆ TEST() [4/5]

TEST ( Proto  ,
IvCiphersLegacy   
)

Definition at line 1781 of file test_proto.cpp.

◆ TEST() [5/5]

TEST ( Proto  ,
IvCiphersNonPreferred   
)

Definition at line 1762 of file test_proto.cpp.

◆ TEST_F() [1/23]

TEST_F ( ProtoUnitTest  ,
BaseMultipleThread   
)

Definition at line 1713 of file test_proto.cpp.

◆ TEST_F() [2/23]

TEST_F ( ProtoUnitTest  ,
BaseSingleThreadNoTlsEkm   
)

Definition at line 1392 of file test_proto.cpp.

◆ TEST_F() [3/23]

TEST_F ( ProtoUnitTest  ,
BaseSingleThreadTlsCryptV2WithEmbeddedServerkey   
)

Definition at line 1413 of file test_proto.cpp.

◆ TEST_F() [4/23]

TEST_F ( ProtoUnitTest  ,
BaseSingleThreadTlsCryptV2WithMissingEmbeddedServerkey   
)

Definition at line 1419 of file test_proto.cpp.

◆ TEST_F() [5/23]

TEST_F ( ProtoUnitTest  ,
BaseSingleThreadTlsCryptV2WithTlsAuthAlsoActive   
)

Definition at line 1425 of file test_proto.cpp.

◆ TEST_F() [6/23]

TEST_F ( ProtoUnitTest  ,
BaseSingleThreadTlsEkm   
)

Definition at line 1380 of file test_proto.cpp.

◆ TEST_F() [7/23]

TEST_F ( ProtoUnitTest  ,
DynamicTlsCryptRekeysTlsCryptV2OnTlsAuthServerWithServerkeyId   
)

Definition at line 1489 of file test_proto.cpp.

◆ TEST_F() [8/23]

TEST_F ( ProtoUnitTest  ,
DynamicTlsCryptRekeysTlsCryptV2OnTlsAuthServerWithServerkeyInConfig   
)

Definition at line 1478 of file test_proto.cpp.

◆ TEST_F() [9/23]

TEST_F ( ProtoUnitTest  ,
DynamicTlsCryptRekeysTlsCryptV2WithServerkeyId   
)

Definition at line 1462 of file test_proto.cpp.

◆ TEST_F() [10/23]

TEST_F ( ProtoUnitTest  ,
DynamicTlsCryptRekeysTlsCryptV2WithServerkeyInConfig   
)

Definition at line 1453 of file test_proto.cpp.

◆ TEST_F() [11/23]

TEST_F ( ProtoUnitTest  ,
TlsAuthSessionSurvivesSpoofedTlsCryptV2Opcode   
)

Definition at line 1436 of file test_proto.cpp.

◆ TEST_F() [12/23]

TEST_F ( ProtoUnitTest  ,
TlsCryptV2ControlPacketCapHonored   
)

Definition at line 1529 of file test_proto.cpp.

◆ TEST_F() [13/23]

TEST_F ( ProtoUnitTest  ,
TlsCryptV2WkcLargerThanControlPayload   
)

Definition at line 1519 of file test_proto.cpp.

◆ TEST_F() [14/23]

TEST_F ( ProtoUnitTest  ,
TlsCryptV2WkcRidesFirstControlPacket   
)

Definition at line 1507 of file test_proto.cpp.

◆ TEST_F() [15/23]

TEST_F ( TlsCryptV2WkcUnwrapTest  ,
RejectsWkcLenLargerThanPacket   
)

Definition at line 1606 of file test_proto.cpp.

◆ TEST_F() [16/23]

TEST_F ( TlsCryptV2WkcUnwrapTest  ,
RejectsWkcLenSmallerThanAuthTag   
)

Definition at line 1617 of file test_proto.cpp.

◆ TEST_F() [17/23]

TEST_F ( TlsCryptV2WkcUnwrapTest  ,
StripAccountsForServerKeyId   
)

Definition at line 1697 of file test_proto.cpp.

◆ TEST_F() [18/23]

TEST_F ( TlsCryptV2WkcUnwrapTest  ,
StripRejectsPacketShorterThanAFrame   
)

Definition at line 1689 of file test_proto.cpp.

◆ TEST_F() [19/23]

TEST_F ( TlsCryptV2WkcUnwrapTest  ,
StripRejectsWkcLeavingNoTlsCryptFrame   
)

Definition at line 1680 of file test_proto.cpp.

◆ TEST_F() [20/23]

TEST_F ( TlsCryptV2WkcUnwrapTest  ,
StripRejectsWkcLenLargerThanPacket   
)

Definition at line 1663 of file test_proto.cpp.

◆ TEST_F() [21/23]

TEST_F ( TlsCryptV2WkcUnwrapTest  ,
StripRejectsWkcLenSmallerThanClientKey   
)

Definition at line 1671 of file test_proto.cpp.

◆ TEST_F() [22/23]

TEST_F ( TlsCryptV2WkcUnwrapTest  ,
StripsResentWkc   
)

Definition at line 1655 of file test_proto.cpp.

◆ TEST_F() [23/23]

TEST_F ( TlsCryptV2WkcUnwrapTest  ,
UnknownServerKeyIdIsAnErrorAndNotAnException   
)

Definition at line 1637 of file test_proto.cpp.

◆ test_retry()

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

Definition at line 1337 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 252 of file test_proto.cpp.