From fc8efe50601d4b251ee3c9be8ed80ec2b97ddd02 Mon Sep 17 00:00:00 2001 From: antifallobst Date: Tue, 21 May 2024 04:59:23 +0200 Subject: [PATCH] fix(cbs): added missing parts of the handshake --- src/cbs/connection.rs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/cbs/connection.rs b/src/cbs/connection.rs index a89c277..4397a48 100644 --- a/src/cbs/connection.rs +++ b/src/cbs/connection.rs @@ -56,14 +56,21 @@ impl UnstableConnection { let packet = Packet::recv(&mut sock_rx, &cipher, &nonce).await?; match packet { Packet::Request { id, body } => { - Packet::response(id_pool.acquire(), id, Response::Success) - .send(&mut sock_tx, &cipher, &nonce) - .await?; + match body { + Request::HandshakeUpgradeConnection => { + Packet::response(id_pool.acquire(), id, Response::Success) + .send(&mut sock_tx, &cipher, &nonce) + .await?; - cli_log::info!( - "CBS {id}: upgraded connection to encrypted messagepack", - id = self.id - ); + cli_log::info!( + "CBS {id}: upgraded connection to encrypted messagepack", + id = self.id + ); + } + req => return Err(anyhow!( + "expected cbs to send: Request::HandshakeUpgradeConnection, but got: Request::{req}" + )) + } } body => { return Err(anyhow!( @@ -72,6 +79,10 @@ impl UnstableConnection { } } + Packet::request(id_pool.acquire(), Request::HandshakeSuccess) + .send(&mut sock_tx, &cipher, &nonce) + .await?; + // Poll packets from socket { let cipher = cipher.clone();