From 70bff48a54a35829ea43a2d696849a68fa60a6e2 Mon Sep 17 00:00:00 2001 From: c0repwn3r Date: Thu, 12 Jan 2023 10:39:53 -0500 Subject: [PATCH] [noise] fixup to transport to work correctly (actually set i_r on handshake messages) --- quicktap/src/noise/data.rs | 6 ++++-- quicktap/src/noise/handshake/mod.rs | 4 ++-- quicktap/src/noise/handshake/response.rs | 6 +++--- quicktap/src/noise/rfc6479/mod.rs | 4 +++- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/quicktap/src/noise/data.rs b/quicktap/src/noise/data.rs index 5c901f1..3166635 100644 --- a/quicktap/src/noise/data.rs +++ b/quicktap/src/noise/data.rs @@ -18,8 +18,8 @@ fn unpad_packet(p: &[u8]) -> Vec { /// This function will error if the encryption step is unsuccessful. pub fn encapsulate(state: &mut HandshakeState, packet: &Vec) -> Result, NoiseError> { let packet = pad_packet(packet); - let counter = state.n_send; - let packet_data = match qcrypto_aead(&state.t_send, state.n_send, &packet, &[]) { + let counter = state.n_send + 1; + let packet_data = match qcrypto_aead(&state.t_send, state.n_send + 1, &packet, &[]) { Ok(d) => d, Err(e) => return Err(NoiseError::ChaCha20Error(e)) }; @@ -32,6 +32,8 @@ pub fn encapsulate(state: &mut HandshakeState, packet: &Vec) -> Result HandshakeState<'a> { cookies: vec![], t_send: [0u8; 32], t_recv: [0u8; 32], - n_send: 0, - n_recv: 0, + n_send: 1, + n_recv: 1, we_are_initiator: false, bitfield: ShiftWindow::new() } diff --git a/quicktap/src/noise/handshake/response.rs b/quicktap/src/noise/handshake/response.rs index b18d3c2..2db6431 100644 --- a/quicktap/src/noise/handshake/response.rs +++ b/quicktap/src/noise/handshake/response.rs @@ -70,6 +70,9 @@ pub fn generate_handshake_response(session: &mut HandshakeState) -> Result<[u8; mac2: [0u8; 16] }; + msg.receiver = session.i_i.to_le_bytes(); + msg.sender = session.i_r.to_le_bytes(); + session.ck = qcrypto_hkdf::<1>(&session.ck, eph_keypair.1.as_bytes())[0]; msg.ephemeral = eph_keypair.1.to_bytes(); @@ -120,9 +123,6 @@ pub fn parse_handshake_response(session: &mut HandshakeState, packet: [u8; 92]) h = qcrypto_hash_twice(&h, &t); - println!("here"); - println!("{:?} {:?} {:?}", k, 0, h); - let empty = match qcrypto_aead_decrypt(&k, 0, &msg.empty, &h) { Ok(s) => s, Err(e) => return Err(NoiseError::ChaCha20Error(e)) diff --git a/quicktap/src/noise/rfc6479/mod.rs b/quicktap/src/noise/rfc6479/mod.rs index 17e6879..4b510c8 100644 --- a/quicktap/src/noise/rfc6479/mod.rs +++ b/quicktap/src/noise/rfc6479/mod.rs @@ -22,7 +22,9 @@ impl ShiftWindow { } /// Check if a given sequence value is okay given the current state of the shift window - pub const fn check_replay_window(&self, seq: u64) -> bool { + pub fn check_replay_window(&self, seq: u64) -> bool { + println!("sequence {} {}", seq, self.replaywin_lastseq); + // first == 0 or wrapped if seq == 0 { return false;