key exchange: say 0 on WebRTC, where no stream key applies

A WebRTC stream is encrypted by DTLS and `set_key_split` collapses to
`set_key` on it, which sets nothing but `peer_verified`. Both sides still
put 1 on the wire, the controlled peer in its signed identity and the
controller in its pick, and agreed on a version neither applied. That held
only because both fell into the same branch: the day one side splits keys
on WebRTC and the other does not, they would agree on 1, derive different
keys, and have no version mismatch to point at.

The controlled peer now advertises 0 on WebRTC and refuses a pick above
what it advertised rather than above the newest it speaks anywhere; the
controller picks 0 there. What is on the wire is what runs.

Also bumps hbb_common for the echo contract: the server tags every
message after the exchange, not the first alone, so dropping one frame at
a known position does not rid an attacker of the downgrade check.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EZ49AbZJYfm8NTp5yDPMab
This commit is contained in:
rustdesk
2026-09-22 13:20:29 +08:00
co-authored by Claude Fable 5.1
parent 6eab60c3e7
commit 818907602f
3 changed files with 22 additions and 6 deletions
+7 -1
View File
@@ -1712,7 +1712,13 @@ impl Client {
}
let (asymmetric_value, symmetric_value, key) =
create_symmetric_key_msg(their_pk_b);
let picked = hbb_common::tcp::kx_version_for(kx_version);
// A WebRTC stream is encrypted by DTLS and takes no stream
// key of its own, split or not, so the pick says what runs: 0.
let picked = if is_webrtc {
0
} else {
hbb_common::tcp::kx_version_for(kx_version)
};
let mut msg_out = Message::new();
msg_out.set_public_key(PublicKey {
asymmetric_value: asymmetric_value.clone(),
+14 -4
View File
@@ -276,13 +276,21 @@ async fn identity_handshake(stream: &mut Stream, secure: bool) -> ResultType<()>
if stream.is_webrtc() && dtls_fingerprint.is_empty() {
bail!("WebRTC local DTLS fingerprint unavailable");
}
// A WebRTC stream is encrypted by DTLS and takes no stream key of its own, split or
// not, so what it advertises is what it runs: 0. Saying 1 there would have a future
// controller that splits keys on WebRTC agree on a version this side never applies.
let advertised = if stream.is_webrtc() {
0
} else {
tcp::KX_VERSION_LATEST
};
msg_out.set_signed_id(SignedId {
id: sign::sign(
&IdPk {
id: Config::get_id(),
pk: Bytes::from(our_pk_b.0.to_vec()),
dtls_fingerprint,
kx_version: tcp::KX_VERSION_LATEST,
kx_version: advertised,
..Default::default()
}
.write_to_bytes()
@@ -305,8 +313,10 @@ async fn identity_handshake(stream: &mut Stream, secure: bool) -> ResultType<()>
&our_sk_b,
)?;
// The controller picks from what we offered; anything above that
// is a bug or tampering, never a legitimate peer.
if pk.kx_version > tcp::KX_VERSION_LATEST {
// is a bug or tampering, never a legitimate peer. Below it needs no
// check: the version picked goes into both transcripts, so a pick
// lowered on the way leaves the two sides with different keys.
if pk.kx_version > advertised {
bail!(
"Handshake failed: key exchange version {} not offered",
pk.kx_version
@@ -319,7 +329,7 @@ async fn identity_handshake(stream: &mut Stream, secure: bool) -> ResultType<()>
&tcp::KxTranscript {
initiator_pk: &pk.asymmetric_value,
responder_pk: &our_pk_b.0,
advertised: tcp::KX_VERSION_LATEST,
advertised,
picked: pk.kx_version,
},
)?;