From: "cron2 (Code Review)" Date: Wed, 19 Nov 2025 16:48:33 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., max@...2606... Message-ID: <3d0fe4122616e80dd8baea67cff446d1441b2016-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="4SLtM//4S7A="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Add option to check tls-crypt-v2 key timestamps List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: MaxF , plaisthos , flichtenheld Cc: openvpn-devel --4SLtM//4S7A= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#7) to the change originally created by= MaxF. ( http://gerrit.openvpn.net/c/openvpn/+/1304?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by plaisthos Change subject: Add option to check tls-crypt-v2 key timestamps ...................................................................... Add option to check tls-crypt-v2 key timestamps This commit adds the option --tls-crypt-v2-max-age n. When a client key is older than n days or has no timestamp, the server rejects it. Based on work by Rein van Baaren for Sentyron. Co-authored-by: Rein van Baaren Change-Id: I0579d18c784e2ac16973d5553992c28f281a0900 Signed-off-by: Max Fillinger Acked-by: Arne Schwabe Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1304 Message-Id: <20251119140149.31867-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg34= 545.html Signed-off-by: Gert Doering --- M doc/man-sections/tls-options.rst M doc/tls-crypt-v2.txt M src/openvpn/init.c M src/openvpn/options.c M src/openvpn/options.h M src/openvpn/ssl_common.h M src/openvpn/tls_crypt.c 7 files changed, 57 insertions(+), 1 deletion(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/04/1304/7 diff --git a/doc/man-sections/tls-options.rst b/doc/man-sections/tls-option= s.rst index db107e6..63cb32f 100644 --- a/doc/man-sections/tls-options.rst +++ b/doc/man-sections/tls-options.rst @@ -568,6 +568,10 @@ The command can reject the connection by exiting with a non-zero exit code. +--tls-crypt-v2-max-age n + Reject tls-crypt-v2 client keys that are older than n days or have + no timestamp. + --tls-exit Exit on TLS negotiation failure. This option can be useful when you only want to make one attempt at connecting, e.g. in a test or monitoring scr= ipt. diff --git a/doc/tls-crypt-v2.txt b/doc/tls-crypt-v2.txt index 7dcd041..c2e9deb 100644 --- a/doc/tls-crypt-v2.txt +++ b/doc/tls-crypt-v2.txt @@ -139,7 +139,10 @@ The message is dropped and no error response is sent when either 3.1, 3= .2 or 3.3 fails (DoS protection). -4. Server optionally checks metadata using a --tls-crypt-v2-verify script +4. The server optionally checks if the client key contains a timestamp tha= t is + below a maximum age configured with the --tls-crypt-v2-max-age option. + +5. Server optionally checks metadata using a --tls-crypt-v2-verify script This allows early abort of connection, *before* we expose any of the notoriously dangerous TLS, X.509 and ASN.1 parsers and thereby reduces = the diff --git a/src/openvpn/init.c b/src/openvpn/init.c index 8d95d5c..fc079e1 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -3418,6 +3418,7 @@ { to.tls_wrap.tls_crypt_v2_server_key =3D c->c1.ks.tls_crypt_v2_= server_key; to.tls_crypt_v2_verify_script =3D c->options.tls_crypt_v2_veri= fy_script; + to.tls_crypt_v2_max_age =3D c->options.tls_crypt_v2_max_age; if (options->ce.tls_crypt_v2_force_cookie) { to.tls_wrap.opt.flags |=3D CO_FORCE_TLSCRYPTV2_COOKIE; diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 683543a..4794315 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -648,6 +648,8 @@ " fresh tls-crypt-v2 server key, and store to keyfile= \n" "--tls-crypt-v2-verify cmd : Run command cmd to verify the metadata of= the\n" " client-supplied tls-crypt-v2 client key\n" + "--tls-crypt-v2-max-age n : Only accept tls-crypt-v2 client keys that = have a\n" + " timestamp which is at most n days old.\n" "--askpass [file]: Get PEM password from controlling tty before we dae= monize.\n" "--auth-nocache : Don't cache --askpass or --auth-user-pass passwords= .\n" "--crl-verify crl ['dir']: Check peer certificate against a CRL.\n" @@ -9079,6 +9081,14 @@ VERIFY_PERMISSION(OPT_P_GENERAL); options->tls_crypt_v2_verify_script =3D p[1]; } + else if (streq(p[0], "tls-crypt-v2-max-age") && p[1]) + { + VERIFY_PERMISSION(OPT_P_GENERAL); + if (!atoi_constrained(p[1], &options->tls_crypt_v2_max_age, "tls-c= rypt-v2-max-age", 1, INT_MAX, msglevel)) + { + goto err; + } + } else if (streq(p[0], "x509-track") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_GENERAL); diff --git a/src/openvpn/options.h b/src/openvpn/options.h index 9d2ff9f..42db9ca 100644 --- a/src/openvpn/options.h +++ b/src/openvpn/options.h @@ -678,6 +678,8 @@ const char *tls_crypt_v2_verify_script; + int tls_crypt_v2_max_age; + /* Allow only one session */ bool single_session; diff --git a/src/openvpn/ssl_common.h b/src/openvpn/ssl_common.h index 23da8cf..3129299 100644 --- a/src/openvpn/ssl_common.h +++ b/src/openvpn/ssl_common.h @@ -383,6 +383,7 @@ bool tls_crypt_v2; const char *tls_crypt_v2_verify_script; + int tls_crypt_v2_max_age; /** TLS handshake wrapping state */ struct tls_wrap_ctx tls_wrap; diff --git a/src/openvpn/tls_crypt.c b/src/openvpn/tls_crypt.c index ab719b3..318c939 100644 --- a/src/openvpn/tls_crypt.c +++ b/src/openvpn/tls_crypt.c @@ -29,6 +29,7 @@ #include "argv.h" #include "base64.h" #include "crypto.h" +#include "integer.h" #include "platform.h" #include "run_command.h" #include "session_id.h" @@ -520,6 +521,34 @@ } static bool +tls_crypt_v2_check_client_key_age(const struct tls_wrap_ctx *ctx, int max_= days) +{ + if (ctx->tls_crypt_v2_metadata.len < 1 + sizeof(int64_t)) + { + msg(M_WARN, "ERROR: Client key metadata is too small to contain a = timestamp."); + return false; + } + + const uint8_t *metadata =3D ctx->tls_crypt_v2_metadata.data; + if (*metadata !=3D TLS_CRYPT_METADATA_TYPE_TIMESTAMP) + { + msg(M_WARN, "ERROR: Client key does not have a timestamp."); + return false; + } + + int64_t timestamp; + memcpy(×tamp, metadata + 1, sizeof(int64_t)); + timestamp =3D (int64_t)ntohll((uint64_t)timestamp); + int64_t max_age_in_seconds =3D max_days * 24 * 60 * 60; + if (now - timestamp > max_age_in_seconds) + { + msg(M_WARN, "ERROR: Client key is too old."); + return false; + } + return true; +} + +static bool tls_crypt_v2_verify_metadata(const struct tls_wrap_ctx *ctx, const struct = tls_options *opt) { bool ret =3D false; @@ -634,6 +663,12 @@ return false; } + if (opt && opt->tls_crypt_v2_max_age > 0 && !tls_crypt_v2_check_client= _key_age(ctx, opt->tls_crypt_v2_max_age)) + { + secure_memzero(&ctx->original_wrap_keydata, sizeof(ctx->original_w= rap_keydata)); + return false; + } + if (opt && opt->tls_crypt_v2_verify_script && !tls_crypt_v2_verify_met= adata(ctx, opt)) { secure_memzero(&ctx->original_wrap_keydata, sizeof(ctx->original_w= rap_keydata)); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1304?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I0579d18c784e2ac16973d5553992c28f281a0900 Gerrit-Change-Number: 1304 Gerrit-PatchSet: 7 Gerrit-Owner: MaxF Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel --4SLtM//4S7A= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 upl= oaded patch set #7 to the change originally created by MaxF.

