Skip to contentSkip to conversation

Change in openvpn[master]: tls_multi_process: promote lame duck key to primary after reneg

Openvpn-devel New ralf_lici (Code Review) 2 participants 7 messages Jan 19 – Mar 2 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1768848003000.I704c560fa23c03237d0f8adc30908a617265a5a1@...2715...

#1 lore raw

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1478?usp=email

to review the following change.

Change subject: tls_multi_process: promote lame duck key to primary after reneg
......................................................................

tls_multi_process: promote lame duck key to primary after reneg

When a key is negotiated, the transition window logic imposes a delay before fully adopting the new key. The auth_deferred_expire field indicates the interval we must wait before considering the key fully usable (see tls_select_encryption_key). However, in an unfortunate scenario where the remote peer uses a reneg-sec interval lower than our handshake window or lower than half of our reneg-sec interval, we end up initializing every key with an auth_deferred_expire value that never expires. This leads to selecting the wrong key when invoking tls_select_encryption_key.

To ensure we always have a fully valid key, whenever a renegotiation happens, promote the old key even if its auth_deferred_expire has not yet expired.

Change-Id: I704c560fa23c03237d0f8adc30908a617265a5a1
---
M src/openvpn/ssl.c

1 file changed, 5 insertions(+), 0 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/78/1478/1

src/openvpn/ssl.c +5 -0
index 69d0e4e..6a28b64 100644
@@ -3310,6 +3310,11 @@
                 ks->state = S_ERROR_PRE;
             }
 
+            /* make the lame duck key the primary one while we transition to
+             * the new one */
+            struct key_state *ks_lame = &session->key[KS_LAME_DUCK];
+            ks_lame->auth_deferred_expire = now;
+
             /* Update auth token on the client if needed on renegotiation
              * (key id !=0) */
             if (session->key[KS_PRIMARY].key_id != 0)

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1478?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I704c560fa23c03237d0f8adc30908a617265a5a1
Gerrit-Change-Number: 1478
Gerrit-PatchSet: 1
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>

#2 lore raw

[Openvpn-devel] [S] Change in openvpn[master]: tls: reject incoming reneg request if primary key is not fully valid

In reply to a message not in the archive

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1478?usp=email

to look at the new patch set (#2).

Change subject: tls: reject incoming reneg request if primary key is not fully valid
......................................................................

tls: reject incoming reneg request if primary key is not fully valid

An incoming P_CONTROL_SOFT_RESET_V1 can arrive while the primary key is already in S_GENERATED_KEYS but no longer fully authorized. This can happen when deferred auth later expires/fails, or when mid-session auth checks deauthenticate the key without demoting its TLS state.

This patch keeps read_control_auth as the first gate, then rejects the incoming renegotiation request unless the primary key is KS_AUTH_TRUE and its auth_deferred_expire gate has passed.

Change-Id I704c560fa23c03237d0f8adc30908a617265a5a1

---
M src/openvpn/ssl.c

1 file changed, 11 insertions(+), 0 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/78/1478/2

src/openvpn/ssl.c +11 -0
index 69d0e4e..ce88478 100644
@@ -3747,6 +3747,17 @@
                 goto error;
             }
 
