Files
VoelinClient/third_party/dimpl/src/dtls12/message/hello_verify.rs
T
Claude d1c4424789 Vendor dimpl 0.7.4 unmodified and patch it in from third_party
str0m's DTLS stack (dimpl) hard-codes the SRTP profile a DTLS server picks
(AES-256-GCM first), with no way to configure it. Official TeamSpeak 6
clients use AES_CM_128_HMAC_SHA1_80, so we need to patch dimpl. This commit
only vendors the crate as published and routes crates.io's dimpl to it;
the change follows separately so it can be reviewed and dropped on its own.

third_party is excluded from the workspace so dimpl's dev-dependencies and
tests stay out of our builds, and own-crates.sh skips it like crates/proto.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
2026-09-26 23:27:21 +00:00

94 lines
2.4 KiB
Rust

use super::ProtocolVersion;
use super::id::Cookie;
use crate::buffer::Buf;
use nom::IResult;
use nom::error::{Error, ErrorKind};
#[derive(Debug, PartialEq, Eq)]
pub struct HelloVerifyRequest {
pub server_version: ProtocolVersion,
pub cookie: Cookie,
}
impl HelloVerifyRequest {
pub fn new(server_version: ProtocolVersion, cookie: Cookie) -> Self {
HelloVerifyRequest {
server_version,
cookie,
}
}
pub fn parse(input: &[u8]) -> IResult<&[u8], HelloVerifyRequest> {
let (input, server_version) = ProtocolVersion::parse(input)?;
let (input, cookie) = Cookie::parse(input)?;
if cookie.is_empty() {
return Err(nom::Err::Failure(Error::new(input, ErrorKind::LengthValue)));
}
Ok((
input,
HelloVerifyRequest {
server_version,
cookie,
},
))
}
pub fn serialize(&self, output: &mut Buf) {
output.extend_from_slice(&self.server_version.as_u16().to_be_bytes());
output.push(self.cookie.len() as u8);
output.extend_from_slice(&self.cookie);
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::buffer::Buf;
const MESSAGE: &[u8] = &[
0xFE, 0xFD, // ProtocolVersion::DTLS1_2
0x01, // Cookie length
0xBB, // Cookie
];
#[test]
fn roundtrip() {
let cookie = Cookie::try_new(&[0xBB]).unwrap();
let hello_verify_request = HelloVerifyRequest::new(ProtocolVersion::DTLS1_2, cookie);
// Serialize and compare to MESSAGE
let mut serialized = Buf::new();
hello_verify_request.serialize(&mut serialized);
assert_eq!(&*serialized, MESSAGE);
// Parse and compare with original
let (rest, parsed) = HelloVerifyRequest::parse(&serialized).unwrap();
assert_eq!(parsed, hello_verify_request);
assert!(rest.is_empty());
}
#[test]
fn empty_cookie() {
let message: &[u8] = &[
0xFE, 0xFD, // ProtocolVersion::DTLS1_2
0x00, // Cookie length (0, which is empty)
];
let result = HelloVerifyRequest::parse(message);
assert!(result.is_err());
}
#[test]
fn cookie_too_long() {
let mut message = MESSAGE.to_vec();
message[2] = 0xFF; // Cookie length (255, which is too long)
let result = HelloVerifyRequest::parse(&message);
assert!(result.is_err());
}
}