OpenVPN
Data Structures | Macros | Enumerations | Functions
ssl_pkt.h File Reference
#include "buffer.h"
#include "ssl_backend.h"
#include "ssl_common.h"
Include dependency graph for ssl_pkt.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  tls_auth_standalone
 
struct  tls_pre_decrypt_state
 struct that stores the temporary data for the tls lite decrypt functions More...
 

Macros

#define P_KEY_ID_MASK   0x07
 
#define P_OPCODE_SHIFT   3
 
#define P_CONTROL_HARD_RESET_CLIENT_V1   1 /* initial key from client, forget previous state */
 
#define P_CONTROL_HARD_RESET_SERVER_V1   2 /* initial key from server, forget previous state */
 
#define P_CONTROL_SOFT_RESET_V1   3 /* new key, graceful transition from old to new key */
 
#define P_CONTROL_V1   4 /* control channel packet (usually TLS ciphertext) */
 
#define P_ACK_V1   5 /* acknowledgement for packets received */
 
#define P_DATA_V1   6 /* data channel packet */
 
#define P_DATA_V2   9 /* data channel packet with peer-id */
 
#define P_CONTROL_HARD_RESET_CLIENT_V2   7 /* initial key from client, forget previous state */
 
#define P_CONTROL_HARD_RESET_SERVER_V2   8 /* initial key from server, forget previous state */
 
#define P_CONTROL_HARD_RESET_CLIENT_V3   10 /* initial key from client, forget previous state */
 
#define P_CONTROL_WKC_V1   11
 
#define P_FIRST_OPCODE   3
 
#define P_LAST_OPCODE   11
 
#define TLS_RELIABLE_N_SEND_BUFFERS   6 /* also window size for reliability layer */
 
#define TLS_RELIABLE_N_REC_BUFFERS   12
 
#define EARLY_NEG_MASK   0xff000000
 
#define EARLY_NEG_START   0x0f000000
 
#define TLV_TYPE_EARLY_NEG_FLAGS   0x0001
 
#define EARLY_NEG_FLAG_RESEND_WKC   0x0001
 

Enumerations

enum  first_packet_verdict {
  VERDICT_VALID_RESET_V2, VERDICT_VALID_RESET_V3, VERDICT_VALID_CONTROL_V1, VERDICT_VALID_ACK_V1,
  VERDICT_VALID_WKC_V1, VERDICT_INVALID
}
 

Functions

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...
 
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...
 
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)
 
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...
 
static const char * packet_opcode_name (int op)
 
static struct tls_wrap_ctxtls_session_get_tls_wrap (struct tls_session *session, int key_id)
 Determines if the current session should use the renegotiation tls wrap struct instead the normal one and returns it. More...
 

Macro Definition Documentation

◆ EARLY_NEG_FLAG_RESEND_WKC

#define EARLY_NEG_FLAG_RESEND_WKC   0x0001

Definition at line 316 of file ssl_pkt.h.

◆ EARLY_NEG_MASK

#define EARLY_NEG_MASK   0xff000000

Definition at line 307 of file ssl_pkt.h.

◆ EARLY_NEG_START

#define EARLY_NEG_START   0x0f000000

Definition at line 308 of file ssl_pkt.h.

◆ P_ACK_V1

#define P_ACK_V1   5 /* acknowledgement for packets received */

Definition at line 46 of file ssl_pkt.h.

◆ P_CONTROL_HARD_RESET_CLIENT_V1

#define P_CONTROL_HARD_RESET_CLIENT_V1   1 /* initial key from client, forget previous state */

Definition at line 42 of file ssl_pkt.h.

◆ P_CONTROL_HARD_RESET_CLIENT_V2

#define P_CONTROL_HARD_RESET_CLIENT_V2   7 /* initial key from client, forget previous state */

Definition at line 51 of file ssl_pkt.h.

◆ P_CONTROL_HARD_RESET_CLIENT_V3

