Skip to content

Commit

Permalink
Added validation on handshake packet size
Browse files Browse the repository at this point in the history
  • Loading branch information
dynos01 committed Jun 21, 2023
1 parent 20ac3c3 commit 59d8719
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ pub(crate) fn validate_handshake(packet: &[u8]) -> Result<()> {
Some(key) => key,
None => unreachable!(),
};

if packet.len() < 16 + 12 { // Reserved + nonce
debug!("Handshake packet too small");
return Err(Box::new(ProtocolError::AuthenticationError));
}

let cipher = ChaCha20Poly1305::new_from_slice(hashed_key)?;
let packet = &packet[16..]; //Drop reserved 16 bytes for now
let nonce = GenericArray::clone_from_slice(&packet[..12]);
Expand Down

0 comments on commit 59d8719

Please sign in to comment.