View Ch= ange

The following approvals got outdated and were removed: Code-Review+2 by plaisthos

Add option to check tls-crypt-v=
2 key timestamps

This commit adds the option --tls-crypt-v2-max-age = n. When a client key
is older than n days or has no timestamp, the serve= r rejects it.

Based on work by Rein van Baaren for Sentyron.

= Co-authored-by: Rein van Baaren <revaban04@...2783...>
Change-Id: = I0579d18c784e2ac16973d5553992c28f281a0900
Signed-off-by: Max Fillinger &= lt;max@...2606...>
Acked-by: Arne Schwabe <arne-openvpn@...1227...= >
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1304
Message-= Id: <20251119140149.31867-1-gert@...1296...>
URL: https://www.mail= -archive.com/openvpn-devel@lists.sourceforge.net/msg34545.html
Signed-of= f-by: Gert Doering <gert@...1296...>
---
M doc/man-sections/tls= -options.rst
M doc/tls-crypt-v2.txt
M src/openvpn/init.c
M src/ope= nvpn/options.c
M src/openvpn/options.h
M src/openvpn/ssl_common.h
= M src/openvpn/tls_crypt.c
7 files changed, 57 insertions(+), 1 deletion(= -)

git pull ssh://gerrit.openvpn.net:29418/openv=
pn refs/changes/04/1304/7
diff --git a/doc/man-sections/tls-options=
.rst b/doc/man-sections/tls-options.rst
index db107e6..63cb= 32f 100644
--- a/doc/man-sections/tls-options.rst+++ b/doc/man-sections/tls-options.rst
@@ -568,6 +56= 8,10 @@
The command can reject the connection by exiting= with a non-zero exit
code.

