From: "MaxF (Code Review)"
Date: Sun, 26 Oct 2025 14:20:03 +0000
References:
Reply-To: max@...2606..., arne-openvpn@...1227...,
openvpn-devel@lists.sourceforge.net, frank@...2641...
Message-ID: <1c4ed9a766140c75d50fd545a402d5772892d2ab-HTML@...2715...>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Content-Type: multipart/alternative; boundary="XGNhTF+WDp4="; charset=UTF-8
Subject: [Openvpn-devel] [S] 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: plaisthos , flichtenheld
Cc: openvpn-devel
--XGNhTF+WDp4=
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is currently required from: flichtenheld, plaisthos.
Hello plaisthos, flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/1304?usp=3Demail
to review the following change.
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
---
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, 45 insertions(+), 1 deletion(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/04/1304/1
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).
=20
-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 aa2611d..a6331dc 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -3442,6 +3442,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 65c6b3b..10c14e1 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -653,6 +653,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"
@@ -9087,6 +9089,13 @@
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 009904a..9329030 100644
--- a/src/openvpn/options.h
+++ b/src/openvpn/options.h
@@ -682,6 +682,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 de89d30..0402a6a 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 51b4eb3..0afbe98 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"
@@ -528,6 +529,25 @@
}
static bool
+tls_crypt_v2_check_client_key_age(const struct tls_wrap_ctx *ctx, int max_=
days)
+{
+ 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 doesn't 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;
@@ -652,6 +672,10 @@
/* Remove client key from buffer so tls-crypt code can unwrap message =
*/
ASSERT(buf_inc_len(buf, -(BLEN(&wrapped_client_key))));
+ if (opt && opt->tls_crypt_v2_max_age > 0) {
+ return tls_crypt_v2_check_client_key_age(ctx, opt->tls_crypt_v2_ma=
x_age);
+ }
+
if (opt && opt->tls_crypt_v2_verify_script)
{
return tls_crypt_v2_verify_metadata(ctx, opt);
--
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: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I0579d18c784e2ac16973d5553992c28f281a0900
Gerrit-Change-Number: 1304
Gerrit-PatchSet: 1
Gerrit-Owner: MaxF
Gerrit-Reviewer: flichtenheld
Gerrit-Reviewer: plaisthos
Gerrit-CC: openvpn-devel
Gerrit-Attention: plaisthos
Gerrit-Attention: flichtenheld
--XGNhTF+WDp4=
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is cur=
rently required from: flichtenheld, plaisthos.
MaxF would like plaisthos and flichtenheld to review th=
is change.
V=
iew Change
Add option to check tls-crypt-v2 key timest=
amps
This commit adds the option --tls-crypt-v2-max-age n. When a cl=
ient 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 <revaban04@...2783...>
Change-Id: I0579d18c784=
e2ac16973d5553992c28f281a0900
---
M doc/man-sections/tls-options.rst<=
br>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, 45 insertions(+), 1 deletion(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/chang=
es/04/1304/1
diff --git a/doc/man-sections/tls-options.rst b/doc/ma=
n-sections/tls-options.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-z=
ero exit
code.
+--tls-crypt-v2-max-age n
+ Reject tls-crypt-v2 client keys th=
at are older than n days or have
+ no timestamp.
+
--tls-exit
Exit on TLS negoti=
ation failure. This option can be useful when you only
w=
ant to make one attempt at connecting, e.g. in a test or monitoring script.=
diff --git a/doc/tls-crypt-v2.txt b/doc/tls-crypt-v2.txt=
span>
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 r=
esponse 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 serve=
r optionally checks if the client key contains a timestamp that is+ below a maximum age confi=
gured with the --tls-crypt-v2-max-age option.
+
+5. Server optionally checks metadata using a --tls-crypt-v2-verify s=
cript
This allows early abort of conn=
ection, *before* we expose any of the
notoriously dange=
rous TLS, X.509 and ASN.1 parsers and thereby reduces the
d=
iff --git a/src/openvpn/init.c b/src/openvpn/init.c
index a=
a2611d..a6331dc 100644
--- a/src/openvpn/init.c
<=
span>+++ b/src/openvpn/init.c
@@ -3442,6 +3442,7 @@<=
br> {
to.tls_wrap.tls_crypt_v2_s=
erver_key =3D c->c1.ks.tls_crypt_v2_server_key;
=
to.tls_crypt_v2_verify_script =3D c->options.tls_crypt_v2_verify_sc=
ript;
+ 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/op=
tions.c b/src/openvpn/options.c
index 65c6b3b..10c14e1 1006=
44
--- a/src/openvpn/options.c
+++ b/src/op=
envpn/options.c
@@ -653,6 +653,8 @@
&q=
uot; fresh tls-crypt-v2 server key, and store to keyfile\n=
"
"--tls-crypt-v2-verify cmd : Run command c=
md 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 daemonize.\n"<=
/span>
"--auth-nocache : Don't cache --askpass or -=
-auth-user-pass passwords.\n"
"--crl-verify =
crl ['dir']: Check peer certificate against a CRL.\n"@@ -9087,6 +9089,13 @@
VERIFY_PERMISSION(O=
PT_P_GENERAL);
options->tls_crypt_v2_verify_scr=
ipt =3D p[1];
}
+ else if (streq(p[0], "tls-crypt-v2-max-age")=
&& p[1])
+ =
{
+ VERIFY_P=
ERMISSION(OPT_P_GENERAL);
+ if (!atoi_constrained(p[1], &options->tls_crypt_v2_max=
_age, "tls-crypt-v2-max-age", 1, INT_MAX, msglevel)) {
=
+ goto err;+ }
+ }
else if (st=
req(p[0], "x509-track") && p[1] && !p[2])<=
br> {
VERIFY_PERMISSION(OPT_P_GENERAL);<=
/span>
diff --git a/src/openvpn/options.h b/src/openvpn/options.h<=
/span>
index 009904a..9329030 100644
--- a/src/ope=
nvpn/options.h
+++ b/src/openvpn/options.h
=
@@ -682,6 +682,8 @@
const char *tls_=
crypt_v2_verify_script;
+ int tls_crypt_v2_max_age;
+
/* Allow only one s=
ession */
bool single_session;
diff --git a/src/openvpn/ssl_common.h b/src/openvpn/ssl_common.h=
index de89d30..0402a6a 100644
--- a/src/op=
envpn/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 sta=
te */
struct tls_wrap_ctx tls_wrap;
di=
ff --git a/src/openvpn/tls_crypt.c b/src/openvpn/tls_crypt.c
index 51b4eb3..0afbe98 100644
--- a/src/openvpn/tls_crypt=
.c
+++ b/src/openvpn/tls_crypt.c
@@ -29,6 +=
29,7 @@
#include "argv.h"
#incl=
ude "base64.h"
#include "crypto.h"
+#include "integer.=
h"
#include "platform.h"
#=
include "run_command.h"
#include "session_i=
d.h"
@@ -528,6 +529,25 @@
}
static bool
+tls_crypt_v2_check_client_key_age(const struct tls_wrap_c=
tx *ctx, int max_days)
+{
+ 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 doesn't have a timestamp.&qu=
ot;);
+ return=
false;
+ }=
+ int64_t timestamp;
+ memcpy(×ta=
mp, 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) {<=
br>+ msg(M_WARN, "E=
RROR: Client key is too old.");
+ return false;
+ }
+ return true;
+}
+
+static bool
tls_cr=
ypt_v2_verify_metadata(const struct tls_wrap_ctx *ctx, const struct tls_opt=
ions *opt)
{
bool ret =3D false;
@@ -652,6 +672,10 @@
/* Remove client key =
from buffer so tls-crypt code can unwrap message */
AS=
SERT(buf_inc_len(buf, -(BLEN(&wrapped_client_key))));
=
+ if (opt &&a=
mp; opt->tls_crypt_v2_max_age > 0) {
+ return tls_crypt_v2_check_client_key_age(ctx=
, opt->tls_crypt_v2_max_age);
+ }
+<=
/span>
if (opt && opt->tls_crypt_v2_verify_script)=
{
return tls_crypt_v2_verify=
_metadata(ctx, opt);
To view, visit change 1304=
. To unsubscribe, or for help writing mail filters, visit settings.
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I0579d18c784e2ac16973d555399=
2c28f281a0900
Gerrit-Change-Number: 1304
Gerrit-PatchSet: 1
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>
Gerrit-Attention: plaisthos <arne-openvpn@...220...=
..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...=
41...>
=
--XGNhTF+WDp4=--