OpenVPN
acc.c File Reference
#include "syshead.h"
#include <string.h>
#include "buffer.h"
#include "error.h"
#include "acc.h"
#include "forward.h"
#include "options_util.h"
#include "ssl_util.h"
#include "ssl_ncp.h"
#include "multi.h"
Include dependency graph for acc.c:

Go to the source code of this file.

Functions

static void log_acc_message (struct context *c, const struct buffer *buf, int payload_len, const char *protocol, int flags)
int parse_acc_message_flags (const char *flags, const char **err_reason, struct gc_arena *gc)
 Parses the flags field of an app control message If there is an error parsing the flags field the method returns -1 and puts the error reason in err_reason.
static int parse_acc_message_flags_buf (struct buffer *buf, const char **err_reason, struct gc_arena *gc)
 Wrapper around parse_acc_message_flags to also include the step of extracting the flags from the buffer and forwarding the buffer beyond the flags field.
void receive_acc_message (struct context *c, const struct buffer *buffer)
 This method parses an app custom control message and delivers it to the management interface.
bool send_acc_message (struct context *c, struct tls_multi *multi, struct tls_session *session, const char *protocol, bool fragment, const char *acc_msg_payload, bool base64)
char * parse_acc_parameters (const char *capabilities, const char *delim, int *max_acc_len, bool server, struct gc_arena *gc)
 Parses an info message from the server that contains app custom control info information prior to the PUSH_REPLY to be able to use app custom control protocols before sending.
struct buffer get_list_intersection (struct gc_arena *gc, const char *list1, const char *list2)
 Calculates the intersection of two list that are both separated by : Items in the result will have the same ordering as in the list1 parameters.
void determine_common_acc_protocols (struct tls_multi *multi, struct tls_session *session)
 Parses the IV_ACC of the peer and sets multi.acc_negotiated_protocols to the common protocols of server and client and multi.acc_max_message_length to the maximum length of the ACC message support by both server and client.
void notify_client_acc_protocols (struct tls_multi *multi)
 Notifies a client via management interface of the negotiated app custom protocols.

Function Documentation

◆ determine_common_acc_protocols()

void determine_common_acc_protocols ( struct tls_multi * multi,
struct tls_session * session )

Parses the IV_ACC of the peer and sets multi.acc_negotiated_protocols to the common protocols of server and client and multi.acc_max_message_length to the maximum length of the ACC message support by both server and client.

If there is no common protocol or the client does not support any app custom protocol multi.acc_negotiated_protocols will be set to NULL.

Parameters
multithe multi instance to use the set the app custom protocols.
sessionthe session to read the client env from

Definition at line 382 of file acc.c.

References tls_multi::acc_max_message_length, tls_multi::acc_negotiated_protocols, tls_options::acc_protocols, buf_len(), buf_str(), D_PUSH_DEBUG, D_PUSH_ERRORS, extract_var_peer_info(), gc, gc_free(), gc_new(), get_list_intersection(), msg, tls_multi::opt, parse_acc_parameters(), tls_multi::peer_info, setenv_int(), setenv_str(), and string_alloc().

Referenced by key_method_2_read(), test_acc_common_protocols(), and test_acc_send_message().

◆ get_list_intersection()

struct buffer get_list_intersection ( struct gc_arena * gc,
const char * list1,
const char * list2 )

Calculates the intersection of two list that are both separated by : Items in the result will have the same ordering as in the list1 parameters.

Parameters
gcReturned buffer will be allocated in this gc
list1First list to intersect
list2Second list to intersect.
Returns
A (potentially empty) buffer containing an intersection list

Definition at line 351 of file acc.c.

References alloc_buf_gc(), buf_cstr(), buf_len(), buf_printf(), buf_write_u8(), gc, get_list_intersection(), min_size(), string_alloc(), strtok_r(), and tls_item_in_cipher_list().

Referenced by add_option(), determine_common_acc_protocols(), get_list_intersection(), parse_server_pushed_info_acc(), and test_list_intersection().

