M1: dalek 4, fuzzing and fixes, tsc-model with server flavor

- curve25519-dalek-ng -> curve25519-dalek 4.
- fuzz/: cargo-fuzz targets for packets, commands and the license chain,
  plus a nightly workflow. Fixes for the panics they found: empty
  license, unchecked license property bounds, wrong index in the C2S
  audio invalid-codec error.
- tsc-model: ServerVersion/ServerFlavor/Capabilities parsed from
  virtualserver_version; tsctl shows the flavor in the tree header.
- CI lints every non-vendored crate via scripts/own-crates.sh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
This commit is contained in:
Claude committed 2026-09-25 13:40:56 +00:00
1 parent 369cbde85d
commit aa19afbcd0
24 files changed
+1835 -57

No files matched your search

+9
View File
@@ -51,3 +51,12 @@ against or offered back to upstream.
`notifystreamsignaling`, `notifystreamclientjoined`, `notifystreamclientleft`) and
commands (`setupstream`, `stopstream`, `streamsignaling`, `respondjoinstreamrequest`,
`removeclientfromstream`). See `docs/protocol-notes/ts6-streaming.md`.
5. **`curve25519-dalek-ng` → `curve25519-dalek` 4** (`tsproto-types`, `tsproto`). The `-ng`
fork is unmaintained; the API is the same apart from the basepoint table being a
reference. Verified by the license-chain unit tests and a live TeamSpeak 6 handshake.
6. **Panics on malformed input found by fuzzing** (`fuzz/`):
- `tsproto/src/license.rs`: an empty license (`initivexpand2 l=`) indexed `data[0]`;
license properties indexed past the end or with start > end. All property reads
are bounds-checked now.
- `tsproto-packets/src/packets.rs`: the invalid-codec error for short C2S audio
packets read `content[4]` instead of the codec byte `content[2]`.
+10 -2
View File
@@ -659,7 +659,7 @@ impl<'a> AudioData<'a> {
Ok(AudioData::C2S {
id,
codec: CodecType::from_u8(content[2])
.ok_or_else(|| Error::InvalidCodec(content[4]))?,
.ok_or_else(|| Error::InvalidCodec(content[2]))?,
data: &content[3..],
})
}
@@ -679,7 +679,7 @@ impl<'a> AudioData<'a> {
return Err(Error::PacketContentTooShort(content.len()));
}
let codec =
CodecType::from_u8(content[2]).ok_or_else(|| Error::InvalidCodec(content[4]))?;
CodecType::from_u8(content[2]).ok_or_else(|| Error::InvalidCodec(content[2]))?;
if newprotocol {
if content.len() < 14 {
return Err(Error::PacketContentTooShort(content.len()));
@@ -1187,6 +1187,14 @@ impl OutAudio {
#[cfg(test)]
mod tests {
#[test]
fn short_c2s_audio_with_invalid_codec_is_an_error() {
// Packet id + invalid codec byte, shorter than the old error path indexed.
for p_type in [PacketType::Voice, PacketType::VoiceWhisper] {
assert!(AudioData::parse(p_type, false, Direction::C2S, &[0, 1, 0xff]).is_err());
}
}
use super::*;
fn test_audio_roundtrip(dir: Direction, data: &AudioData) {
+1 -1
View File
@@ -20,7 +20,7 @@ include = [
[dependencies]
base64 = "0.22"
bitflags = { version = "2", features = ["serde"] }
curve25519-dalek-ng = "4"
curve25519-dalek = { version = "4", features = ["rand_core"] }
elliptic-curve = { version = "0.13", features = ["ecdh"] }
generic-array = "0.14"
num-bigint = "0.4"
+4 -4
View File
@@ -3,9 +3,9 @@ use std::convert::TryInto;
use std::{cmp, fmt, str};
use base64::prelude::*;
use curve25519_dalek_ng::constants;
use curve25519_dalek_ng::edwards::{CompressedEdwardsY, EdwardsPoint};
use curve25519_dalek_ng::scalar::Scalar;
use curve25519_dalek::constants;
use curve25519_dalek::edwards::{CompressedEdwardsY, EdwardsPoint};
use curve25519_dalek::scalar::Scalar;
use elliptic_curve::sec1::{FromEncodedPoint, ToEncodedPoint};
use generic_array::GenericArray;
use generic_array::typenum::Unsigned;
@@ -522,7 +522,7 @@ impl EccKeyPrivEd25519 {
impl<'a> From<&'a EccKeyPrivEd25519> for EccKeyPubEd25519 {
fn from(priv_key: &'a EccKeyPrivEd25519) -> Self {
Self((&constants::ED25519_BASEPOINT_TABLE * &priv_key.0).compress())
Self((constants::ED25519_BASEPOINT_TABLE * &priv_key.0).compress())
}
}
+1 -1
View File
@@ -21,7 +21,7 @@ include = [
aes = "0.8"
base64 = "0.22"
omnom = "3"
curve25519-dalek-ng = "4"
curve25519-dalek = { version = "4", features = ["rand_core"] }
eax = "0.5"
futures = "0.3"
generic-array = "0.14"
@@ -1,7 +1,7 @@
use base64::prelude::*;
use clap::Parser;
use curve25519_dalek_ng::edwards::CompressedEdwardsY;
use curve25519_dalek_ng::scalar::Scalar;
use curve25519_dalek::edwards::CompressedEdwardsY;
use curve25519_dalek::scalar::Scalar;
#[derive(Parser, Debug)]
#[command(author, about)]
+1 -1
View File
@@ -1,5 +1,5 @@
//! Handle packet splitting and cryptography
use curve25519_dalek_ng::edwards::EdwardsPoint;
use curve25519_dalek::edwards::EdwardsPoint;
use eax::aead::consts::{U16, U8};
use eax::{AeadInPlace, Eax, KeyInit};
use generic_array::GenericArray;
+21 -13
View File
@@ -3,8 +3,8 @@ use std::fmt;
use std::io::Cursor;
use std::str;
use curve25519_dalek_ng::edwards::EdwardsPoint;
use curve25519_dalek_ng::scalar::Scalar;
use curve25519_dalek::edwards::EdwardsPoint;
use curve25519_dalek::scalar::Scalar;
use num_derive::{FromPrimitive, ToPrimitive};
use num_traits::{FromPrimitive as _, ToPrimitive as _};
use omnom::{ReadExt, WriteExt};
@@ -165,7 +165,9 @@ impl Licenses {
pub fn parse(data: Vec<u8>) -> Result<Self> { Self::parse_internal(data, true) }
pub fn parse_internal(data: Vec<u8>, check_expired: bool) -> Result<Self> {
let version = data[0];
let Some(&version) = data.first() else {
return Err(Error::TooShort(0, "empty license"));
};
if version != 0 && version != 1 {
return Err(Error::UnsupportedVersion(version));
}
@@ -510,17 +512,20 @@ impl License {
) -> Result<impl Iterator<Item = Result<LicenseProperty<'a>>> + 'b> {
if let InnerLicense::Ts5Server { properties } = &self.inner {
Ok(properties.iter().map(move |p| {
// Every access is bounds-checked: the data comes from the server.
let get = |start: usize, end: usize| {
data.get(start..end).ok_or(Error::TooShort(data.len(), "license property"))
};
let o = BLOCK_MIN_LEN + 2 + p;
let len = data[o];
let header = get(o, o + 3)?;
let (len, id, typ) = (header[0], header[1], header[2]);
let len_usize = len as usize;
let id = data[o + 1];
let typ = data[o + 2];
// Check length
if let Some(expected) = match typ {
// String, check that it is null-terminated
0 => {
if data[o + len_usize] != 0 {
if get(o + len_usize, o + len_usize + 1)?[0] != 0 {
return Err(Error::NonterminatedString);
}
None
@@ -540,14 +545,14 @@ impl License {
return Err(Error::WrongPropertyType { id, expected: 1, actual: typ });
}
Ok(LicenseProperty::Unknown1(
(&data[o + 3..o + 3 + 4]).read_be().map_err(Error::Deserialize)?,
get(o + 3, o + 3 + 4)?.read_be().map_err(Error::Deserialize)?,
))
}
2 => {
if typ != 0 {
return Err(Error::WrongPropertyType { id, expected: 0, actual: typ });
}
let s = str::from_utf8(&data[o + 3..o + len_usize])
let s = str::from_utf8(get(o + 3, o + len_usize)?)
.map_err(Error::DeserializeString)?;
Ok(LicenseProperty::Issuer(s))
}
@@ -556,12 +561,10 @@ impl License {
return Err(Error::WrongPropertyType { id, expected: 1, actual: typ });
}
Ok(LicenseProperty::MaxClients(
(&data[o + 3..o + 3 + 4]).read_be().map_err(Error::Deserialize)?,
get(o + 3, o + 3 + 4)?.read_be().map_err(Error::Deserialize)?,
))
}
_ => {
Ok(LicenseProperty::Unknown { id, typ, data: &data[o + 3..o + len_usize] })
}
_ => Ok(LicenseProperty::Unknown { id, typ, data: get(o + 3, o + len_usize)? }),
}
}))
} else {
@@ -844,6 +847,11 @@ impl LicenseBlockBuilder<'_, '_> {
#[cfg(test)]
mod tests {
#[test]
fn empty_license_is_an_error() {
assert!(super::Licenses::parse(Vec::new()).is_err());
}
use super::*;
use base64::prelude::*;
+18
View File
@@ -0,0 +1,18 @@
[package]
name = "tsc-model"
version = "0.1.0"
description = "UI-facing domain model shared by the client engine, gateway and UI (no IO)."
edition.workspace = true
rust-version.workspace = true
license.workspace = true
repository.workspace = true
publish.workspace = true
[dependencies]
serde = { version = "1", features = ["derive"] }
[dev-dependencies]
serde_json = "1"
[lints]
workspace = true
+8
View File
@@ -0,0 +1,8 @@
//! Domain model shared by the client engine, the gateway and the UI.
//!
//! Nothing in here does IO; the types describe what a server offers and what
//! the user sees.
mod server;
pub use server::{Capabilities, ServerFlavor, ServerVersion};
+138
View File
@@ -0,0 +1,138 @@
//! Server software detection and the capabilities that follow from it.
use std::fmt;
use serde::{Deserialize, Serialize};
/// Parsed `virtualserver_version`, e.g. `3.13.8 [Build: 1779874471]` or
/// `6.0.0-beta13.1 [Build: 1790080330]`.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct ServerVersion {
pub major: u32,
pub minor: u32,
pub patch: u32,
/// Pre-release tag such as `beta13.1`.
pub pre: Option<String>,
/// Build timestamp (seconds since the Unix epoch).
pub build: Option<u64>,
}
impl ServerVersion {
pub fn parse(s: &str) -> Option<Self> {
let s = s.trim();
let (version, rest) = s.split_once(' ').unwrap_or((s, ""));
let build = rest
.trim()
.strip_prefix("[Build:")
.and_then(|b| b.strip_suffix(']'))
.and_then(|b| b.trim().parse().ok());
let (numbers, pre) = match version.split_once('-') {
Some((n, p)) => (n, Some(p.to_string())),
None => (version, None),
};
let mut parts = numbers.split('.').map(|p| p.parse::<u32>());
let major = parts.next()?.ok()?;
let minor = parts.next().unwrap_or(Ok(0)).ok()?;
let patch = parts.next().unwrap_or(Ok(0)).ok()?;
Some(Self { major, minor, patch, pre, build })
}
}
impl fmt::Display for ServerVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}.{}.{}", self.major, self.minor, self.patch)?;
if let Some(pre) = &self.pre {
write!(f, "-{pre}")?;
}
Ok(())
}
}
/// Which server software we are talking to.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ServerFlavor {
/// TeamSpeak 3 server (3.x).
Ts3(ServerVersion),
/// TeamSpeak 6 server (6.x; TeamSpeak 5 server betas are treated alike).
Ts6(ServerVersion),
/// Unparseable or unexpected version string.
Unknown(String),
}
impl ServerFlavor {
/// Classify a `virtualserver_version` string.
pub fn from_version_string(s: &str) -> Self {
match ServerVersion::parse(s) {
Some(v) if v.major == 3 => ServerFlavor::Ts3(v),
Some(v) if v.major >= 5 => ServerFlavor::Ts6(v),
_ => ServerFlavor::Unknown(s.to_string()),
}
}
pub fn version(&self) -> Option<&ServerVersion> {
match self {
ServerFlavor::Ts3(v) | ServerFlavor::Ts6(v) => Some(v),
ServerFlavor::Unknown(_) => None,
}
}
pub fn capabilities(&self) -> Capabilities {
match self {
ServerFlavor::Ts3(_) => {
Capabilities { streams: false, raw_query: true, ssh_query: true, http_query: false }
}
ServerFlavor::Ts6(_) => {
Capabilities { streams: true, raw_query: false, ssh_query: true, http_query: true }
}
ServerFlavor::Unknown(_) => Capabilities::default(),
}
}
}
/// Features that depend on the server software.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Capabilities {
/// Screen sharing / video streams (TeamSpeak 6).
pub streams: bool,
/// Raw TCP ServerQuery (TeamSpeak 3 only; may still be disabled by the admin).
pub raw_query: bool,
/// SSH ServerQuery.
pub ssh_query: bool,
/// HTTP WebQuery (TeamSpeak 6), request/response only, no events.
pub http_query: bool,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parses_ts3() {
let v = ServerVersion::parse("3.13.8 [Build: 1779874471]").unwrap();
assert_eq!((v.major, v.minor, v.patch), (3, 13, 8));
assert_eq!(v.pre, None);
assert_eq!(v.build, Some(1_779_874_471));
let flavor = ServerFlavor::from_version_string("3.13.8 [Build: 1779874471]");
assert!(matches!(flavor, ServerFlavor::Ts3(_)));
assert!(!flavor.capabilities().streams);
}
#[test]
fn parses_ts6_beta() {
let s = "6.0.0-beta13.1 [Build: 1790080330]";
let v = ServerVersion::parse(s).unwrap();
assert_eq!(v.pre.as_deref(), Some("beta13.1"));
assert_eq!(v.to_string(), "6.0.0-beta13.1");
let flavor = ServerFlavor::from_version_string(s);
assert!(matches!(flavor, ServerFlavor::Ts6(_)));
assert!(flavor.capabilities().streams);
assert!(!flavor.capabilities().raw_query);
}
#[test]
fn handles_garbage() {
assert!(matches!(ServerFlavor::from_version_string(""), ServerFlavor::Unknown(_)));
assert!(matches!(ServerFlavor::from_version_string("x.y"), ServerFlavor::Unknown(_)));
assert_eq!(ServerVersion::parse("3").unwrap().minor, 0);
}
}