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
95 lines
2.6 KiB
Rust
95 lines
2.6 KiB
Rust
//! DTLS 1.2 curve type definitions.
|
|
//!
|
|
//! NamedGroup is now in crate::types as it's shared between DTLS versions.
|
|
//! CurveType is DTLS 1.2 specific (used in ServerKeyExchange).
|
|
|
|
use nom::IResult;
|
|
use nom::number::complete::be_u8;
|
|
use std::fmt;
|
|
|
|
/// Curve type for ECDH parameters in DTLS 1.2.
|
|
///
|
|
/// This is specific to DTLS 1.2's ServerKeyExchange message format.
|
|
#[repr(transparent)]
|
|
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
|
|
pub struct CurveType(u8);
|
|
|
|
#[allow(non_upper_case_globals)]
|
|
impl CurveType {
|
|
/// Explicit prime curve parameters.
|
|
pub const ExplicitPrime: Self = Self(1);
|
|
/// Explicit characteristic-2 curve parameters.
|
|
pub const ExplicitChar2: Self = Self(2);
|
|
/// Named curve (the common case).
|
|
pub const NamedCurve: Self = Self(3);
|
|
|
|
/// Convert a u8 value to a `CurveType`.
|
|
pub const fn from_u8(value: u8) -> Self {
|
|
Self(value)
|
|
}
|
|
|
|
/// Convert this `CurveType` to its u8 value.
|
|
pub const fn as_u8(&self) -> u8 {
|
|
self.0
|
|
}
|
|
|
|
const fn is_unknown(&self) -> bool {
|
|
!matches!(*self, Self(1..=3))
|
|
}
|
|
|
|
/// Parse a `CurveType` from wire format.
|
|
pub fn parse(input: &[u8]) -> IResult<&[u8], CurveType> {
|
|
let (input, value) = be_u8(input)?;
|
|
Ok((input, CurveType::from_u8(value)))
|
|
}
|
|
}
|
|
|
|
impl fmt::Debug for CurveType {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
if self.is_unknown() {
|
|
return f.debug_tuple("Unknown").field(&self.0).finish();
|
|
}
|
|
|
|
let name = match *self {
|
|
CurveType::ExplicitPrime => "ExplicitPrime",
|
|
CurveType::ExplicitChar2 => "ExplicitChar2",
|
|
CurveType::NamedCurve => "NamedCurve",
|
|
_ => unreachable!("known DTLS 1.2 curve type missing Debug label"),
|
|
};
|
|
|
|
f.write_str(name)
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn curve_type_newtype_shape() {
|
|
assert_eq!(std::mem::size_of::<CurveType>(), 1);
|
|
}
|
|
|
|
#[test]
|
|
fn curve_type_wire_roundtrip() {
|
|
for curve_type in [
|
|
CurveType::ExplicitPrime,
|
|
CurveType::ExplicitChar2,
|
|
CurveType::NamedCurve,
|
|
] {
|
|
assert_eq!(CurveType::from_u8(curve_type.as_u8()), curve_type);
|
|
assert!(!curve_type.is_unknown());
|
|
}
|
|
|
|
let unknown = CurveType::from_u8(0xFF);
|
|
assert_eq!(unknown.as_u8(), 0xFF);
|
|
assert!(unknown.is_unknown());
|
|
}
|
|
|
|
#[test]
|
|
fn curve_type_debug_stays_enum_like() {
|
|
assert_eq!(format!("{:?}", CurveType::NamedCurve), "NamedCurve");
|
|
assert_eq!(format!("{:?}", CurveType::from_u8(0xFF)), "Unknown(255)");
|
|
}
|
|
}
|