57 :
pcfg_(*psfp->proto_context_config),
102 return is_tls_crypt_v2
128 pctb_ = std::move(pctb);
138 template <
typename Buf>
142 buf.read(&net_id,
sizeof(net_id));
143 return ntohl(net_id) <= 1;
152 template <
typename Buf>
156 bool has_own_pktid =
true)
192 static const size_t reqd_packet_size
197 if (pkt_buf.
size() < reqd_packet_size)
208 recv_buf_copy.
advance(hmac_size);
211 cli_auth_pktid.
read(recv_buf_copy);
213 uint8_t cli_net_id[4];
215 recv_buf_copy.
read(cli_net_id,
sizeof(cli_net_id));
225 send_buf.
prepend(
static_cast<const void *
>(&net_id),
sizeof(net_id));
229 send_buf.
prepend(cli_net_id,
sizeof(cli_net_id));
282 if (pkt_buf.
size() < reqd_packet_size)
293 recv_buf_copy.
advance(hmac_size);
296 cli_auth_pktid.
read(recv_buf_copy);
314 if (pkt_buf.
size() < reqd_packet_size)
323 replay_packet_id.
read(recv_buf_copy);
345 packet_id.write(payload,
true);
347 client_session_id.
prepend(payload);
350 payload.
prepend(&acked_packet_id,
sizeof(acked_packet_id));
357 work.prepend_alloc(hmac_size);
375 work.data() + data_offset,
376 work.max_size() - data_offset,
379 work.inc_size(encrypt_bytes);
406 const unsigned char *orig_data = work_buf.
c_data();
417 const size_t decrypt_bytes = recv->
decrypt(orig_data + head_size,
421 recv_buf_copy.
size());
425 work.inc_size(decrypt_bytes);
433 if (
work.size() < reqd_decrypted_size)
485 uint32_t valid_time =
static_cast<uint32_t
>(
now_->
raw() / interval - offset);
487 hmac_ctx_.update(
reinterpret_cast<const unsigned char *
>(&valid_time),
492 size_t cli_addrport_size;
494 hmac_ctx_.update(cli_addr_port, cli_addrport_size);
501 BufferAllocated hmac_result(SSLLib::CryptoAPI::HMACContext::MAX_HMAC_SIZE);
504 srv_psid.
read(hmac_result);
515 for (
unsigned int offset = 0; offset <= 1; ++offset)
519 if (srv_psid.
match(calc_psid))
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.
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.
void advance(const size_t delta)
Advances the buffer by the specified delta.
bool empty() const
Returns true if the buffer is empty.
void push_front(const T &value)
Append a T object to the array, with possible resize.
void read(NCT *data, const size_t size)
Read data from the buffer into the specified memory location.
size_t prepare(const unsigned int context, Buffer &buf) const
StaticKey slice(unsigned int key_specifier) const
virtual OvpnHMACInstance::Ptr new_obj()=0
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 void init(const StaticKey &key)=0
virtual bool ovpn_hmac_cmp(const 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 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.
SSLFactoryAPI::Ptr ssl_factory
TLSCryptContext::Ptr tls_crypt_context
bool tls_auth_enabled() const
OpenVPNStaticKey tls_auth_key
leave this undefined to disable tls_auth
OvpnHMACContext::Ptr tls_auth_context
bool tls_crypt_v2_enabled() const
bool is_clients_handshake_ack_tls_auth() const
Returns true if this could be the third packet of the 3-way handshake (tls-auth/none).
static unsigned char get_server_hard_reset_opfield()
bool is_clients_handshake_ack_tls_crypt_v2() const
Returns true if this could be the third packet of the 3-way handshake (tls-crypt-v2).
bool supports_early_negotiation(const PacketIDControl &pidc) const noexcept
Returns true if the peer supports early negotiation (i.e. is able to reply with CONTROL_WKC_V1).
bool is_ack_v1() const
Returns true if the packet is a P_ACK_V1 (no own message-id field on the wire).
static void prepend_TLV(Buffer &payload)
Adds an {EARLY_NEG_FLAGS, 2, EARLY_NEG_FLAG_RESEND_WKC} TLV to a payload buffer (use with TLS crypt V...
bool is_tls_crypt_v2() const noexcept
Returns true if this is a TLS crypt V2 protocol packet.
bool is_clients_initial_reset() const
bool match(const ProtoSessionID &other) const
const Buffer get_buf() const
void prepend(Buffer &buf) const
Interface to communicate the server's address semantics.
virtual const unsigned char * get_abstract_cli_addrport(size_t &slab_size) const =0
Implements the PsidCookie interface.
static StaticKey create_key()
SSLLib::CryptoAPI::HMACContext hmac_ctx_
OvpnHMACInstance::Ptr ta_hmac_recv_
ProtoSessionID get_cookie_psid() override
Get the cookie psid from client's 2nd packet.
static const StaticKey & get_key()
ProtoSessionID cookie_psid_
const Time::Duration & handwindow_
TLSCryptInstance::Ptr init_tls_crypt_v2(Buffer &pkt_buf, const unsigned int slice)
Set up the one TLSCryptInstance a caller needs from a tls-crypt-v2 packet's WKc.
static bool read_id_is_early_handshake(Buf &buf)
bool check_session_id_hmac(const ProtoSessionID &srv_psid, const ProtoSessionID &cli_psid, const PsidCookieAddrInfoBase &pcaib)
PsidCookieTransportBase::Ptr pctb_
Intercept process_clients_initial_reset_tls_crypt(Buffer &pkt_buf, const PsidCookieAddrInfoBase &pcaib, const CookieHelper &ch)
Intercept process_clients_server_reset_ack_tls_auth(ConstBuffer &pkt_buf, const PsidCookieAddrInfoBase &pcaib, bool is_ack_v1)
static constexpr int SID_SIZE
ProtoContext::ProtoConfig & pcfg_
Intercept intercept(Buffer &pkt_buf, const PsidCookieAddrInfoBase &pcaib) override
Called when a potential new client session packet is received.
ProtoSessionID calculate_session_id_hmac(const ProtoSessionID &cli_psid, const PsidCookieAddrInfoBase &pcaib, unsigned int offset)
Calculate the psid cookie, the ProtoSessionID hmac.
Intercept process_clients_initial_reset_tls_auth(ConstBuffer &pkt_buf, const PsidCookieAddrInfoBase &pcaib)
static constexpr CryptoAlgs::Type digest_
static void pre_threading_setup()
bool validate_3whs_ack_payload(Buf &buf, const ProtoSessionID &cli_psid, const PsidCookieAddrInfoBase &pcaib, bool has_own_pktid=true)
Intercept process_clients_server_reset_ack_tls_crypt(Buffer &pkt_buf, const PsidCookieAddrInfoBase &pcaib)
static constexpr int OPCODE_SIZE
void provide_psid_cookie_transport(PsidCookieTransportBase::Ptr pctb) override
Give this component the transport needed to send the server's HARD_RESET.
PsidCookieImpl(ServerProto::Factory *psfp)
OvpnHMACInstance::Ptr ta_hmac_send_
virtual bool psid_cookie_send_const(Buffer &send_buf, const PsidCookieAddrInfoBase &pcaib)=0
Interface to integrate this component into the server implementation.
Intercept
Values returned by the intercept() function.
virtual SSLLib::Ctx libctx()=0
virtual const Mode & mode() const =0
void init_from_rng(StrongRandomAPI &rng, const size_t key_size)
const unsigned char * data() const
virtual TLSCryptInstance::Ptr new_obj_send()=0
virtual TLSCryptInstance::Ptr new_obj_recv()=0
constexpr static const size_t hmac_offset
virtual size_t digest_size() const =0
virtual bool hmac_cmp(const unsigned char *header, const size_t header_len, const unsigned char *payload, const size_t payload_len)=0
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
virtual size_t decrypt(const unsigned char *iv, unsigned char *out, const size_t olen, const unsigned char *in, const size_t ilen)=0
base_type seconds_since_epoch() const
void work(openvpn_io::io_context &io_context, ThreadCommon &tc, MyRunContext &runctx, const unsigned int unit)
const Alg & get(const Type type)
static constexpr std::size_t id_size
Support deferred server-side state creation when client connects.
static constexpr size_t size()
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.