#define P_CONTROL_HARD_RESET_CLIENT_V3   10 /* initial key from client, forget previous state */

Definition at line 55 of file ssl_pkt.h.

◆ P_CONTROL_HARD_RESET_SERVER_V1

#define P_CONTROL_HARD_RESET_SERVER_V1   2 /* initial key from server, forget previous state */

Definition at line 43 of file ssl_pkt.h.

◆ P_CONTROL_HARD_RESET_SERVER_V2

#define P_CONTROL_HARD_RESET_SERVER_V2   8 /* initial key from server, forget previous state */

Definition at line 52 of file ssl_pkt.h.

◆ P_CONTROL_SOFT_RESET_V1

#define P_CONTROL_SOFT_RESET_V1   3 /* new key, graceful transition from old to new key */

Definition at line 44 of file ssl_pkt.h.

◆ P_CONTROL_V1

#define P_CONTROL_V1   4 /* control channel packet (usually TLS ciphertext) */

Definition at line 45 of file ssl_pkt.h.

◆ P_CONTROL_WKC_V1

#define P_CONTROL_WKC_V1   11

Definition at line 59 of file ssl_pkt.h.

◆ P_DATA_V1

#define P_DATA_V1   6 /* data channel packet */

Definition at line 47 of file ssl_pkt.h.

◆ P_DATA_V2

#define P_DATA_V2   9 /* data channel packet with peer-id */

Definition at line 48 of file ssl_pkt.h.

◆ P_FIRST_OPCODE

#define P_FIRST_OPCODE   3

Definition at line 64 of file ssl_pkt.h.

◆ P_KEY_ID_MASK

#define P_KEY_ID_MASK   0x07

Definition at line 38 of file ssl_pkt.h.

◆ P_LAST_OPCODE

#define P_LAST_OPCODE   11

Definition at line 65 of file ssl_pkt.h.

◆ P_OPCODE_SHIFT

#define P_OPCODE_SHIFT   3

Definition at line 39 of file ssl_pkt.h.

◆ TLS_RELIABLE_N_REC_BUFFERS

#define TLS_RELIABLE_N_REC_BUFFERS   12

Definition at line 71 of file ssl_pkt.h.

◆ TLS_RELIABLE_N_SEND_BUFFERS

#define TLS_RELIABLE_N_SEND_BUFFERS   6 /* also window size for reliability layer */

Definition at line 70 of file ssl_pkt.h.

◆ TLV_TYPE_EARLY_NEG_FLAGS

#define TLV_TYPE_EARLY_NEG_FLAGS   0x0001

Definition at line 315 of file ssl_pkt.h.

Enumeration Type Documentation

◆ first_packet_verdict

Enumerator
VERDICT_VALID_RESET_V2 

This packet is a valid reset packet from the peer (all but tls-crypt-v2)

VERDICT_VALID_RESET_V3 

This is a valid v3 reset (tls-crypt-v2)

VERDICT_VALID_CONTROL_V1 

This packet is a valid control packet from the peer.

VERDICT_VALID_ACK_V1 

This packet is a valid ACK control packet from the peer, i.e.

it has a valid session id hmac in it

VERDICT_VALID_WKC_V1 

The packet is a valid control packet with appended wrapped client key.

VERDICT_INVALID 

the packet failed on of the various checks

Definition at line 84 of file ssl_pkt.h.

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)

◆ packet_opcode_name()

static const char* packet_opcode_name ( int  op)
inlinestatic

◆ 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  )

◆ 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_session_get_tls_wrap()

static struct tls_wrap_ctx* tls_session_get_tls_wrap ( struct tls_session session,
int  key_id 
)
inlinestatic

Determines if the current session should use the renegotiation tls wrap struct instead the normal one and returns it.

Parameters
session
key_idkey_id of the received/or to be send packet
Returns

Definition at line 285 of file ssl_pkt.h.

References tls_wrap_ctx::TLS_WRAP_CRYPT.

Referenced by tls_pre_decrypt(), 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 
)