61 unsigned char c[slab_size_];
81 const std::string tls_key_fn = UNITTEST_SOURCE_DIR
"/input/psid_cookie_tls.key";
82 pcfg->tls_auth_key.parse_from_file(tls_key_fn);
86 pcfg->handshake_window = Time::Duration::seconds(60);
87 pcfg->key_direction = 0;
92 spf->proto_context_config =
pcfg;
105 now += Time::Duration::binary_ms(binary_ms);
124 ASSERT_NE(pci_dut,
nullptr);
128 EXPECT_TRUE(start == *pci_dut->
now_);
151 EXPECT_TRUE(hmac_ok);
153 advance_clock(interval);
156 EXPECT_TRUE(hmac_ok);
158 advance_clock(interval);
161 EXPECT_FALSE(hmac_ok);
178 std::uint32_t acked_pktid_be,
179 std::uint32_t own_pktid_be,
180 unsigned char ack_count,
181 unsigned char op_field)
194 buf.
prepend(&own_pktid_be,
sizeof(own_pktid_be));
196 buf.
prepend(&acked_pktid_be,
sizeof(acked_pktid_be));
235 auto f = make_fixture();
243 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
244 EXPECT_TRUE(pcookie_impl->get_cookie_psid().match(
f.cookie_psid));
251 auto f = make_fixture();
259 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
264 auto f = make_fixture();
272 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::DROP_2ND);
277 auto f = make_fixture();
285 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
290 auto f = make_fixture();
298 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::DROP_2ND);
303 auto f = make_fixture();
311 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::DROP_2ND);
320 auto f = make_fixture();
328 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::HANDLE_2ND);
333 auto f = make_fixture();
341 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::EARLY_DROP);
346 auto f = make_fixture();
351 bogus.
randomize(*pcookie_impl->pcfg_.rng);
360 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::DROP_2ND);
365 auto f = make_fixture();
375 EXPECT_EQ(pcookie_impl->intercept(pkt,
f.cli_addr), PsidCookie::Intercept::DROP_2ND);
static constexpr size_t slab_size_
ClientAddressMock(RandomAPI &prng)
union ClientAddressMock::@122 addrport_
const unsigned char * get_abstract_cli_addrport(size_t &slab_size) const override
virtual ~ClientAddressMock()=default
const void * get_impl_info() const 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)
Time advance_clock(uint64_t binary_ms)
Time set_clock(Time setting)
ProtoContext::ProtoConfig::Ptr pcfg
ServerProto::Factory::Ptr spf
openvpn_io::io_context dummy_io_context
std::unique_ptr< PsidCookieImpl > pcookie_impl
void reset(const size_t min_capacity, const BufferFlags flags=BufAllocFlags::NO_FLAGS)
Resets the buffer with the specified minimum capacity and flags.
T * prepend_alloc(const size_t size)
Allocate space for prepending 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.
void push_front(const T &value)
Append a T object to the array, with possible resize.
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)
Time::Duration handshake_window
OpenVPNStaticKey tls_auth_key
leave this undefined to disable tls_auth
static unsigned char op_compose(const unsigned int opcode, const unsigned int key_id)
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 integrate this component into the server implementation.
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.
base_type seconds_since_epoch() const
constexpr BufferFlags GROW(1U<< 2)
if enabled, buffer will grow (otherwise buffer_full exception will be thrown)
Type lookup(const std::string &name)
ProtoSessionID cookie_psid
ClientAddressMock cli_addr
static constexpr size_t idsize
TEST_F(PsidCookieTest, CheckSetup)