= +--tls-crypt-v2-max-age n
+ Reject tls-crypt-v2 cli= ent keys that are older than n days or have
+ no timestamp.
+
--tls-exit
Exit on= TLS negotiation failure. This option can be useful when you only want to make one attempt at connecting, e.g. in a test or monitor= ing script.
diff --git a/doc/tls-crypt-v2.txt b/doc/tls-cry= pt-v2.txt
index 7dcd041..c2e9deb 100644
---= a/doc/tls-crypt-v2.txt
+++ b/doc/tls-crypt-v2.txt@@ -139,7 +139,10 @@
The message is dropped and= no error response is sent when either 3.1, 3.2 or
3.3 = fails (DoS protection).

-4. Server optionally checks metadata using a --tls-cryp= t-v2-verify script
+4= . The server optionally checks if the client key contains a timestamp that = is
+ below a maximu= m age configured with the --tls-crypt-v2-max-age option.
+
+5. Server optionally checks metadata using a --tls-crypt-= v2-verify script

This allows early ab= ort of connection, *before* we expose any of the
notori= ously dangerous TLS, X.509 and ASN.1 parsers and thereby reduces the=
diff --git a/src/openvpn/init.c b/src/openvpn/init.c
index 8d95d5c..fc079e1 100644

--- a/src/openvpn/init.c<= /span>
+++ b/src/openvpn/init.c
@@ -3418,6 +3418,7= @@
{
to.tls_wrap.tls= _crypt_v2_server_key =3D c->c1.ks.tls_crypt_v2_server_key;
to.tls_crypt_v2_verify_script =3D c->options.tls_crypt_v= 2_verify_script;

+ = to.tls_crypt_v2_max_age =3D c->options.tls_crypt_v2_max_age;
if (options->ce.tls_crypt_v2_force_cookie)
{
to.tls_wrap.o= pt.flags |=3D CO_FORCE_TLSCRYPTV2_COOKIE;
diff --git a/src/= openvpn/options.c b/src/openvpn/options.c
index 683543a..47= 94315 100644
--- a/src/openvpn/options.c
++= + b/src/openvpn/options.c
@@ -648,6 +648,8 @@
" fresh tls-crypt-v2 server key, and store to= keyfile\n"

"--tls-crypt-v2-verify cmd : Run= command cmd to verify the metadata of the\n"
&qu= ot; client-supplied tls-crypt-v2 client key\n"=
+ "--tls-crypt-v2-m= ax-age n : Only accept tls-crypt-v2 client keys that have a\n"<= br>+ " = timestamp which is at most n days old.\n"
"= --askpass [file]: Get PEM password from controlling tty before we daemonize= .\n"
"--auth-nocache : Don't cache --as= kpass or --auth-user-pass passwords.\n"
"--c= rl-verify crl ['dir']: Check peer certificate against a CRL.\n"= ;
@@ -9079,6 +9081,14 @@
VERIFY_PE= RMISSION(OPT_P_GENERAL);
options->tls_crypt_v2_= verify_script =3D p[1];
}
+ else if (streq(p[0], "tls-crypt-v2-max-= age") && p[1])
+ {
+ = VERIFY_PERMISSION(OPT_P_GENERAL);
+ if (!atoi_constrained(p[1], &options->tls_cr= ypt_v2_max_age, "tls-crypt-v2-max-age", 1, INT_MAX, msglevel))
+ {
+ goto err;

= + }
+ }
else if (stre= q(p[0], "x509-track") && p[1] && !p[2]) {
VERIFY_PERMISSION(OPT_P_GENERAL);
diff --git a/src/openvpn/options.h b/src/openvpn/options.h
index 9d2ff9f..42db9ca 100644
--- a/src/openv= pn/options.h
+++ b/src/openvpn/options.h
@@= -678,6 +678,8 @@

const char *tls_cr= ypt_v2_verify_script;

+ int tls_crypt_v2_max_age;
+
/* Allow only one sessi= on */
bool single_session;
diff --git a/src/openvpn/ssl_common.h b/src/openvpn/ssl_common.h
index 23da8cf..3129299 100644
--- a/src/openvp= n/ssl_common.h
+++ b/src/openvpn/ssl_common.h
@@ -383,6 +383,7 @@


bool tls_cryp= t_v2;
const char *tls_crypt_v2_verify_script;+ int tls_crypt_v2_max_age= ;

/** TLS handshake wrapping state *= /
struct tls_wrap_ctx tls_wrap;
diff -= -git a/src/openvpn/tls_crypt.c b/src/openvpn/tls_crypt.c
in= dex ab719b3..318c939 100644
--- a/src/openvpn/tls_crypt.c
+++ b/src/openvpn/tls_crypt.c
@@ -29,6 +29,7= @@
#include "argv.h"
#include = "base64.h"
#include "crypto.h"<= br>+#include "integer.h&qu= ot;
#include "platform.h"
#incl= ude "run_command.h"
#include "session_id.h&= quot;
@@ -520,6 +521,34 @@
}

static bool
+tls_crypt_v2_check_client_key_age(const struct tls_wrap_ctx *= ctx, int max_days)
+{=
+ if (ctx->tls= _crypt_v2_metadata.len < 1 + sizeof(int64_t))
+ {
+ msg(M_WARN, "ERROR: Client key metadata is too = small to contain a timestamp.");
+ return false;
+ }
+
+ const uin= t8_t *metadata =3D ctx->tls_crypt_v2_metadata.data;
+ if (*metadata !=3D TLS_CRYPT_METADAT= A_TYPE_TIMESTAMP)
+ = {
+ msg(M_WA= RN, "ERROR: Client key does not have a timestamp.");
+ return false;

= + }
+
+ int64_t timestamp;
+ memcpy(&timestamp, metadata + 1, sizeof(int64_t));
+ timestamp =3D (in= t64_t)ntohll((uint64_t)timestamp);
+ int64_t max_age_in_seconds =3D max_days * 24 * 60 * 60;<= /span>
+ if (now - timest= amp > max_age_in_seconds)
+ {
+ = msg(M_WARN, "ERROR: Client key is too old.");
+ return false;
+ }

+ return true;
+}
+
+static bool
tls_crypt_v2_verify_metadata(const struct tls_wrap_ctx *ctx= , const struct tls_options *opt)
{
bo= ol ret =3D false;
@@ -634,6 +663,12 @@
= return false;
}

+ if (opt && opt->tls_= crypt_v2_max_age > 0 && !tls_crypt_v2_check_client_key_age(ctx, = opt->tls_crypt_v2_max_age))

+ {
+ = secure_memzero(&ctx->original_wrap_keydata, sizeof(ctx->orig= inal_wrap_keydata));
= + return false;
+
= if (opt && opt->tls_crypt_v2_verify_script &&= !tls_crypt_v2_verify_metadata(ctx, opt))
{
= secure_memzero(&ctx->original_wrap_keydata, sizeof(ct= x->original_wrap_keydata));

To view,= visit c= hange 1304. To unsubscribe, or for help writing mail filters, visit settings.

<= meta itemprop=3D"name" content=3D"View Change"/>
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I0579d18c784e2ac16973d555399= 2c28f281a0900
Gerrit-Change-Number: 1304
Gerrit-PatchSet: 7
Gerrit-Owner: MaxF <max@...2606...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --4SLtM//4S7A=--