From: "MaxF (Code Review)" Date: Mon, 27 Oct 2025 15:56:30 +0000 References: Reply-To: max@...2606..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="RvMextVcS+k="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Zeroize tls-crypt-v2 client keys List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --RvMextVcS+k= 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/+/1315?usp=3Demail to review the following change. Change subject: Zeroize tls-crypt-v2 client keys ...................................................................... Zeroize tls-crypt-v2 client keys Joshua Rogers sent in a bug report generated with ZeroPath that the tls-crypt-v2 client key is loaded before running the verify script. If the verify script fails, the key is not zeroized. While investigating this report, I found that free_tls_pre_decrypt_state never zeroizes tls_wrap_tmp.original_wrap_keydata. So also when the check is successful, key data will remain in memory when it is no longer needed. This commit moves the tls-crypt-v2-verify check before loading the key. If it fails, original_wrap_keydata is zeroized. Also, in free_tls_pre_decrypt_state, if a key has been loaded, original_wrap_keydata is zeroized. Change-Id: Icfcbf8ee20c1c0016eb98b570f24b9325b157c5c Signed-off-by: Max Fillinger --- M src/openvpn/ssl_pkt.c M src/openvpn/tls_crypt.c 2 files changed, 7 insertions(+), 5 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/15/1315/1 diff --git a/src/openvpn/ssl_pkt.c b/src/openvpn/ssl_pkt.c index 825719c..d7f7ac3 100644 --- a/src/openvpn/ssl_pkt.c +++ b/src/openvpn/ssl_pkt.c @@ -280,6 +280,7 @@ if (state->tls_wrap_tmp.cleanup_key_ctx) { free_key_ctx_bi(&state->tls_wrap_tmp.opt.key_ctx_bi); + secure_memzero(&state->tls_wrap_tmp.original_wrap_keydata, sizeof(= state->tls_wrap_tmp.original_wrap_keydata)); } } diff --git a/src/openvpn/tls_crypt.c b/src/openvpn/tls_crypt.c index 51b4eb3..a808de3 100644 --- a/src/openvpn/tls_crypt.c +++ b/src/openvpn/tls_crypt.c @@ -642,6 +642,12 @@ 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)); + return false; + } + /* Load the decrypted key */ ctx->mode =3D TLS_WRAP_CRYPT; ctx->cleanup_key_ctx =3D true; @@ -652,11 +658,6 @@ /* 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_verify_script) - { - return tls_crypt_v2_verify_metadata(ctx, opt); - } - return true; } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1315?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: Icfcbf8ee20c1c0016eb98b570f24b9325b157c5c Gerrit-Change-Number: 1315 Gerrit-PatchSet: 1 Gerrit-Owner: MaxF Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld --RvMextVcS+k= 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

Zeroize tls-crypt-v2 client keys

Jos= hua Rogers sent in a bug report generated with ZeroPath that the
tls-cry= pt-v2 client key is loaded before running the verify script. If
the veri= fy script fails, the key is not zeroized.

While investigating this r= eport, I found that free_tls_pre_decrypt_state
never zeroizes tls_wrap_t= mp.original_wrap_keydata. So also when the
check is successful, key data= will remain in memory when it is no longer
needed.

This commit m= oves the tls-crypt-v2-verify check before loading the key.
If it fails, = original_wrap_keydata is zeroized. Also, in
free_tls_pre_decrypt_state, = if a key has been loaded,
original_wrap_keydata is zeroized.

Chan= ge-Id: Icfcbf8ee20c1c0016eb98b570f24b9325b157c5c
Signed-off-by: Max Fill= inger <max@...2606...>
---
M src/openvpn/ssl_pkt.c
M src/ope= nvpn/tls_crypt.c
2 files changed, 7 insertions(+), 5 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/c=
hanges/15/1315/1
diff --git a/src/openvpn/ssl_pkt.c b/src/openvpn/s=
sl_pkt.c
index 825719c..d7f7ac3 100644
--- = a/src/openvpn/ssl_pkt.c
+++ b/src/openvpn/ssl_pkt.c<= br>@@ -280,6 +280,7 @@
if (state->tls_wrap_tm= p.cleanup_key_ctx)
{
free_key= _ctx_bi(&state->tls_wrap_tmp.opt.key_ctx_bi);
+ secure_memzero(&state->tls= _wrap_tmp.original_wrap_keydata, sizeof(state->tls_wrap_tmp.original_wra= p_keydata));
}
}

diff --git a/src/openvpn/tls_crypt.c b/src/openvpn/tls_crypt.= c
index 51b4eb3..a808de3 100644
--- a/src/o= penvpn/tls_crypt.c
+++ b/src/openvpn/tls_crypt.c
= @@ -642,6 +642,12 @@
return false; }

+ if (opt && opt->tls_crypt_v2_verify_script &= & !tls_crypt_v2_verify_metadata(ctx, opt))
+ {
+ secure_memzero(&ctx->original_wrap_keydata, siz= eof(ctx->original_wrap_keydata));
+ return false;
+ }
+
/* Load the decrypted key */
= ctx->mode =3D TLS_WRAP_CRYPT;
ctx->cleanup_key= _ctx =3D true;
@@ -652,11 +658,6 @@
/*= 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_verify_script)
- {
- return tls_crypt_v2_verify_metadata(ctx, opt);
- }
-
return true;
}


To vie= w, visit change 1315. To unsubscribe, or for help writing mail filters, visit <= a href=3D"http://gerrit.openvpn.net/settings?usp=3Demail">settings.

=
<= meta itemprop=3D"name" content=3D"View Change"/>
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Icfcbf8ee20c1c0016eb98b570f2= 4b9325b157c5c
Gerrit-Change-Number: 1315
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...>
= --RvMextVcS+k=--