const struct options *options = &c->options;
/* TLS handshake authentication (--tls-auth) */
- if (options->tls_auth_file)
+ if (options->ce.tls_auth_file)
{
/* Initialize key_type for tls-auth with auth only */
CLEAR(c->c1.ks.tls_auth_key_type);
crypto_read_openvpn_key(&c->c1.ks.tls_auth_key_type,
&c->c1.ks.tls_wrap_key,
- options->tls_auth_file,
- options->tls_auth_file_inline,
- options->key_direction,
+ options->ce.tls_auth_file,
+ options->ce.tls_auth_file_inline,
+ options->ce.key_direction,
"Control Channel Authentication", "tls-auth");
}
/* TLS handshake encryption+authentication (--tls-crypt) */
- if (options->tls_crypt_file)
+ if (options->ce.tls_crypt_file)
{
tls_crypt_init_key(&c->c1.ks.tls_wrap_key,
- options->tls_crypt_file,
- options->tls_crypt_inline, options->tls_server);
+ options->ce.tls_crypt_file,
+ options->ce.tls_crypt_inline, options->tls_server);
}
}
#endif
/* TLS handshake authentication (--tls-auth) */
- if (options->tls_auth_file)
+ if (options->ce.tls_auth_file)
{
to.tls_wrap.mode = TLS_WRAP_AUTH;
to.tls_wrap.opt.key_ctx_bi = c->c1.ks.tls_wrap_key;
}
/* TLS handshake encryption (--tls-crypt) */
- if (options->tls_crypt_file)
+ if (options->ce.tls_crypt_file)
{
to.tls_wrap.mode = TLS_WRAP_CRYPT;
to.tls_wrap.opt.key_ctx_bi = c->c1.ks.tls_wrap_key;
#ifdef ENABLE_OCC
SHOW_INT(explicit_exit_notification);
#endif
+
+ SHOW_STR(tls_auth_file);
+ SHOW_PARM(key_direction, keydirection2ascii(o->key_direction, false, true),
+ "%s");
+ SHOW_STR(tls_crypt_file);
}
SHOW_BOOL(push_peer_info);
SHOW_BOOL(tls_exit);
- SHOW_STR(tls_auth_file);
- SHOW_STR(tls_crypt_file);
-
#ifdef ENABLE_PKCS11
{
int i;
notnull(options->priv_key_file, "private key file (--key) or PKCS#12 file (--pkcs12)");
}
}
- if (options->tls_auth_file && options->tls_crypt_file)
+ if (ce->tls_auth_file && ce->tls_crypt_file)
{
msg(M_USAGE, "--tls-auth and --tls-crypt are mutually exclusive");
}
}
}
+ /*
+ * Set per-connection block tls-auth/crypt fields if undefined.
+ *
+ * At the end only one of the two will be really set because the parser
+ * logic prevents configurations where both are set.
+ */
+ if (!ce->tls_auth_file && !ce->tls_crypt_file)
+ {
+ ce->tls_auth_file = o->tls_auth_file;
+ ce->tls_auth_file_inline = o->tls_auth_file_inline;
+ ce->key_direction = o->key_direction;
+
+ ce->tls_crypt_file = o->tls_crypt_file;
+ ce->tls_crypt_inline = o->tls_crypt_inline;
+ }
+
+ /* pre-cache tls-auth/crypt key file if persist-key was specified and keys
+ * were not already embedded in the config file
+ */
+ if (o->persist_key)
+ {
+ if (ce->tls_auth_file && !ce->tls_auth_file_inline)
+ {
+ struct buffer in = buffer_read_from_file(o->tls_auth_file, &o->gc);
+ if (!buf_valid(&in))
+ msg(M_FATAL, "Cannot pre-load tls-auth keyfile (%s)",
+ o->tls_auth_file);
+
+ ce->tls_auth_file = INLINE_FILE_TAG;
+ ce->tls_auth_file_inline = (char *)in.data;
+ }
+
+ if (ce->tls_crypt_file && !ce->tls_crypt_inline)
+ {
+ struct buffer in = buffer_read_from_file(o->tls_crypt_file, &o->gc);
+ if (!buf_valid(&in))
+ msg(M_FATAL, "Cannot pre-load tls-crypt keyfile (%s)",
+ o->tls_auth_file);
+
+ ce->tls_crypt_file = INLINE_FILE_TAG;
+ ce->tls_crypt_inline = (char *)in.data;
+ }
+ }
}
#ifdef _WIN32
options_postprocess_mutate_ce(o, o->connection_list->array[i]);
}
- /* pre-cache tls-auth/crypt key file if persist-key was specified */
- if (o->persist_key)
- {
- if (o->tls_auth_file && !o->tls_auth_file_inline)
- {
- struct buffer in = buffer_read_from_file(o->tls_auth_file, &o->gc);
- if (!buf_valid(&in))
- msg(M_FATAL, "Cannot pre-load tls-auth keyfile (%s)",
- o->tls_auth_file);
-
- o->tls_auth_file = INLINE_FILE_TAG;
- o->tls_auth_file_inline = (char *)in.data;
- }
-
- if (o->tls_crypt_file && !o->tls_crypt_inline)
- {
- struct buffer in = buffer_read_from_file(o->tls_crypt_file, &o->gc);
- if (!buf_valid(&in))
- msg(M_FATAL, "Cannot pre-load tls-crypt keyfile (%s)",
- o->tls_auth_file);
-
- o->tls_crypt_file = INLINE_FILE_TAG;
- o->tls_crypt_inline = (char *)in.data;
- }
- }
-
if (o->tls_server)
{
/* Check that DH file is specified, or explicitly disabled */
options->crl_file, R_OK, "--crl-verify");
}
- errs |= check_file_access(CHKACC_FILE|CHKACC_INLINE|CHKACC_PRIVATE,
- options->tls_auth_file, R_OK, "--tls-auth");
- errs |= check_file_access(CHKACC_FILE|CHKACC_INLINE|CHKACC_PRIVATE,
- options->tls_crypt_file, R_OK, "--tls-crypt");
+ ASSERT(options->connection_list);
+ for (int i = 0; i < options->connection_list->len; ++i)
+ {
+ struct connection_entry *ce = options->connection_list->array[i];
+
+ errs |= check_file_access(CHKACC_FILE|CHKACC_INLINE|CHKACC_PRIVATE,
+ ce->tls_auth_file, R_OK, "--tls-auth");
+
+ errs |= check_file_access(CHKACC_FILE|CHKACC_INLINE|CHKACC_PRIVATE,
+ ce->tls_crypt_file, R_OK, "--tls-crypt");
+
+ }
+
errs |= check_file_access(CHKACC_FILE|CHKACC_INLINE|CHKACC_PRIVATE,
options->shared_secret_file, R_OK, "--secret");
+
errs |= check_file_access(CHKACC_DIRPATH|CHKACC_FILEXSTWR,
options->packet_id_file, R_OK|W_OK, "--replay-persist");
{
if (TLS_CLIENT || TLS_SERVER)
{
- if (o->tls_auth_file)
+ if (o->ce.tls_auth_file)
{
buf_printf(&out, ",tls-auth");
}
{
int key_direction;
+ VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION);
+
key_direction = ascii2keydirection(msglevel, p[1]);
if (key_direction >= 0)
{
- options->key_direction = key_direction;
+ if (permission_mask & OPT_P_GENERAL)
+ {
+ options->key_direction = key_direction;
+ }
+ else if (permission_mask & OPT_P_CONNECTION)
+ {
+ options->ce.key_direction = key_direction;
+ }
}
else
{
}
else if (streq(p[0], "tls-auth") && p[1] && !p[3])
{
- VERIFY_PERMISSION(OPT_P_GENERAL);
- if (streq(p[1], INLINE_FILE_TAG) && p[2])
+ int key_direction = -1;
+
+ VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION);
+
+ if (permission_mask & OPT_P_GENERAL)
{
- options->tls_auth_file_inline = p[2];
+ if (streq(p[1], INLINE_FILE_TAG) && p[2])
+ {
+ options->tls_auth_file_inline = p[2];
+ }
+ else if (p[2])
+ {
+ key_direction = ascii2keydirection(msglevel, p[2]);
+ if (key_direction < 0)
+ {
+ goto err;
+ }
+ options->key_direction = key_direction;
+ }
+ options->tls_auth_file = p[1];
}
- else if (p[2])
+ else if (permission_mask & OPT_P_CONNECTION)
{
- int key_direction;
-
- key_direction = ascii2keydirection(msglevel, p[2]);
- if (key_direction >= 0)
+ options->ce.key_direction = KEY_DIRECTION_BIDIRECTIONAL;
+ if (streq(p[1], INLINE_FILE_TAG) && p[2])
{
- options->key_direction = key_direction;
+ options->ce.tls_auth_file_inline = p[2];
}
- else
+ else if (p[2])
{
- goto err;
+ key_direction = ascii2keydirection(msglevel, p[2]);
+ if (key_direction < 0)
+ {
+ goto err;
+ }
+ options->ce.key_direction = key_direction;
}
+ options->ce.tls_auth_file = p[1];
}
- options->tls_auth_file = p[1];
}
else if (streq(p[0], "tls-crypt") && p[1] && !p[3])
{
- VERIFY_PERMISSION(OPT_P_GENERAL);
- if (streq(p[1], INLINE_FILE_TAG) && p[2])
+ VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION);
+ if (permission_mask & OPT_P_GENERAL)
{
- options->tls_crypt_inline = p[2];
+ if (streq(p[1], INLINE_FILE_TAG) && p[2])
+ {
+ options->tls_crypt_inline = p[2];
+ }
+ options->tls_crypt_file = p[1];
+ }
+ else if (permission_mask & OPT_P_CONNECTION)
+ {
+ if (streq(p[1], INLINE_FILE_TAG) && p[2])
+ {
+ options->ce.tls_crypt_inline = p[2];
+ }
+ options->ce.tls_crypt_file = p[1];
+
}
- options->tls_crypt_file = p[1];
}
else if (streq(p[0], "key-method") && p[1] && !p[2])
{