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:
1 parent
369cbde85d
commit
aa19afbcd0
24 files changed
+1835
-57
No files matched your search
@@ -29,9 +29,9 @@ jobs:
|
||||
# and have known clippy findings (cleanup is milestone M1), so the strict
|
||||
# checks cover our own crates only.
|
||||
- name: rustfmt (own crates)
|
||||
run: cargo fmt -p tsctl --check
|
||||
run: cargo fmt $(scripts/own-crates.sh) --check
|
||||
- name: clippy (own crates, deny warnings)
|
||||
run: cargo clippy -p tsctl --all-targets --no-deps -- -D warnings
|
||||
run: cargo clippy $(scripts/own-crates.sh) --all-targets --no-deps -- -D warnings
|
||||
- name: clippy (workspace, report only)
|
||||
run: cargo clippy --workspace --all-targets
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
name: Fuzz
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "17 3 * * *"
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
fuzz:
|
||||
name: fuzz ${{ matrix.target }}
|
||||
runs-on: ubuntu-24.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
target: [packet, command, license]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install nightly and cargo-fuzz
|
||||
run: |
|
||||
rustup toolchain install nightly --profile minimal
|
||||
cargo install cargo-fuzz --locked
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
with:
|
||||
workspaces: fuzz
|
||||
- name: Fuzz for 10 minutes
|
||||
working-directory: fuzz
|
||||
run: cargo +nightly fuzz run ${{ matrix.target }} -- -max_total_time=600
|
||||
- name: Upload crash artifacts
|
||||
if: failure()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: fuzz-${{ matrix.target }}-artifacts
|
||||
path: fuzz/artifacts/
|
||||
Generated
+44
-30
@@ -378,7 +378,7 @@ checksum = "8543454e3c3f5126effff9cd44d562af4e31fb8ce1cc0d3dcd8f084515dbc1aa"
|
||||
dependencies = [
|
||||
"cipher",
|
||||
"dbl",
|
||||
"digest 0.10.7",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -652,18 +652,32 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "curve25519-dalek-ng"
|
||||
version = "4.1.1"
|
||||
name = "curve25519-dalek"
|
||||
version = "4.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1c359b7249347e46fb28804470d071c921156ad62b3eef5d34e2ba867533dec8"
|
||||
checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"digest 0.9.0",
|
||||
"cfg-if",
|
||||
"cpufeatures 0.2.17",
|
||||
"curve25519-dalek-derive",
|
||||
"fiat-crypto",
|
||||
"rand_core 0.6.4",
|
||||
"subtle-ng",
|
||||
"rustc_version",
|
||||
"subtle",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "curve25519-dalek-derive"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dasp_sample"
|
||||
version = "0.11.0"
|
||||
@@ -705,15 +719,6 @@ dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.7"
|
||||
@@ -794,7 +799,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca"
|
||||
dependencies = [
|
||||
"der",
|
||||
"digest 0.10.7",
|
||||
"digest",
|
||||
"elliptic-curve",
|
||||
"rfc6979",
|
||||
"signature",
|
||||
@@ -815,7 +820,7 @@ checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47"
|
||||
dependencies = [
|
||||
"base16ct",
|
||||
"crypto-bigint 0.5.5",
|
||||
"digest 0.10.7",
|
||||
"digest",
|
||||
"ff",
|
||||
"generic-array",
|
||||
"group",
|
||||
@@ -888,6 +893,12 @@ dependencies = [
|
||||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fiat-crypto"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d"
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.14"
|
||||
@@ -1211,7 +1222,7 @@ version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
|
||||
dependencies = [
|
||||
"digest 0.10.7",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2704,7 +2715,7 @@ checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures 0.2.17",
|
||||
"digest 0.10.7",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2715,7 +2726,7 @@ checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures 0.2.17",
|
||||
"digest 0.10.7",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2749,7 +2760,7 @@ version = "2.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de"
|
||||
dependencies = [
|
||||
"digest 0.10.7",
|
||||
"digest",
|
||||
"rand_core 0.6.4",
|
||||
]
|
||||
|
||||
@@ -2831,12 +2842,6 @@ version = "2.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
||||
|
||||
[[package]]
|
||||
name = "subtle-ng"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "734676eb262c623cec13c3155096e08d1f8f29adce39ba17948b18dad1e54142"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.119"
|
||||
@@ -3270,6 +3275,14 @@ dependencies = [
|
||||
"tsproto-types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tsc-model"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tsclientlib"
|
||||
version = "0.2.0"
|
||||
@@ -3317,6 +3330,7 @@ dependencies = [
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
"tsc-model",
|
||||
"tsclientlib",
|
||||
"tsproto-packets",
|
||||
]
|
||||
@@ -3331,7 +3345,7 @@ dependencies = [
|
||||
"clap",
|
||||
"criterion",
|
||||
"crypto-bigint 0.6.1",
|
||||
"curve25519-dalek-ng",
|
||||
"curve25519-dalek",
|
||||
"eax",
|
||||
"futures",
|
||||
"generic-array",
|
||||
@@ -3389,7 +3403,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"bitflags",
|
||||
"curve25519-dalek-ng",
|
||||
"curve25519-dalek",
|
||||
"elliptic-curve",
|
||||
"generic-array",
|
||||
"heck",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
[workspace]
|
||||
resolver = "3"
|
||||
exclude = ["fuzz"]
|
||||
members = [
|
||||
"crates/proto/tsproto-types",
|
||||
"crates/proto/tsproto-structs",
|
||||
@@ -7,6 +8,7 @@ members = [
|
||||
"crates/proto/tsproto",
|
||||
"crates/proto/ts-bookkeeping",
|
||||
"crates/proto/tsclientlib",
|
||||
"crates/tsc-model",
|
||||
"tools/tsctl",
|
||||
]
|
||||
default-members = [
|
||||
@@ -16,6 +18,7 @@ default-members = [
|
||||
"crates/proto/tsproto",
|
||||
"crates/proto/ts-bookkeeping",
|
||||
"crates/proto/tsclientlib",
|
||||
"crates/tsc-model",
|
||||
"tools/tsctl",
|
||||
]
|
||||
|
||||
|
||||
@@ -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]`.
|
||||
@@ -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) {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,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;
|
||||
|
||||
@@ -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::*;
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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};
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
target/
|
||||
corpus/
|
||||
artifacts/
|
||||
coverage/
|
||||
Generated
+1431
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,38 @@
|
||||
[package]
|
||||
name = "tsc-fuzz"
|
||||
version = "0.0.0"
|
||||
publish = false
|
||||
edition = "2024"
|
||||
|
||||
[package.metadata]
|
||||
cargo-fuzz = true
|
||||
|
||||
[dependencies]
|
||||
libfuzzer-sys = "0.4"
|
||||
ts-bookkeeping = { path = "../crates/proto/ts-bookkeeping" }
|
||||
tsproto = { path = "../crates/proto/tsproto" }
|
||||
tsproto-packets = { path = "../crates/proto/tsproto-packets" }
|
||||
|
||||
# Not part of the main workspace: cargo-fuzz needs a nightly toolchain.
|
||||
[workspace]
|
||||
|
||||
[[bin]]
|
||||
name = "packet"
|
||||
path = "fuzz_targets/packet.rs"
|
||||
test = false
|
||||
doc = false
|
||||
bench = false
|
||||
|
||||
[[bin]]
|
||||
name = "command"
|
||||
path = "fuzz_targets/command.rs"
|
||||
test = false
|
||||
doc = false
|
||||
bench = false
|
||||
|
||||
[[bin]]
|
||||
name = "license"
|
||||
path = "fuzz_targets/license.rs"
|
||||
test = false
|
||||
doc = false
|
||||
bench = false
|
||||
@@ -0,0 +1,24 @@
|
||||
//! Decrypted command payloads, parsed into typed messages.
|
||||
#![no_main]
|
||||
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use ts_bookkeeping::messages::s2c::InMessage;
|
||||
use tsproto_packets::commands::CommandParser;
|
||||
use tsproto_packets::packets::{Direction, InPacket};
|
||||
|
||||
/// S2C header: 8 byte MAC, packet id 1, type Command with the NewProtocol flag.
|
||||
const HEADER: [u8; 11] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0x22];
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let (_, args) = CommandParser::new(data);
|
||||
for arg in args {
|
||||
let _ = format!("{arg:?}");
|
||||
}
|
||||
|
||||
let mut packet = HEADER.to_vec();
|
||||
packet.extend_from_slice(data);
|
||||
let packet = InPacket::new(Direction::S2C, &packet);
|
||||
if let Ok(msg) = InMessage::new(&packet.header(), data) {
|
||||
let _ = format!("{msg:?}");
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
//! The license chain sent in `initivexpand2 l=...` during the handshake.
|
||||
#![no_main]
|
||||
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use tsproto::license::Licenses;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
if let Ok(licenses) = Licenses::parse_ignore_expired(data.to_vec()) {
|
||||
let _ = format!("{licenses:?}");
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
//! Raw UDP packets from the server.
|
||||
#![no_main]
|
||||
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use tsproto_packets::packets::{Direction, InPacket};
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
for dir in [Direction::S2C, Direction::C2S] {
|
||||
if let Ok(packet) = InPacket::try_new(dir, data) {
|
||||
let _ = format!("{packet:?}");
|
||||
let _ = packet.header().packet_type();
|
||||
let _ = packet.ack_packet();
|
||||
}
|
||||
}
|
||||
});
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
# Print `-p <crate>` for every workspace crate outside the vendored crates/proto,
|
||||
# for commands that apply strict checks to our own code only:
|
||||
# cargo clippy $(scripts/own-crates.sh) --all-targets --no-deps -- -D warnings
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
cargo metadata --no-deps --format-version 1 |
|
||||
jq -r '.packages[] | select(.manifest_path | contains("/crates/proto/") | not) | "-p \(.name)"' |
|
||||
tr '\n' ' '
|
||||
@@ -20,6 +20,7 @@ tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
tsclientlib = { path = "../../crates/proto/tsclientlib" }
|
||||
tsproto-packets = { path = "../../crates/proto/tsproto-packets" }
|
||||
tsc-model = { path = "../../crates/tsc-model" }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -4,6 +4,7 @@ use std::collections::HashMap;
|
||||
use std::fmt::Write;
|
||||
|
||||
use tsclientlib::data;
|
||||
use tsc_model::ServerFlavor;
|
||||
use tsclientlib::{ChannelId, ClientType};
|
||||
|
||||
/// Minimal channel view, so the ordering logic can be tested without a connection.
|
||||
@@ -114,7 +115,12 @@ pub fn from_state(state: &data::Connection) -> String {
|
||||
streaming: c.is_streaming == Some(true),
|
||||
})
|
||||
.collect();
|
||||
render(&state.server.name, &channels, &clients)
|
||||
let flavor = match ServerFlavor::from_version_string(&state.server.version) {
|
||||
ServerFlavor::Ts3(v) => format!("TeamSpeak 3 {v}"),
|
||||
ServerFlavor::Ts6(v) => format!("TeamSpeak 6 {v}"),
|
||||
ServerFlavor::Unknown(v) => format!("unknown version {v:?}"),
|
||||
};
|
||||
render(&format!("{} ({flavor})", state.server.name), &channels, &clients)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in new issue
Block a user