◆ log_acc_message()

◆ notify_client_acc_protocols()

void notify_client_acc_protocols ( struct tls_multi * multi)

Notifies a client via management interface of the negotiated app custom protocols.

Parameters
multithe tls_multi instance of the connection

Definition at line 436 of file acc.c.

References tls_multi::acc_max_message_length, tls_multi::acc_negotiated_protocols, M_CLIENT, and msg.

Referenced by do_deferred_options(), and parse_server_pushed_info_acc().

◆ parse_acc_message_flags()

int parse_acc_message_flags ( const char * flags,
const char ** err_reason,
struct gc_arena * gc )

Parses the flags field of an app control message If there is an error parsing the flags field the method returns -1 and puts the error reason in err_reason.

Definition at line 91 of file acc.c.

References ACC_MESSAGE_FLAGS_ASCII, ACC_MESSAGE_FLAGS_BASE64, ACC_MESSAGE_FLAGS_FRAGMENT, man_def_auth_context::flags, gc, and gc_malloc().

Referenced by management_send_acc_message(), and parse_acc_message_flags_buf().

◆ parse_acc_message_flags_buf()

int parse_acc_message_flags_buf ( struct buffer * buf,
const char ** err_reason,
struct gc_arena * gc )
static

Wrapper around parse_acc_message_flags to also include the step of extracting the flags from the buffer and forwarding the buffer beyond the flags field.

Definition at line 139 of file acc.c.

References buf_extract_field(), man_def_auth_context::flags, gc, and parse_acc_message_flags().

Referenced by receive_acc_message().

◆ parse_acc_parameters()

char * parse_acc_parameters ( const char * capabilities,
const char * delim,
int * max_acc_len,
bool server,
struct gc_arena * gc )

Parses an info message from the server that contains app custom control info information prior to the PUSH_REPLY to be able to use app custom control protocols before sending.

In client mode only allow what we support ourselves. In server mode allow also capabilities that we not support ourselves.

Parameters
capabilitiesThe string to parse
delimThe delimiter to use when parsing the string. IV_ACC uses "," as delimiter while the custom-control PUSH message uses " " as "," is already used to separate different push directives
max_acc_lenSet to the maximum ACC message length
serverWhether we are server or client
gcThe gc arena to use for allocating the resulting string
Returns
The resulting protocol string or NULL on error

Definition at line 287 of file acc.c.

References ACC_MAX_MSG_LEN, ACC_MIN_MSG_LEN, atoi_constrained(), D_PUSH_ERRORS, gc, min_int(), msg, string_alloc(), strtok_r(), and tls_item_in_cipher_list().

Referenced by determine_common_acc_protocols(), parse_server_pushed_info_acc(), and test_parse_acc_parameters().

◆ receive_acc_message()

void receive_acc_message ( struct context * c,
const struct buffer * buffer )

This method parses an app custom control message and delivers it to the management interface.

We leave reassembly of fragmented messages to the management interface.

Parameters
cThe context struct
bufferBuffer containing the control message with ACC

Definition at line 152 of file acc.c.

References tls_multi::acc_negotiated_protocols, alloc_buf_gc(), atoi_constrained(), BLEN, buf_advance(), buf_cstr(), buf_extract_field(), buf_len(), buf_printf(), buf_read_u8(), context::c2, CBPTR, D_PUSH_ERRORS, format_hex(), gc, gc_free(), gc_malloc(), gc_new(), log_acc_message(), msg, parse_acc_message_flags_buf(), TLS_CHANNEL_BUF_SIZE, tls_item_in_cipher_list(), and context_2::tls_multi.

Referenced by parse_incoming_control_channel_command(), and test_acc_parse_client_messages().

◆ send_acc_message()

bool send_acc_message ( struct context * c,
struct tls_multi * multi,
struct tls_session * session,
const char * protocol,
bool fragment,
const char * acc_msg_payload,
bool base64 )