62 const char *ncpstr = peer_info ? strstr(peer_info,
"IV_NCP=") : NULL;
66 int r = sscanf(ncpstr,
"IV_NCP=%d", &ncp);
87 || strstr(peer_info,
"IV_CIPHERS="))
100 bool error_found =
false;
129 msg(
M_WARN,
"WARNING: cipher 'none' specified for --data-ciphers. "
130 "This allows negotiation of NO encryption and "
131 "tunnelled data WILL then be transmitted in clear text "
133 "PLEASE DO RECONSIDER THIS SETTING!");
144 msg(
M_WARN,
"Unsupported %scipher algorithm '%s'. It does not use "
145 "CFB, OFB, CBC, or a supported AEAD mode",
optstr,
token);
170 msg(
M_WARN,
"Length of --data-ciphers is over the "
171 "limit of 127 chars");
206 o->ncp_ciphers = ncp_ciphers;
241 return "AES-256-GCM:AES-128-GCM";
266 if (remote_cipher == NULL
267 || (peer_info && strstr(peer_info,
"IV_CIPHERS=")))
275 while ((token =
strsep(&tmp_ciphers,
":")))
278 ||
streq(token, remote_cipher))
306 if (remote_ciphername
321 msg(
D_PUSH_DEBUG,
"OPTIONS IMPORT: data channel crypto options modified");
343 "cipher with server. Add the server's "
344 "cipher ('%s') to --data-ciphers (currently '%s'), e.g."
345 "--data-ciphers %s:%s if you want to connect to this server.",
355 "cipher with server. Configure "
356 "--data-ciphers-fallback if you want to connect "
376 const char *server_ciphers;
377 const char *client_ciphers;
381 server_ciphers =
session->opt->config_ncp_ciphers;
382 client_ciphers = peer_ciphers;
386 client_ciphers =
session->opt->config_ncp_ciphers;
387 server_ciphers = peer_ciphers;
392 char *tmp_ciphers =
string_alloc(server_ciphers, &gc_local);
395 while ((token =
strsep(&tmp_ciphers,
":")))
403 const char *ret = NULL;
415 const char *common_cipher)
446 session->opt->crypto_flags &= ~CO_EPOCH_DATA_KEY_FORMAT;
449#if defined(HAVE_EXPORT_KEYING_MATERIAL)
469 "Continuing anyway, expect problems");
473 multi->
peer_id = (peerid[0] << 16) + (peerid[1] << 8) + peerid[2];
506 const char *ciphername =
session->opt->key_type.cipher;
518 "TLS_export=%d, DATA_v2=%d, peer-id %d, epoch=%d, cipher=%s",
539 msg(
D_TLS_ERRORS,
"Error: negotiated cipher not allowed - %s not in %s%s",
562 const char *search =
"DEFAULT";
563 const int ncp_ciphers_len = strlen(o->
ncp_ciphers) + strlen(replace) - strlen(search) + 1;
565 uint8_t *ncp_ciphers =
gc_malloc(ncp_ciphers_len,
true, &o->
gc);
582 o->ncp_ciphers = (
char *) ncp_ciphers;
597 o->ncp_ciphers_conf =
o->ncp_ciphers;
608 const char *
default_ciphers =
"AES-256-GCM:AES-128-GCM:CHACHA20-POLY1305";
619 o->ncp_ciphers_conf =
"DEFAULT";
636 if (!
strcmp(
o->ncp_ciphers,
o->ncp_ciphers_conf))
void free_buf(struct buffer *buf)
bool buf_printf(struct buffer *buf, const char *format,...)
bool buf_puts(struct buffer *buf, const char *str)
void buf_null_terminate(struct buffer *buf)
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
struct buffer alloc_buf(size_t size)
char * string_alloc(const char *str, struct gc_arena *gc)
static void buf_set_write(struct buffer *buf, uint8_t *data, int size)
static int buf_len(const struct buffer *buf)
static int buf_forward_capacity(const struct buffer *buf)
static bool buf_write(struct buffer *dest, const void *src, size_t size)
static void gc_free(struct gc_arena *a)
static char * buf_str(const struct buffer *buf)
static struct gc_arena gc_new(void)
char * strsep(char **stringp, const char *delim)
#define CO_USE_TLS_KEY_MATERIAL_EXPORT
Bit-flag indicating that data channel key derivation is done using TLS keying material export [RFC570...
#define CO_USE_DYNAMIC_TLS_CRYPT
Bit-flag indicating that renegotiations are using tls-crypt with a TLS-EKM derived key.
#define CO_EPOCH_DATA_KEY_FORMAT
Bit-flag indicating the epoch the data format.
#define CO_USE_CC_EXIT_NOTIFY
Bit-flag indicating that explicit exit notifies should be sent via the control channel instead of usi...
bool cipher_kt_mode_cbc(const char *ciphername)
Check if the supplied cipher is a supported CBC mode cipher.
static bool cipher_defined(const char *ciphername)
Checks if the cipher is defined and is not the null (none) cipher.
bool cipher_kt_mode_aead(const char *ciphername)
Check if the supplied cipher is a supported AEAD mode cipher.
bool cipher_kt_mode_ofb_cfb(const char *ciphername)
Check if the supplied cipher is a supported OFB or CFB mode cipher.
static bool cipher_valid(const char *ciphername)
Returns if the cipher is valid, based on the given cipher name.
const char * cipher_kt_name(const char *ciphername)
Retrieve a normalised string describing the cipher (e.g.
static const char * dco_get_supported_ciphers(void)
#define OPT_P_NCP
Negotiable crypto parameters.
static bool dco_enabled(const struct options *o)
Returns whether the current configuration has dco enabled.
#define IV_PROTO_CC_EXIT_NOTIFY
Support for explicit exit notify via control channel This also includes support for the protocol-flag...
#define IV_PROTO_DATA_EPOCH
Support the extended packet id and epoch format for data channel packets.
#define IV_PROTO_DATA_V2
Support P_DATA_V2.
#define IV_PROTO_TLS_KEY_EXPORT
Supports key derivation via TLS key material exporter [RFC5705].
#define IV_PROTO_DYN_TLS_CRYPT
Support to dynamic tls-crypt (renegotiation with TLS-EKM derived tls-crypt key)
#define IV_PROTO_NCP_P2P
Support doing NCP in P2P mode.
#define EXPORT_P2P_PEERID_LABEL
bool key_state_export_keying_material(struct tls_session *session, const char *label, size_t label_size, void *ekm, size_t ekm_size)
Keying Material Exporters [RFC 5705] allows additional keying material to be derived from existing TL...
char * ncp_get_best_cipher(const char *server_list, const char *peer_info, const char *remote_cipher, struct gc_arena *gc)
Iterates through the ciphers in server_list and return the first cipher that is also supported by the...
const char * tls_peer_ncp_list(const char *peer_info, struct gc_arena *gc)
Returns the support cipher list from the peer according to the IV_NCP and IV_CIPHER values in peer_in...
void options_postprocess_setdefault_ncpciphers(struct options *o)
Checks for availibility of Chacha20-Poly1305 and sets the ncp_cipher to either AES-256-GCM:AES-128-GC...
const char * ncp_expanded_ciphers(struct options *o, struct gc_arena *gc)
returns the o->ncp_ciphers in brackets, e.g.
bool check_session_cipher(struct tls_session *session, struct options *options)
Checks if the cipher is allowed, otherwise returns false and reset the cipher to the config cipher.
void p2p_mode_ncp(struct tls_multi *multi, struct tls_session *session)
Determines if there is common cipher of both peer by looking at the IV_CIPHER peer info.
static int tls_peer_info_ncp_ver(const char *peer_info)
Return the Negotiable Crypto Parameters version advertised in the peer info string,...
bool check_pull_client_ncp(struct context *c, const int found)
Checks whether the cipher negotiation is in an acceptable state and we continue to connect or should ...
bool tls_item_in_cipher_list(const char *item, const char *list)
Return true iff item is present in the colon-separated zero-terminated cipher list.
void append_cipher_to_ncp_list(struct options *o, const char *ciphername)
Appends the cipher specified by the ciphernamer parameter to to the o->ncp_ciphers list.
static void p2p_ncp_set_options(struct tls_multi *multi, struct tls_session *session, const char *common_cipher)
bool tls_peer_supports_ncp(const char *peer_info)
Returns whether the client supports NCP either by announcing IV_NCP>=2 or the IV_CIPHERS list.
static bool tls_poor_mans_ncp(struct options *o, const char *remote_ciphername)
"Poor man's NCP": Use peer cipher if it is an allowed (NCP) cipher.
char * mutate_ncp_cipher_list(const char *list, struct gc_arena *gc)
Check whether the ciphers in the supplied list are supported.
const char * get_p2p_ncp_cipher(struct tls_session *session, const char *peer_info, struct gc_arena *gc)
Determines the best common cipher from both peers IV_CIPHER lists.
static void replace_default_in_ncp_ciphers_option(struct options *o, const char *replace)
Replaces the string DEFAULT with the string replace.
Control Channel SSL/Data dynamic negotiation Module This file is split from ssl.h to be able to unit ...
#define MAX_NCP_CIPHERS_LENGTH
The maximum length of a ncp-cipher string that is accepted.
char * extract_var_peer_info(const char *peer_info, const char *var, struct gc_arena *gc)
Extracts a variable from peer info, the returned string will be allocated using the supplied gc_arena...
unsigned int extract_iv_proto(const char *peer_info)
Extracts the IV_PROTO variable and returns its value or 0 if it cannot be extracted.
Wrapper structure for dynamically allocated memory.
int len
Length in bytes of the actual content within the allocated memory.
struct tls_multi * tls_multi
TLS state structure for this VPN tunnel.
Contains all state information for one tunnel.
struct context_2 c2
Level 2 context.
struct options options
Options loaded from command line or configuration file.
Garbage collection arena used to keep track of dynamically allocated memory.
const char * ncp_ciphers_conf
The original ncp_ciphers specified by the user in the configuration.
bool enable_ncp_fallback
If defined fall back to ciphername if NCP fails.
Security parameter state for a single VPN tunnel.
char * remote_ciphername
cipher specified in peer's config file
Security parameter state of a single session within a VPN tunnel.