+            /*
+             * Do not allow incoming renegotiation unless our primary key is
+             * fully authenticated and past the deferred-auth/transition gate.
+             */
+            if (ks->authenticated != KS_AUTH_TRUE || now < ks->auth_deferred_expire)
+            {
+                msg(D_TLS_ERRORS,
+                    "TLS Error: rejecting incoming renegotiation request: key not fully authenticated/valid");
+                goto error;
+            }
+
             key_state_soft_reset(session);
 
             dmsg(D_TLS_DEBUG, "TLS: received P_CONTROL_SOFT_RESET_V1 s=%d sid=%s", i,

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1478?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I704c560fa23c03237d0f8adc30908a617265a5a1
Gerrit-Change-Number: 1478
Gerrit-PatchSet: 2
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>

#3 lore raw

[Openvpn-devel] [S] Change in openvpn[master]: tls: reject incoming reneg request if primary key is not fully valid

In reply to a message not in the archive

Attention is currently required from: ralf_lici.

plaisthos has posted comments on this change by ralf_lici. ( http://gerrit.openvpn.net/c/openvpn/+/1478?usp=email )

Change subject: tls: reject incoming reneg request if primary key is not fully valid
......................................................................

Patch Set 2: Code-Review+2

(2 comments)

Commit Message:

http://gerrit.openvpn.net/c/openvpn/+/1478/comment/d36c7cbc_c403a599?usp=email :
PS2, Line 12: checks deauthenticate the key without demoting its TLS state.
Should we add the scenario where we just waiting for the hand-window to have the key be fully authenticated? The patch seem to address this but the commit message does not.

File src/openvpn/ssl.c:

http://gerrit.openvpn.net/c/openvpn/+/1478/comment/7f990c4b_9382fc22?usp=email :
PS2, Line 3757: "TLS Error: rejecting incoming renegotiation request: key not fully authenticated/valid");
Maybe make this message a bit more verbose to help later debugging and print the key-id in ks too?

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1478?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I704c560fa23c03237d0f8adc30908a617265a5a1
Gerrit-Change-Number: 1478
Gerrit-PatchSet: 2
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: ralf_lici <[email protected]...>
Gerrit-Comment-Date: Mon, 16 Feb 2026 14:32:19 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes

#4 lore raw

[Openvpn-devel] [S] Change in openvpn[master]: tls: reject incoming reneg request if primary key is not fully valid

In reply to a message not in the archive

Attention is currently required from: plaisthos, ralf_lici.

Hello plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1478?usp=email

to look at the new patch set (#3).

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

The change is no longer submittable: Code-Review and checks~ChecksSubmitRule are unsatisfied now.

Change subject: tls: reject incoming reneg request if primary key is not fully valid
......................................................................

tls: reject incoming reneg request if primary key is not fully valid

Incoming P_CONTROL_SOFT_RESET_V1 can arrive while the active key is not yet fully valid for renegotiation. This includes the window where we are still waiting for auth_deferred_expire (derived from handshake/reneg timing), as well as cases where deferred or mid-session auth later leaves the key non-authenticated even though state is S_GENERATED_KEYS.

This patch keeps read_control_auth as the first gate, then rejects the incoming renegotiation requests unless the primary key is KS_AUTH_TRUE and auth_deferred_expire has passed.

Change-Id I704c560fa23c03237d0f8adc30908a617265a5a1

---
M src/openvpn/ssl.c

1 file changed, 14 insertions(+), 0 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/78/1478/3

src/openvpn/ssl.c +14 -0
index 69d0e4e..98641a1 100644
@@ -3747,6 +3747,20 @@
                 goto error;
             }
 
+            /*
+             * Do not allow incoming renegotiation unless our primary key is
+             * fully authenticated and past the deferred-auth/transition gate.
+             */
+            time_t auth_deferred_left = ks->auth_deferred_expire - now;
+            if (ks->authenticated != KS_AUTH_TRUE || auth_deferred_left > 0)
+            {
+                msg(D_TLS_ERRORS,
+                    "TLS Error: rejecting incoming renegotiation request for key-id %d: "
+                    "auth=%s, auth_deferred_expire in %d seconds",
+                    ks->key_id, ks_auth_name(ks->authenticated), auth_deferred_left > 0 ? (int)auth_deferred_left : 0);
+                goto error;
+            }
+
             key_state_soft_reset(session);
 
             dmsg(D_TLS_DEBUG, "TLS: received P_CONTROL_SOFT_RESET_V1 s=%d sid=%s", i,

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1478?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I704c560fa23c03237d0f8adc30908a617265a5a1
Gerrit-Change-Number: 1478
Gerrit-PatchSet: 3
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: ralf_lici <[email protected]...>

#5 lore raw

[Openvpn-devel] [S] Change in openvpn[master]: tls: reject incoming reneg request if primary key is not fully valid

In reply to a message not in the archive

Attention is currently required from: plaisthos.

ralf_lici has posted comments on this change by ralf_lici. ( http://gerrit.openvpn.net/c/openvpn/+/1478?usp=email )

Change subject: tls: reject incoming reneg request if primary key is not fully valid
......................................................................

Patch Set 3:

(2 comments)

Commit Message:

http://gerrit.openvpn.net/c/openvpn/+/1478/comment/02b189c3_6784af74?usp=email :
PS2, Line 12: checks deauthenticate the key without demoting its TLS state.

Quoted 1 line

Should we add the scenario where we just waiting for the hand-window to have the key be fully authen […]

Done

File src/openvpn/ssl.c:

http://gerrit.openvpn.net/c/openvpn/+/1478/comment/5ea276c4_a76158a4?usp=email :
PS2, Line 3757: "TLS Error: rejecting incoming renegotiation request: key not fully authenticated/valid");

Quoted 1 line

Maybe make this message a bit more verbose to help later debugging and print the key-id in ks too?

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1478?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I704c560fa23c03237d0f8adc30908a617265a5a1
Gerrit-Change-Number: 1478
Gerrit-PatchSet: 3
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Comment-Date: Tue, 17 Feb 2026 08:10:55 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: plaisthos <[email protected]...>

#6 lore raw

[Openvpn-devel] [S] Change in openvpn[master]: tls: reject incoming reneg request if primary key is not fully valid

In reply to a message not in the archive

Attention is currently required from: ralf_lici.

plaisthos has posted comments on this change by ralf_lici. ( http://gerrit.openvpn.net/c/openvpn/+/1478?usp=email )

Change subject: tls: reject incoming reneg request if primary key is not fully valid
......................................................................

Patch Set 3: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1478?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I704c560fa23c03237d0f8adc30908a617265a5a1
Gerrit-Change-Number: 1478
Gerrit-PatchSet: 3
Gerrit-Owner: ralf_lici <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: ralf_lici <[email protected]...>
Gerrit-Comment-Date: Mon, 02 Mar 2026 15:06:28 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes

#7 lore raw

PATCH v3 1/1 tls: reject incoming reneg request if primary key is not fully valid

In reply to a message not in the archive

From: Ralf Lici <[email protected]...>

Incoming P_CONTROL_SOFT_RESET_V1 can arrive while the active key is not yet fully valid for renegotiation. This includes the window where we are still waiting for auth_deferred_expire (derived from handshake/reneg timing), as well as cases where deferred or mid-session auth later leaves the key non-authenticated even though state is S_GENERATED_KEYS.

This patch keeps read_control_auth as the first gate, then rejects the incoming renegotiation requests unless the primary key is KS_AUTH_TRUE and auth_deferred_expire has passed.

Change-Id I704c560fa23c03237d0f8adc30908a617265a5a1

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1478
---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1478
This mail reflects revision 3 of this Change.

Acked-by according to Gerrit (reflected above):
Arne Schwabe <[email protected]...>

src/openvpn/ssl.c +14 -0
index 69d0e4e..98641a1 100644
@@ -3747,6 +3747,20 @@
                 goto error;
             }
 
+            /*
+             * Do not allow incoming renegotiation unless our primary key is
+             * fully authenticated and past the deferred-auth/transition gate.
+             */
+            time_t auth_deferred_left = ks->auth_deferred_expire - now;
+            if (ks->authenticated != KS_AUTH_TRUE || auth_deferred_left > 0)
+            {
+                msg(D_TLS_ERRORS,
+                    "TLS Error: rejecting incoming renegotiation request for key-id %d: "
+                    "auth=%s, auth_deferred_expire in %d seconds",
+                    ks->key_id, ks_auth_name(ks->authenticated), auth_deferred_left > 0 ? (int)auth_deferred_left : 0);
+                goto error;
+            }
+
             key_state_soft_reset(session);
 
             dmsg(D_TLS_DEBUG, "TLS: received P_CONTROL_SOFT_RESET_V1 s=%d sid=%s", i,