OpenVPN
Macros | Functions
ssl_pkt.c File Reference
#include "syshead.h"
#include "ssl_util.h"
#include "ssl_pkt.h"
#include "ssl_common.h"
#include "crypto.h"
#include "session_id.h"
#include "reliable.h"
#include "tls_crypt.h"
Include dependency graph for ssl_pkt.c:

Go to the source code of this file.

Macros

#define SWAP_BUF_SIZE   256
 

Functions

static bool swap_hmac (struct buffer *buf, const struct crypto_options *co, bool incoming)
 Move a packet authentication HMAC + related fields to or from the front of the buffer so it can be processed by encrypt/decrypt. More...
 
static void tls_wrap_control (struct tls_wrap_ctx *ctx, uint8_t header, struct buffer *buf, struct session_id *session_id)
 Wraps a TLS control packet by adding tls-auth HMAC or tls-crypt(-v2) encryption and opcode header including session id. More...
 
void write_control_auth (struct tls_session *session, struct key_state *ks, struct buffer *buf, struct link_socket_actual **to_link_addr, int opcode, int max_ack, bool prepend_ack)
 
bool read_control_auth (struct buffer *buf, struct tls_wrap_ctx *ctx, const struct link_socket_actual *from, const struct tls_options *opt)
 
void free_tls_pre_decrypt_state (struct tls_pre_decrypt_state *state)
 
enum first_packet_verdict tls_pre_decrypt_lite (const struct tls_auth_standalone *tas, struct tls_pre_decrypt_state *state, const struct link_socket_actual *from, const struct buffer *buf)
 Inspect an incoming packet for which no VPN tunnel is active, and determine whether a new VPN tunnel should be created. More...
 
struct buffer tls_reset_standalone (struct tls_wrap_ctx *ctx, struct tls_auth_standalone *tas, struct session_id *own_sid, struct session_id *remote_sid, uint8_t header, bool request_resend_wkc)
 This function creates a reset packet using the information from the tls pre decrypt state. More...
 
hmac_ctx_tsession_id_hmac_init (void)
 
struct session_id calculate_session_id_hmac (struct session_id client_sid, const struct openvpn_sockaddr *from, hmac_ctx_t *hmac, int handwindow, int offset)
 Calculates the HMAC based server session id based on a client session id and socket addr. More...
 
bool check_session_id_hmac (struct tls_pre_decrypt_state *state, const struct openvpn_sockaddr *from, hmac_ctx_t *hmac, int handwindow)
 Checks if a control packet has a correct HMAC server session id. More...
 

Macro Definition Documentation

◆ SWAP_BUF_SIZE

#define SWAP_BUF_SIZE   256

Definition at line 41 of file ssl_pkt.c.

Function Documentation

◆ calculate_session_id_hmac()

struct session_id calculate_session_id_hmac ( struct session_id  client_sid,
const struct openvpn_sockaddr from,
hmac_ctx_t hmac,
int  handwindow,
int  offset 
)

Calculates the HMAC based server session id based on a client session id and socket addr.

Parameters
client_sidsession id of the client
fromlink_socket from the client
hmacthe hmac context to use for the calculation
handwindowthe quantisation of the current time
offsetoffset to 'now' to use
Returns
the expected server session id

Definition at line 487 of file ssl_pkt.c.

References hmac_ctx_final(), hmac_ctx_reset(), hmac_ctx_update(), now, SHA256_DIGEST_LENGTH, and SID_SIZE.

Referenced by check_session_id_hmac(), do_pre_decrypt_check(), and test_calc_session_id_hmac_static().

◆ check_session_id_hmac()

bool check_session_id_hmac ( struct tls_pre_decrypt_state state,
const struct openvpn_sockaddr from,
hmac_ctx_t hmac,
int  handwindow 
)

Checks if a control packet has a correct HMAC server session id.

Parameters
client_sidsession id of the client
fromlink_socket from the client
hmacthe hmac context to use for the calculation
handwindowthe quantisation of the current time
Returns
the expected server session id

Definition at line 529 of file ssl_pkt.c.

References calculate_session_id_hmac(), memcmp_constant_time(), tls_pre_decrypt_state::newbuf, tls_pre_decrypt_state::peer_session_id, reliable_ack_parse(), tls_pre_decrypt_state::server_session_id, and SID_SIZE.

Referenced by do_pre_decrypt_check(), test_verify_hmac_none(), and test_verify_hmac_tls_auth().

◆ free_tls_pre_decrypt_state()

void free_tls_pre_decrypt_state ( struct tls_pre_decrypt_state state)

◆ read_control_auth()

bool read_control_auth ( struct buffer buf,
struct tls_wrap_ctx ctx,
const struct link_socket_actual from,
const struct tls_options opt 
)

◆ session_id_hmac_init()

hmac_ctx_t* session_id_hmac_init ( void  )

◆ swap_hmac()

static bool swap_hmac ( struct buffer buf,
const struct crypto_options co,
bool  incoming 
)
static

Move a packet authentication HMAC + related fields to or from the front of the buffer so it can be processed by encrypt/decrypt.

Turning the on wire format that starts with the opcode to a format that starts with the hmac e.g. "onwire" [opcode, peer session id] [hmac, packet id] [remainder of packed]

"internal" [hmac, packet id] [opcode, peer session id] [remainder of packet]

Parameters
bufthe buffer the swap operation is executed on
incomingdetermines the direction of the swap
cocrypto options, determines the hmac to use in the swap
Returns
if the swap was successful (buf was large enough)

Definition at line 61 of file ssl_pkt.c.

References ASSERT, BPTR, key_ctx_bi::decrypt, key_ctx_bi::encrypt, key_ctx::hmac, hmac_ctx_size(), crypto_options::key_ctx_bi, buffer::len, packet_id_size(), SID_SIZE, and SWAP_BUF_SIZE.

Referenced by read_control_auth(), and tls_wrap_control().

◆ tls_reset_standalone()

struct buffer tls_reset_standalone ( struct tls_wrap_ctx ctx,
struct tls_auth_standalone tas,
struct session_id own_sid,
struct session_id remote_sid,
uint8_t  header,
bool  request_resend_wkc 
)

◆ tls_wrap_control()

static void tls_wrap_control ( struct tls_wrap_ctx ctx,
uint8_t  header,
struct buffer buf,
struct session_id session_id 
)
static

Wraps a TLS control packet by adding tls-auth HMAC or tls-crypt(-v2) encryption and opcode header including session id.

Parameters
ctxtls wrapping context
headerfirst byte of the packet (opcode and key id)
bufbuffer to write the resulting packet to
session_idsession id to use as our session id

Definition at line 121 of file ssl_pkt.c.

References ASSERT, buf_copy(), buf_init, buf_write(), buf_write_prepend(), clear_buf(), D_TLS_ERRORS, buffer::len, tls_wrap_ctx::mode, msg, buffer::offset, openvpn_encrypt(), tls_wrap_ctx::opt, P_CONTROL_HARD_RESET_CLIENT_V3, P_CONTROL_WKC_V1, P_OPCODE_SHIFT, session_id_write(), session_id_write_prepend(), swap_hmac(), tls_wrap_ctx::tls_crypt_v2_wkc, tls_crypt_wrap(), and tls_wrap_ctx::work.

Referenced by tls_reset_standalone(), and write_control_auth().

◆ write_control_auth()

void write_control_auth ( struct tls_session session,
struct key_state ks,
struct buffer buf,
struct link_socket_actual **  to_link_addr,
int  opcode,
int  max_ack,
bool  prepend_ack 
)