65 unsigned char c[slab_size_];
87 const std::string tls_key_fn = UNITTEST_SOURCE_DIR
"/input/psid_cookie_tls.key";
88 pcfg->tls_auth_key.parse_from_file(tls_key_fn);
92 pcfg->handshake_window = Time::Duration::seconds(60);
93 pcfg->key_direction = 0;
98 spf->proto_context_config =
pcfg;
111 now += Time::Duration::binary_ms(binary_ms);
130 ASSERT_NE(pci_dut,
nullptr);
134 EXPECT_TRUE(start == *pci_dut->
now_);
157 EXPECT_TRUE(hmac_ok);
159 advance_clock(interval);
162 EXPECT_TRUE(hmac_ok);
164 advance_clock(interval);
167 EXPECT_FALSE(hmac_ok);
184 std::uint32_t acked_pktid_be,
185 std::uint32_t own_pktid_be,
186 unsigned char ack_count,
187 unsigned char op_field)
200 buf.
prepend(&own_pktid_be,
sizeof(own_pktid_be));
202 buf.
prepend(&acked_pktid_be,
sizeof(acked_pktid_be));
241 auto f = make_fixture();
249 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
250 EXPECT_TRUE(pcookie_impl->get_cookie_psid().match(
f.cookie_psid));
257 auto f = make_fixture();
265 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
270 auto f = make_fixture();
278 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::DROP_2ND);
283 auto f = make_fixture();
291 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
296 auto f = make_fixture();
304 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::DROP_2ND);
309 auto f = make_fixture();
317 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::DROP_2ND);
326 auto f = make_fixture();
334 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
339 auto f = make_fixture();
347 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::EARLY_DROP);
352 auto f = make_fixture();
357 bogus.
randomize(*pcookie_impl->pcfg_.rng);
366 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::DROP_2ND);
371 auto f = make_fixture();
381 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::DROP_2ND);
451 pcfg.set_tls_crypt_algs();
452 pcfg.tls_crypt_ = ProtoContext::ProtoConfig::TLSCrypt::V2;
453 pcfg.tls_crypt_v2_serverkey_id =
true;
454 pcfg.tls_crypt_v2_serverkey_dir = UNITTEST_SOURCE_DIR
"/../ssl";
459 server_key.
parse(
read_text(UNITTEST_SOURCE_DIR
"/../ssl/06/063FE634.key"));
465 SSLLib::SSLAPI::Config::Ptr sslcfg(
new SSLLib::SSLAPI::Config());
467 sslcfg->set_frame(
pcfg.frame);
468 sslcfg->set_rng(
pcfg.rng);
469 sslcfg->load_ca(
read_text(UNITTEST_SOURCE_DIR
"/../ssl/ca.crt"),
true);
470 sslcfg->load_cert(
read_text(UNITTEST_SOURCE_DIR
"/../ssl/server.crt"));
471 sslcfg->load_private_key(
read_text(UNITTEST_SOURCE_DIR
"/../ssl/server.key"));
472 pcfg.ssl_factory = sslcfg->new_factory();
511 const std::string &metadata,
516 const size_t hmac_size =
pcfg.tls_crypt_context->digest_size();
520 wrap->
init(
pcfg.ssl_factory->libctx(),
526 inner.
write(kc, kc_size);
527 if (!metadata.empty())
529 inner.
push_back(
static_cast<unsigned char>(metadata_type));
530 inner.
write(metadata.c_str(), metadata.size());
534 const bool with_k_id =
pcfg.tls_crypt_v2_serverkey_id;
536 const size_t k_id_size = with_k_id ?
sizeof(k_id_be) : 0;
539 const std::uint16_t wkc_len =
static_cast<std::uint16_t
>(
sizeof(std::uint16_t) + hmac_size
540 + inner.
size() + k_id_size);
541 const std::uint16_t wkc_len_be = htons(wkc_len);
545 hmac_input.
write(&wkc_len_be,
sizeof(wkc_len_be));
547 hmac_input.
write(&k_id_be,
sizeof(k_id_be));
555 const size_t ciphertext_bytes = wrap->
encrypt(tag,
556 wkc.
data() + hmac_size,
562 wkc.
write(&k_id_be,
sizeof(k_id_be));
563 wkc.
write(&wkc_len_be,
sizeof(wkc_len_be));
576 unsigned char op_field)
587 unsigned char op_field,
588 std::uint32_t own_pktid_be)
591 const size_t hmac_size =
pcfg.tls_crypt_context->digest_size();
595 send->
init(
pcfg.ssl_factory->libctx(),
603 const std::uint32_t acked_pktid_be = 0;
604 payload.
write(&acked_pktid_be,
sizeof(acked_pktid_be));
605 cookie_psid.
write(payload);
606 payload.
write(&own_pktid_be,
sizeof(own_pktid_be));
611 work.prepend_alloc(hmac_size);
615 work.push_front(op_field);
621 work.data() + data_offset,
622 work.max_size() - data_offset,
625 work.inc_size(encrypt_bytes);
642 std::uint32_t own_pktid_be = 0)
645 pcookie_impl->pcfg_.prng->rand_bytes(kc_raw,
sizeof(kc_raw));
647 std::memcpy(kc.
raw_alloc(), kc_raw,
sizeof(kc_raw));
655 wrap_wkc(kc_raw,
"v=1,type=external", 0x00),
679 pkt.
write(&early_neg_be,
sizeof(early_neg_be));
680 const std::uint32_t pid_time_be = 0;
681 pkt.
write(&pid_time_be,
sizeof(pid_time_be));
684 while (pkt.
size() < frame_size)
716 auto f = make_fixture();
719 make_wkc(
"v=1,type=external"),
722 const size_t wire_size = pkt.
size();
725 ASSERT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
727 EXPECT_EQ(pkt.
size(), wire_size);
731 EXPECT_LT(pkt.
size(), wire_size);
739 auto f = make_fixture();
742 make_wkc(
"v=1,type=external"),
745 ASSERT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
749 EXPECT_TRUE(pcookie_impl->pcfg_.tls_crypt_v2_serverkey_id);
750 EXPECT_FALSE(pcookie_impl->pcfg_.tls_crypt_key.defined());
751 EXPECT_FALSE(spf->clone_proto_config()->tls_crypt_key.defined());
798 void error(
const size_t type,
const std::string *text =
nullptr)
override
848 auto f = make_fixture();
851 make_wkc(
"v=1,type=external"),
854 ASSERT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
856 ASSERT_EQ(meta_factory->n_created, 0u);
859 EXPECT_GT(session.
recv(pkt), 0u);
862 EXPECT_EQ(meta_factory->n_created, 1u);
863 EXPECT_EQ(meta_factory->last->n_calls, 1u);
868 auto f = make_fixture();
869 const std::string metadata =
"v=1,type=external,sn=04:e3,time=1750000000,tenant=acme";
876 ASSERT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
877 EXPECT_TRUE(pcookie_impl->get_cookie_psid().match(
f.cookie_psid));
881 ASSERT_GT(session.
recv(pkt), 0u);
883 ASSERT_EQ(meta_factory->n_created, 1u);
884 ASSERT_TRUE(meta_factory->last);
885 EXPECT_EQ(meta_factory->last->n_calls, 1u);
886 EXPECT_EQ(meta_factory->last->type_seen, 0x00);
887 EXPECT_EQ(meta_factory->last->payload_seen, metadata);
895 auto f = make_fixture();
898 make_wkc(
"v=1,type=external"),
901 ASSERT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
904 pkt.
data()[pkt.
size() - 32] ^= 0x01;
907 EXPECT_EQ(session.
recv(pkt), 0u);
921 pcfg.tls_crypt_v2_serverkey_id =
false;
922 pcfg.tls_crypt_v2_serverkey_dir.clear();
933 auto f = make_fixture();
936 make_wkc(
"v=1,type=external"),
939 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
946 auto f = make_fixture();
949 make_wkc(
"v=1,type=external"),
952 ASSERT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
955 EXPECT_GT(session.
recv(pkt), 0u);
956 EXPECT_EQ(meta_factory->n_created, 1u);
966 auto f = make_fixture();
972 wrap_wkc(client_key_raw_,
"", 0x00, short_kc),
976 ASSERT_NO_THROW(ret = pcookie_impl->intercept(pkt,
f.cli_addr));
977 EXPECT_NE(ret, PsidCookie::Intercept::HANDLE_2ND);
984 wrap_wkc(client_key_raw_,
"", 0x00, short_kc),
1000 pcookie_impl->provide_psid_cookie_transport(transport);
1002 auto f = make_fixture();
1003 BufferAllocated pkt = build_first_packet_tls_crypt_v2(
f.cli_psid, make_wkc(
"v=1,type=external"));
1005 const size_t wire_size = pkt.
size();
1008 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::HANDLE_1ST);
1009 EXPECT_EQ(transport->n_sent, 1u);
1011 EXPECT_EQ(pkt.
size(), wire_size);
1035 auto f = make_fixture();
1038 make_wkc(
"v=1,type=external"),
1041 ASSERT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
1051 EXPECT_GT(session.
recv(pkt), 0u);
1059 auto f = make_fixture();
1062 make_wkc(
"v=1,type=external"),
1065 ASSERT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
1068 ASSERT_TRUE(pcookie_impl->pcfg_.tls_auth_enabled());
1078 EXPECT_GT(session.
recv(pkt), 0u);
1085 auto f = make_fixture();
1088 make_wkc(
"v=1,type=external"),
1089 control_v1_op_field());
1112 pcfg.tls_auth_key.erase();
1113 pcfg.tls_crypt_ = ProtoContext::ProtoConfig::TLSCrypt::V1;
1114 pcfg.tls_crypt_v2_serverkey_id =
false;
1115 pcfg.tls_crypt_v2_serverkey_dir.clear();
1131 auto f = make_fixture();
1135 other_psid.
randomize(*pcookie_impl->pcfg_.rng);
1145 EXPECT_TRUE(
validate(v1_packet(other_psid,
f.cookie_psid)));
1146 EXPECT_TRUE(
validate(v1_packet(
f.cli_psid,
f.cookie_psid)));
1160 pcfg.tls_crypt_ = ProtoContext::ProtoConfig::TLSCrypt::None;
1161 pcfg.tls_crypt_key.erase();
1162 pcfg.tls_crypt_v2_serverkey_id =
false;
1163 pcfg.tls_crypt_v2_serverkey_dir.clear();
1171 auto f = make_fixture();
1193 auto f = make_fixture();
1195 for (
size_t size = 1; size <= 96; ++size)
1210 ASSERT_NO_THROW(ret = pcookie_impl->intercept(pkt,
f.cli_addr)) <<
"size " << size;
1211 EXPECT_NE(ret, PsidCookie::Intercept::HANDLE_2ND) <<
"size " << size;
1221 auto f = make_fixture();
1224 make_wkc(
"v=1,type=external"),
1227 ASSERT_EQ(pcookie_impl->intercept(good,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
1233 pcookie_impl->pcfg_.prng->rand_bytes(foreign_key_raw,
sizeof(foreign_key_raw));
1236 wrap_wkc(foreign_key_raw,
"v=1,type=external", 0x00),
1240 EXPECT_EQ(session.
recv(spoofed), 0u);
1243 EXPECT_GT(session.
recv(good), 0u);
1253 auto f = make_fixture();
1256 make_wkc(
"v=1,type=external"),
1259 ASSERT_EQ(pcookie_impl->intercept(good,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
1262 bogus_cookie_psid.
randomize(*pcookie_impl->pcfg_.rng);
1265 EXPECT_EQ(session.
recv(build_foreign_third_packet(bogus_cookie_psid)), 0u);
1268 EXPECT_GT(session.
recv(good), 0u);
1277 auto f = make_fixture();
1280 make_wkc(
"v=1,type=external"),
1283 ASSERT_EQ(pcookie_impl->intercept(good,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
1288 session.
recv(wrap_third_packet(client_key_,
1291 make_wkc(
"v=1,type=external"),
1299 control_v1_op_field(),
1302 session.
recv(no_wkc);
1314 auto f = make_fixture();
1317 make_wkc(
"v=1,type=external"),
1322 EXPECT_GT(session.
recv(pkt), 0u);
1324 EXPECT_EQ(meta_factory->n_created, 1u);
1325 EXPECT_EQ(meta_factory->last->n_calls, 1u);
1333 auto f = make_fixture();
1337 pcookie_impl->pcfg_.prng->rand_bytes(foreign_key_raw,
sizeof(foreign_key_raw));
1340 wrap_wkc(foreign_key_raw,
"v=1,type=ATTACKER", 0x00),
1345 EXPECT_EQ(session.
recv(spoofed), 0u);
1346 EXPECT_EQ(meta_factory->n_created, 0u);
1349 EXPECT_EQ(session.
recv(spoofed), 0u);
1350 EXPECT_EQ(meta_factory->n_created, 0u);
1351 EXPECT_FALSE(meta_factory->last);
1356 make_wkc(
"v=1,type=external"),
1358 EXPECT_GT(session.
recv(good), 0u);
1359 EXPECT_EQ(meta_factory->n_created, 1u);
1360 EXPECT_EQ(meta_factory->last->payload_seen,
"v=1,type=external");
1368 auto f = make_fixture();
1371 make_wkc(
"v=1,type=external"),
1374 pcookie_impl->pcfg_.tls_crypt_metadata_factory.reset();
1375 ASSERT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
1378 EXPECT_GT(session.
recv(pkt), 0u);
1379 EXPECT_EQ(meta_factory->n_created, 0u);
1386 auto f = make_fixture();
1389 make_wkc(std::string(
"\x68\x74\x9f\x00", 4), 0x01),
1392 ASSERT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
1395 ASSERT_GT(session.
recv(pkt), 0u);
1397 ASSERT_TRUE(meta_factory->last);
1398 EXPECT_EQ(meta_factory->last->n_calls, 1u);
1399 EXPECT_EQ(meta_factory->last->type_seen, 0x01);
1404 auto f = make_fixture();
1410 ASSERT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
1413 ASSERT_GT(session.
recv(pkt), 0u);
1415 ASSERT_TRUE(meta_factory->last);
1416 EXPECT_EQ(meta_factory->last->n_calls, 1u);
1417 EXPECT_EQ(meta_factory->last->type_seen, -1);
1425 auto f = make_fixture();
1427 bogus.
randomize(*pcookie_impl->pcfg_.rng);
1431 make_wkc(
"v=1,type=external"),
1434 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::DROP_2ND);
1436 EXPECT_EQ(meta_factory->n_created, 0u);
1437 EXPECT_FALSE(meta_factory->last);
1445 auto f = make_fixture();
1446 meta_factory->accept =
false;
1450 make_wkc(
"v=1,type=external"),
1454 ASSERT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
1457 EXPECT_EQ(session.
recv(pkt), 0u);
1458 EXPECT_EQ(session.
rec->
names,
"TLS_CRYPT_META_FAIL");
static constexpr size_t slab_size_
ClientAddressMock(RandomAPI &prng)
union ClientAddressMock::@119 addrport_
const unsigned char * get_abstract_cli_addrport(size_t &slab_size) const override
virtual ~ClientAddressMock()=default
const void * get_impl_info() const override
A ProtoContext needs one of these; it counts what the session puts on the wire.
bool supports_epoch_data() override
void control_net_send(const Buffer &net_buf) override
void active(bool primary) override
Called when KeyContext transitions to ACTIVE state.
void control_recv(BufferPtr &&app_bp) override
BufferAllocated build_third_packet_tls_auth(const ProtoSessionID &cli_psid, const ProtoSessionID &cookie_psid, std::uint32_t acked_pktid_be, std::uint32_t own_pktid_be, unsigned char ack_count, unsigned char op_field)
A server with one tls-crypt-v2 key in its config for every client.
PsidCookieSingleServerKeyTest()
Time advance_clock(uint64_t binary_ms)
Time set_clock(Time setting)
ProtoContext::ProtoConfig::Ptr pcfg
ServerProto::Factory::Ptr spf
the server factory each session's ProtoConfig is cloned from
openvpn_io::io_context dummy_io_context
std::unique_ptr< PsidCookieImpl > pcookie_impl
A server holding a tls-crypt-v2 key and no tls-auth one.
PsidCookieTlsCryptV2OnlyTest()
Tests for the tls-crypt-v2 arm of intercept()
static unsigned char control_v1_op_field()
the opcode of the packets that follow, which carry no WKc to key a session from
BufferAllocated wrap_third_packet(const OpenVPNStaticKey &kc, const ProtoSessionID &cli_psid, const ProtoSessionID &cookie_psid, const BufferAllocated &wkc, unsigned char op_field, std::uint32_t own_pktid_be)
BufferAllocated make_wkc(const std::string &metadata, int metadata_type=0x00)
Build the WKc a client appends to its handshake packets.
OpenVPNStaticKey server_key_
Ka/Ke, used here to wrap the WKc.
static unsigned char wkc_v1_op_field()
the opcode of the third packet, the one whose WKc keys the session behind it
BufferAllocated build_third_packet_tls_crypt_v2(const ProtoSessionID &cli_psid, const ProtoSessionID &cookie_psid, const BufferAllocated &wkc, unsigned char op_field)
Build the tls-crypt-v2 third packet of the 3-way handshake: a CONTROL_WKC_V1 wrapped with Kc,...
RCPtr< MetadataRecorderFactory > meta_factory
OpenVPNStaticKey client_key_
Kc, as the client keys its tls-crypt instance.
BufferAllocated wrap_wkc(const unsigned char *kc, const std::string &metadata, int metadata_type, size_t kc_size=OpenVPNStaticKey::KEY_SIZE)
BufferAllocated build_first_packet_tls_crypt_v2(const ProtoSessionID &cli_psid, const BufferAllocated &wkc)
Build the tls-crypt-v2 first handshake packet: a CONTROL_HARD_RESET_CLIENT_V3 with the WKc behind the...
PsidCookieTlsCryptV2Test()
unsigned char client_key_raw_[OpenVPNStaticKey::KEY_SIZE]
BufferAllocated build_foreign_third_packet(const ProtoSessionID &cookie_psid, std::uint32_t own_pktid_be=0)
The handshake packet a client of this server can forge for another's address.
static constexpr std::uint32_t SERVER_KEY_ID
K_id of test/ssl/06/063FE634.key, the server key the WKc names.
Names every error the session reports, so a test can say why a packet was dropped.
void error(const size_t type, const std::string *text=nullptr) override
Stands in for the transport the cookie layer answers a first packet through.
bool psid_cookie_send_const(Buffer &send_buf, const PsidCookieAddrInfoBase &pcaib) override
A plain tls-auth server: no tls-crypt of either version.
A tls-crypt v1 server: one key shared with every client, no tls-auth, no WKc.
BufferAllocated v1_packet(const ProtoSessionID &cli_psid, const ProtoSessionID &srv_psid)
A CONTROL_V1 frame from cli_psid, wrapped with the shared key and echoing srv_psid.
void reset(const size_t min_capacity, const BufferFlags flags=BufAllocFlags::NO_FLAGS)
Resets the buffer with the specified minimum capacity and flags.
const T * c_data() const
Returns a const pointer to the start of the buffer.
T * prepend_alloc(const size_t size)
Allocate space for prepending data to the buffer.
void inc_size(const size_t delta)
Increment the size of the array (usually used in a similar context to set_size such as after mutable_...
size_t max_size() const
Return the maximum allowable size value in T objects given the current offset (without considering re...
void push_back(const T &value)
Append a T object to the end of the array, resizing the array if necessary.
T * write_alloc(const size_t size)
Allocate space for writing data to the buffer.
void prepend(const T *data, const size_t size)
Prepend data to the buffer.
size_t size() const
Returns the size of the buffer in T objects.
T * data()
Get a mutable pointer to the start of the array.
bool empty() const
Returns true if the buffer is empty.
void write(const T *data, const size_t size)
Write data to the buffer.
void push_front(const T &value)
Append a T object to the array, with possible resize.
void set_size(const size_t size)
After an external method, operating on the array as a mutable unsigned char buffer,...
unsigned char * raw_alloc()
StaticKey slice(unsigned int key_specifier) const
virtual void ovpn_hmac_gen(unsigned char *data, const size_t data_size, const size_t l1, const size_t l2, const size_t l3)=0
virtual size_t output_size() const =0
void write_next(Buffer &buf, const bool prepend, const PacketIDControl::time_t now)
static bool strip_resent_wkc(Buffer &recv, const ProtoConfig &proto_config)
Virtually remove a resent WKc from the end of a CONTROL_WKC_V1 packet.
static size_t tls_crypt_frame_size(const ProtoConfig &proto_config)
Smallest tls-crypt frame a WKc can be appended to.
static Error::Type unwrap_tls_crypt_wkc(Buffer &recv, const ProtoConfig &proto_config, TLSCryptInstance &tls_crypt_server, UnwrappedWkc &unwrapped)
Extract and process the TLS crypt WKc information.
Time::Duration handshake_window
OpenVPNStaticKey tls_auth_key
leave this undefined to disable tls_auth
bool control_net_recv(const PacketType &type, BufferPtr &&net_bp)
void flush(const bool control_channel)
PacketType packet_type(const Buffer &buf)
@ CONTROL_HARD_RESET_CLIENT_V3
static unsigned char op_compose(const unsigned int opcode, const unsigned int key_id)
bool control_net_validate(const PacketType &type, const Buffer &net_buf)
static constexpr PacketIDControl::id_t EARLY_NEG_START
void reset(const ProtoSessionID cookie_psid=ProtoSessionID())
Resets ProtoContext *this to it's initial state.
void start(const ProtoSessionID cookie_psid=ProtoSessionID())
Initialize the state machine and start protocol negotiation.
void write(Buffer &buf) const
void randomize(StrongRandomAPI &rng)
void prepend(Buffer &buf) const
Interface to communicate the server's address semantics.
Implements the PsidCookie interface.
OvpnHMACInstance::Ptr ta_hmac_recv_
bool check_session_id_hmac(const ProtoSessionID &srv_psid, const ProtoSessionID &cli_psid, const PsidCookieAddrInfoBase &pcaib)
static constexpr int SID_SIZE
ProtoContext::ProtoConfig & pcfg_
ProtoSessionID calculate_session_id_hmac(const ProtoSessionID &cli_psid, const PsidCookieAddrInfoBase &pcaib, unsigned int offset)
Calculate the psid cookie, the ProtoSessionID hmac.
static void pre_threading_setup()
static constexpr int OPCODE_SIZE
Interface to provide access to the server's transport capability.
Interface to integrate this component into the server implementation.
Intercept
Values returned by the intercept() function.
void reset() noexcept
Points this RCPtr<T> to nullptr safely.
T * get() const noexcept
Returns the raw pointer to the object T, or nullptr.
Abstract base class for random number generators.
void rand_fill(T &obj)
Fill a data object with random bytes.
static Ptr Create(ArgsT &&...args)
Creates a new instance of RcEnable with the given arguments.
constexpr static const size_t hmac_offset
virtual bool hmac_gen(unsigned char *header, const size_t header_len, const unsigned char *payload, const size_t payload_len)=0
virtual size_t encrypt(const unsigned char *iv, unsigned char *out, const size_t olen, const unsigned char *in, const size_t ilen)=0
virtual void init(SSLLib::Ctx libctx, const StaticKey &key_hmac, const StaticKey &key_crypt)=0
void extract_key(OpenVPNStaticKey &tls_key)
void parse(const std::string &key_text)
base_type seconds_since_epoch() const
void work(openvpn_io::io_context &io_context, ThreadCommon &tc, MyRunContext &runctx, const unsigned int unit)
constexpr BufferFlags GROW(1U<< 2)
if enabled, buffer will grow (otherwise buffer_full exception will be thrown)
constexpr BufferFlags CONSTRUCT_ZERO(1U<< 0)
if enabled, constructors/init will zero allocated space
Type lookup(const std::string &name)
const char * name(const size_t type)
Frame::Ptr frame_init_simple(const size_t payload)
std::string read_text(const std::string &filename, const std::uint64_t max_size=0)
BufferAllocatedType< unsigned char > BufferAllocated
std::string buf_to_string(const Buffer &buf)
The session kotun.hpp creates once intercept() has returned HANDLE_2ND.
CookieSession(const ProtoContext::ProtoConfig::Ptr &cfg, const ProtoSessionID &cookie_psid)
RCPtr< RecordingStats > rec
size_t recv(const BufferAllocated &pkt)
ProtoSessionID cookie_psid
ClientAddressMock cli_addr
static constexpr size_t idsize
What a WKc yields, owned by whoever asked for the unwrap.
OpenVPNStaticKey client_key
Kc, the client key the WKc wrapped.
TEST_F(PsidCookieTest, CheckSetup)
void validate(const ValidateCreds::Type type, const bool expected_result, const std::string &cred, const bool strict)