Go to the documentation of this file.
59 const char *ncpstr = peer_info ? strstr(peer_info,
"IV_NCP=") : NULL;
63 int r = sscanf(ncpstr,
"IV_NCP=%d", &ncp);
84 || strstr(peer_info,
"IV_CIPHERS="))
97 bool error_found =
false;
102 const char *token = strtok(tmp_ciphers,
":");
114 bool optional =
false;
121 const bool nonecipher = (strcmp(token,
"none") == 0);
122 const char *optstr = optional ?
"optional " :
"";
126 msg(
M_WARN,
"WARNING: cipher 'none' specified for --data-ciphers. "
127 "This allows negotiation of NO encryption and "
128 "tunnelled data WILL then be transmitted in clear text "
130 "PLEASE DO RECONSIDER THIS SETTING!");
134 msg(
M_WARN,
"Unsupported %scipher in --data-ciphers: %s", optstr, token);
135 error_found = error_found || !optional;
141 msg(
M_WARN,
"Unsupported %scipher algorithm '%s'. It does not use "
142 "CFB, OFB, CBC, or a supported AEAD mode", optstr, token);
143 error_found = error_found || !optional;
152 ovpn_cipher_name =
"none";
165 strlen(ovpn_cipher_name) + 2))
167 msg(
M_WARN,
"Length of --data-ciphers is over the "
168 "limit of 127 chars");
173 buf_puts(&new_list, ovpn_cipher_name);
176 token = strtok(NULL,
":");
182 if (!error_found &&
buf_len(&new_list) > 0)
198 size_t newlen = strlen(o->
ncp_ciphers) + 1 + strlen(ciphername) + 1;
199 char *ncp_ciphers =
gc_malloc(newlen,
false, &o->
gc);
210 char *tmp_ciphers_orig = tmp_ciphers;
212 const char *token = strtok(tmp_ciphers,
":");
215 if (0 == strcmp(token, item))
219 token = strtok(NULL,
":");
221 free(tmp_ciphers_orig);
223 return token != NULL;
239 return "AES-256-GCM:AES-128-GCM";
249 const char *remote_cipher,
struct gc_arena *gc)
264 if (remote_cipher == NULL
265 || (peer_info && strstr(peer_info,
"IV_CIPHERS=")))
273 while ((token =
strsep(&tmp_ciphers,
":")))
276 ||
streq(token, remote_cipher))
304 if (remote_ciphername
319 msg(
D_PUSH_DEBUG,
"OPTIONS IMPORT: data channel crypto options modified");
341 "cipher with server. Add the server's "
342 "cipher ('%s') to --data-ciphers (currently '%s') if "
343 "you want to connect to this server.",
352 "cipher with server. Configure "
353 "--data-ciphers-fallback if you want to connect "
373 const char *server_ciphers;
374 const char *client_ciphers;
378 server_ciphers =
session->opt->config_ncp_ciphers;
379 client_ciphers = peer_ciphers;
383 client_ciphers =
session->opt->config_ncp_ciphers;
384 server_ciphers = peer_ciphers;
389 char *tmp_ciphers =
string_alloc(server_ciphers, &gc_local);
392 while ((token =
strsep(&tmp_ciphers,
":")))
400 const char *ret = NULL;
433 #if defined(HAVE_EXPORT_KEYING_MATERIAL)
453 "Continuing anyway, expect problems");
457 multi->
peer_id = (peerid[0] << 16) + (peerid[1] << 8) + peerid[2];
489 const char *fallback_name =
"none";
490 const char *ciphername =
session->opt->key_type.cipher;
497 buf_printf(&out,
"(not negotiated, fallback-cipher: %s)", fallback_name);
498 common_cipher =
BSTR(&out);
502 "TLS_export=%d, DATA_v2=%d, peer-id %d, cipher=%s",
516 if (!
session->opt->server && !cipher_allowed_as_fallback
519 msg(
D_TLS_ERRORS,
"Error: negotiated cipher not allowed - %s not in %s",
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.
static bool cipher_valid(const char *ciphername)
Returns if the cipher is valid, based on the given cipher name.
static int tls_peer_info_ncp_ver(const char *peer_info)
Return the Negotiable Crypto Parameters version advertised in the peer info string,...
bool enable_ncp_fallback
If defined fall back to ciphername if NCP fails.
static struct gc_arena gc_new(void)
#define IV_PROTO_DATA_V2
Support P_DATA_V2.
struct tls_multi * tls_multi
TLS state structure for this VPN tunnel.
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.
static bool cipher_defined(const char *ciphername)
Checks if the cipher is defined and is not the null (none) cipher.
Contains all state information for one tunnel.
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.
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
void buf_null_terminate(struct buffer *buf)
#define IV_PROTO_TLS_KEY_EXPORT
Supports key derivation via TLS key material exporter [RFC5705].
char * mutate_ncp_cipher_list(const char *list, struct gc_arena *gc)
Check whether the ciphers in the supplied list are supported.
const char * cipher_kt_name(const char *ciphername)
Retrieve a normalised string describing the cipher (e.g.
Security parameter state for a single VPN tunnel.
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.
struct context_2 c2
Level 2 context.
char * string_alloc(const char *str, struct gc_arena *gc)
static void p2p_ncp_set_options(struct tls_multi *multi, struct tls_session *session)
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...
#define OPT_P_NCP
Negotiable crypto parameters.
struct options options
Options loaded from command line or configuration file.
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.
#define MAX_NCP_CIPHERS_LENGTH
The maximum length of a ncp-cipher string that is accepted.
bool cipher_kt_mode_aead(const char *ciphername)
Check if the supplied cipher is a supported AEAD mode cipher.
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...
Wrapper structure for dynamically allocated memory.
#define CO_USE_DYNAMIC_TLS_CRYPT
Bit-flag indicating that renegotiations are using tls-crypt with a TLS-EKM derived key.
Security parameter state of a single session within a VPN tunnel.
bool cipher_kt_mode_ofb_cfb(const char *ciphername)
Check if the supplied cipher is a supported OFB or CFB mode cipher.
Garbage collection arena used to keep track of dynamically allocated memory.
#define IV_PROTO_DYN_TLS_CRYPT
Support to dynamic tls-crypt (renegotiation with TLS-EKM derived tls-crypt key)
bool buf_puts(struct buffer *buf, const char *str)
void free_buf(struct buffer *buf)
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...
static int buf_len(const struct buffer *buf)
#define IV_PROTO_NCP_P2P
Support doing NCP in P2P mode.
void * gc_malloc(size_t size, bool clear, struct gc_arena *a)
static void gc_free(struct gc_arena *a)
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 ...
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.
bool cipher_kt_mode_cbc(const char *ciphername)
Check if the supplied cipher is a supported CBC mode cipher.
#define EXPORT_P2P_PEERID_LABEL
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.
char * strsep(char **stringp, const char *delim)
char * remote_ciphername
cipher specified in peer's config file
static char * buf_str(const struct buffer *buf)
static int buf_forward_capacity(const struct buffer *buf)
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...
#define CO_USE_TLS_KEY_MATERIAL_EXPORT
Bit-flag indicating that data channel key derivation is done using TLS keying material export [RFC570...
struct buffer alloc_buf(size_t size)
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.
#define CO_USE_CC_EXIT_NOTIFY
Bit-flag indicating that explicit exit notifies should be sent via the control channel instead of usi...
#define IV_PROTO_CC_EXIT_NOTIFY
Support for explicit exit notify via control channel This also includes support for the protocol-flag...
bool buf_printf(struct buffer *buf, const char *format,...)