diff --git a/libs/hbb_common b/libs/hbb_common index 445486cca..1266b5615 160000 --- a/libs/hbb_common +++ b/libs/hbb_common @@ -1 +1 @@ -Subproject commit 445486ccaae6cbe9c45adca11916a04969cdefd1 +Subproject commit 1266b56150da889dfec318e68b9b20d7c30c0bb6 diff --git a/src/client.rs b/src/client.rs index 38c77bb84..b720c488a 100644 --- a/src/client.rs +++ b/src/client.rs @@ -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(), diff --git a/src/server.rs b/src/server.rs index 34f60080b..1e77d3076 100644 --- a/src/server.rs +++ b/src/server.rs @@ -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, }, )?;