From b6897cb1d755a40defc4fd54cd2c5fdb04678919 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Wed, 23 Sep 2026 09:53:34 +0800 Subject: [PATCH] key exchange: one call sets the negotiated key bump hbb_common cbc8772: Stream::set_negotiated_key. The rendezvous client, the controller and the controlled side each branched on the picked version to choose between split and single keys. They now hand the transcript to Stream, which makes that choice once. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019aokqJuhjvB3kijXtAg5Ns --- libs/hbb_common | 2 +- src/client.rs | 24 ++++++++++-------------- src/common.rs | 24 ++++++++++-------------- src/server.rs | 24 ++++++++++-------------- 4 files changed, 31 insertions(+), 43 deletions(-) diff --git a/libs/hbb_common b/libs/hbb_common index 26582e163..cbc8772d4 160000 --- a/libs/hbb_common +++ b/libs/hbb_common @@ -1 +1 @@ -Subproject commit 26582e163d7bb581d00f02094c68a739d01e157a +Subproject commit cbc8772d4ab749c70634b2f1c7e76e509e69f363 diff --git a/src/client.rs b/src/client.rs index b720c488a..d5a4abb0b 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1727,20 +1727,16 @@ impl Client { ..Default::default() }); timeout(CONNECT_TIMEOUT, conn.send(&msg_out)).await??; - if picked >= 1 { - conn.set_key_split( - key, - true, - &hbb_common::tcp::KxTranscript { - initiator_pk: &asymmetric_value, - responder_pk: &their_pk_b, - advertised: kx_version, - picked, - }, - )?; - } else { - conn.set_key(key); - } + conn.set_negotiated_key( + key, + true, + &hbb_common::tcp::KxTranscript { + initiator_pk: &asymmetric_value, + responder_pk: &their_pk_b, + advertised: kx_version, + picked, + }, + )?; } else { if is_webrtc { bail!("WebRTC handshake id mismatch (possible MITM)"); diff --git a/src/common.rs b/src/common.rs index 3188b8b03..6fb43da1c 100644 --- a/src/common.rs +++ b/src/common.rs @@ -2128,20 +2128,16 @@ async fn key_exchange(conn: &mut Stream, key: &str, log_on_success: bool) -> Res ..Default::default() }); timeout(CONNECT_TIMEOUT, conn.send(&msg_out)).await??; - if version >= 1 { - conn.set_key_split( - key, - true, - &hbb_common::tcp::KxTranscript { - initiator_pk: &asymmetric_value, - responder_pk: &their_pk_b, - advertised: ex.version, - picked: version, - }, - )?; - } else { - conn.set_key(key); - } + conn.set_negotiated_key( + key, + true, + &hbb_common::tcp::KxTranscript { + initiator_pk: &asymmetric_value, + responder_pk: &their_pk_b, + advertised: ex.version, + picked: version, + }, + )?; if log_on_success { log::info!("Connection secured"); } diff --git a/src/server.rs b/src/server.rs index 80a56c851..6384d88e0 100644 --- a/src/server.rs +++ b/src/server.rs @@ -318,20 +318,16 @@ async fn identity_handshake(stream: &mut Stream, secure: bool) -> ResultType<()> pk.kx_version ); } - if pk.kx_version >= 1 { - stream.set_key_split( - key, - false, - &tcp::KxTranscript { - initiator_pk: &pk.asymmetric_value, - responder_pk: &our_pk_b.0, - advertised, - picked: pk.kx_version, - }, - )?; - } else { - stream.set_key(key); - } + stream.set_negotiated_key( + key, + false, + &tcp::KxTranscript { + initiator_pk: &pk.asymmetric_value, + responder_pk: &our_pk_b.0, + advertised, + picked: pk.kx_version, + }, + )?; } else if pk.asymmetric_value.is_empty() { Config::set_key_confirmed(false); log::info!("Force to update pk");