Merge branch 'codex/myteamspeak-account': myTeamSpeak account sign-in

Conflicts with the channel banners on main, both kept:
- crates/proto/UPSTREAM.md: myTeamSpeak's local patch is number 14, after
  the channel banners' 13.
- voelin-core/src/voice.rs: both test modules.
- ui/app.slint: the mobile shell hides behind the account prompt and keeps
  the channel chat's banner.
- ui/shells/common.slint: the user card counts a signed-in account as named
  and shows our avatar, the person icon only without one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FEpqsPES27Eacue91u3d2Q
This commit is contained in:
Claude committed 2026-10-04 17:55:31 +00:00
commit 64fa161cd6
185 files changed
+52751 -217

No files matched your search

+12
View File
@@ -117,3 +117,15 @@ against or offered back to upstream.
cannot drop the whole channel list; its numbers are those of
`HostBannerMode` (the server's `channeledit` documentation: 0 as it is,
1 stretched, 2 scaled keeping the aspect ratio).
14. **myTeamSpeak connection identity** (`tsproto/src/myts.rs`,
`tsclientlib/src/myts.rs`, `tsclientlib/src/lib.rs`). Validated, redacted account
credentials retain the original raw signing scalar and validate again when
deserialized from a credential store. Connection-bound account proofs use the
negotiated shared IV and the official raw-scalar signing construction, not
Ed25519 seed expansion. `clientinit` and `updatemytsid` carry the six official
case-sensitive proof fields; clearing an account sends only an empty
`myTeamspeakId`. Connection options retain the latest account for reconnects;
callers cancel and rebuild an in-flight attempt when its snapshot changes.
Tests cover an independent signature vector, persistence validation/redaction,
wire field names, clearing and reconnect snapshot replacement. The account
UUID and the ordinary server identity remain separate.
+21 -2
View File
@@ -44,6 +44,7 @@ use tsproto_packets::packets::{InCommandBuf, OutCommand, OutPacket, PacketType};
#[cfg(feature = "audio")]
pub mod audio;
mod myts;
pub mod prelude;
pub mod resolver;
pub mod sync;
@@ -382,9 +383,11 @@ impl Connection {
address: address.into(),
local_address: None,
identity: None,
myts_identity: None,
server: None,
name: "TeamSpeakUser".into(),
version: Version::Windows_3_X_X__1,
metadata: Cow::Borrowed(""),
hardware_id: "923f136fb1e22ae6ce95e60255529c00,d13231b1bc33edfecfb9169cc7a63bcc".into(),
channel: None,
channel_password: None,
@@ -536,7 +539,7 @@ impl Connection {
.as_ref()
.map(|p| tsproto_types::crypto::encode_password(p.as_bytes()))
.unwrap_or_default();
let packet = c2s::OutClientInitMessage::new(&mut iter::once(c2s::OutClientInitPart {
let mut packet = c2s::OutClientInitMessage::new(&mut iter::once(c2s::OutClientInitPart {
name: Cow::Borrowed(options.name.as_ref()),
version: Cow::Borrowed(client_version),
platform: Cow::Borrowed(client_platform),
@@ -549,7 +552,7 @@ impl Connection {
default_channel: Cow::Borrowed(options.channel.as_deref().unwrap_or_default()),
default_channel_password: Cow::Borrowed(default_channel_password.as_ref()),
password: Cow::Borrowed(password.as_ref()),
metadata: "".into(),
metadata: Cow::Borrowed(options.metadata.as_ref()),
version_sign: Cow::Borrowed(client_version_sign.as_ref()),
client_key_offset: counter,
phonetic_name: "".into(),
@@ -564,6 +567,13 @@ impl Connection {
security_hash: None,
}));
// Voelin patch: account proof is bound to this transport's negotiated IV.
// The generated legacy client_myteamspeak_id field stays absent.
if let Some(identity) = &options.myts_identity {
let params = client.params.as_ref().ok_or(Error::InitserverParamsMissing)?;
identity.proof(&params.shared_iv).write_to(&mut packet);
}
client.send_packet(packet.into_packet()).map_err(Error::SendClientinit)?;
match tokio::time::timeout(
@@ -1711,9 +1721,11 @@ pub struct ConnectOptions {
address: ServerAddress,
local_address: Option<SocketAddr>,
identity: Option<Identity>,
myts_identity: Option<tsproto::myts::Identity>,
server: Option<UidBuf>,
name: Cow<'static, str>,
version: Version,
metadata: Cow<'static, str>,
hardware_id: Cow<'static, str>,
channel: Option<Cow<'static, str>>,
channel_password: Option<Cow<'static, str>>,
@@ -1853,6 +1865,13 @@ impl ConnectOptions {
self
}
/// Application metadata, independently of the signed compatibility version.
/// Voelin patch: carries the actual application name/build to the server.
pub fn metadata<S: Into<Cow<'static, str>>>(mut self, metadata: S) -> Self {
self.metadata = metadata.into();
self
}
/// The hardware ID (HWID) of the client.
///
/// # Default
+91
View File
@@ -0,0 +1,91 @@
//! Voelin patch: connection-bound myTeamSpeak proof and live account changes.
use tsproto::myts::Identity;
use tsproto_packets::packets::{Direction, Flags, OutCommand, PacketType};
use crate::{ConnectOptions, Connection, ConnectionState, Error, MessageHandle, Result};
impl ConnectOptions {
/// Snapshot the account credential for the initial connection and reconnects.
/// This is separate from the server identity and account profile UUID.
pub fn myts_identity(mut self, identity: Option<Identity>) -> Self {
self.myts_identity = identity;
self
}
}
impl Connection {
/// Publish a connection-bound account proof, or clear the account identity.
///
/// Always updates the reconnect options, even if currently disconnected or
/// sending fails. A running connection attempt owns its previous snapshot:
/// callers must cancel and rebuild that attempt after `NotConnected`.
/// Await the returned handle's `StreamItem::MessageResult` for server acceptance.
pub fn update_myts_identity(&mut self, identity: Option<Identity>) -> Result<MessageHandle> {
self.options.myts_identity = identity;
let iv = match &self.state {
ConnectionState::Connected { con, .. } => {
con.client.params.as_ref().ok_or(Error::InitserverParamsMissing)?.shared_iv
}
_ => return Err(Error::NotConnected),
};
let packet = update_packet(self.options.myts_identity.as_ref(), &iv);
self.send_command_with_result(packet)
}
}
fn update_packet(identity: Option<&Identity>, iv: &[u8; 64]) -> OutCommand {
let mut packet =
OutCommand::new(Direction::C2S, Flags::empty(), PacketType::Command, "updatemytsid");
if let Some(identity) = identity {
identity.proof(iv).write_to(&mut packet);
} else {
// Empty arguments are serialized without '=' by the existing writer.
packet.write_arg("myTeamspeakId", &"");
}
packet
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn clear_contains_no_previous_account_proof() {
let packet = update_packet(None, &[0; 64]).into_packet();
assert_eq!(packet.content(), b"updatemytsid myTeamspeakId");
}
#[test]
fn update_uses_current_connection_challenge() {
// Scalar one and the standard compressed Edwards base point.
let mut private = [0; 32];
private[0] = 1;
let mut public = [0x66; 32];
public[0] = 0x58;
let identity = Identity::new(vec![1; 33], 42, public, private, vec![2; 65]).unwrap();
let first = update_packet(Some(&identity), &[0; 64]).into_packet();
let second = update_packet(Some(&identity), &[1; 64]).into_packet();
assert_ne!(first.content(), second.content());
let wire = std::str::from_utf8(first.content()).unwrap();
assert!(wire.starts_with("updatemytsid myTeamspeakId="));
assert!(wire.contains(" acTime=42 "));
assert!(!wire.contains("client_myteamspeak_id"));
assert_eq!(wire.split(' ').count(), 7);
}
#[test]
fn failed_update_still_replaces_reconnect_snapshot() {
// Building opens no socket until the connection future is polled.
let mut private = [0; 32];
private[0] = 1;
let mut public = [0x66; 32];
public[0] = 0x58;
let identity = Identity::new(vec![1; 33], 42, public, private, vec![2; 65]).unwrap();
let mut connection =
Connection::build("localhost").myts_identity(Some(identity)).connect().unwrap();
assert!(connection.options.myts_identity.is_some());
assert!(matches!(connection.update_myts_identity(None), Err(Error::NotConnected)));
assert!(connection.options.myts_identity.is_none());
}
}
+2
View File
@@ -43,8 +43,10 @@ tsproto-packets = { path = "../tsproto-packets", version = "0.1" }
tsproto-types = { path = "../tsproto-types", version = "0.1" }
quicklz = "0.3"
crypto-bigint = "0.6"
zeroize = "1"
[dev-dependencies]
serde_json = "1"
anyhow = "1"
criterion = "0.8"
once_cell = "1"
+1
View File
@@ -26,6 +26,7 @@ pub mod client;
pub mod connection;
pub mod license;
pub mod log;
pub mod myts;
pub mod packet_codec;
pub mod resend;
pub mod utils;
+247
View File
@@ -0,0 +1,247 @@
//! Validated myTeamSpeak signing credentials and connection-bound public proofs.
//!
//! Serializing an [`Identity`] exports its private key. Persist it only in a
//! credential store, never application settings, diagnostics or packet logs.
use std::fmt;
use base64::prelude::*;
use curve25519_dalek::{constants::ED25519_BASEPOINT_TABLE, scalar::Scalar};
use serde::{Deserialize, Deserializer, Serialize};
use sha2::{Digest, Sha256, Sha512};
use thiserror::Error;
use tsproto_packets::packets::OutCommand;
use zeroize::Zeroize;
/// An account identity; distinct from the account UUID and server identity.
#[derive(Clone, Serialize)]
pub struct Identity {
myts_id: Vec<u8>,
creation_time: u64,
public_key: [u8; 32],
private_key: [u8; 32],
public_signature: Vec<u8>,
}
#[derive(Debug, Error)]
pub enum IdentityError {
#[error("myTeamSpeak identity must contain 33 bytes")]
InvalidId,
#[error("myTeamSpeak public signature must contain 65 to 4096 bytes")]
InvalidSignature,
#[error("myTeamSpeak private key is zero or does not match its public key")]
InvalidKeyPair,
}
impl fmt::Debug for Identity {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("Identity([REDACTED])") }
}
impl Drop for Identity {
fn drop(&mut self) { self.private_key.zeroize(); }
}
impl<'de> Deserialize<'de> for Identity {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
struct Stored {
myts_id: Vec<u8>,
creation_time: u64,
public_key: [u8; 32],
private_key: [u8; 32],
public_signature: Vec<u8>,
}
let mut stored = Stored::deserialize(deserializer)?;
let result = Self::new(
stored.myts_id,
stored.creation_time,
stored.public_key,
stored.private_key,
stored.public_signature,
);
stored.private_key.zeroize();
result.map_err(serde::de::Error::custom)
}
}
impl Identity {
/// `creation_time` is the voice protocol's decimal `acTime` integer,
/// byte-swapped from the account service's numeric creation timestamp.
pub fn new(
myts_id: Vec<u8>, creation_time: u64, public_key: [u8; 32], mut private_key: [u8; 32],
public_signature: Vec<u8>,
) -> Result<Self, IdentityError> {
let result = (|| {
if myts_id.len() != 33 {
return Err(IdentityError::InvalidId);
}
if !(65..=4096).contains(&public_signature.len()) {
return Err(IdentityError::InvalidSignature);
}
let mut scalar = Scalar::from_bytes_mod_order(private_key);
let valid = scalar != Scalar::ZERO
&& (ED25519_BASEPOINT_TABLE * &scalar).compress().to_bytes() == public_key;
scalar.zeroize();
if !valid {
return Err(IdentityError::InvalidKeyPair);
}
Ok(Self { myts_id, creation_time, public_key, private_key, public_signature })
})();
private_key.zeroize();
result
}
pub fn id(&self) -> String { BASE64_STANDARD.encode(&self.myts_id) }
/// Sign this connection's challenge with the original raw private scalar.
/// This is not Ed25519's seed expansion: the account already stores a scalar.
pub fn proof(&self, shared_iv: &[u8; 64]) -> Proof {
let mut challenge = Sha256::new();
challenge.update([0x30, 0x08, 0, 0, 0, 0]);
challenge.update(shared_iv);
let mut message = challenge.finalize().to_vec();
message.extend_from_slice(b"MyTeamSpeakID");
let mut nonce_hash = Sha512::new();
nonce_hash.update(self.private_key);
nonce_hash.update(&message);
let mut nonce = Scalar::from_bytes_mod_order_wide(&nonce_hash.finalize().into());
let public_nonce = (ED25519_BASEPOINT_TABLE * &nonce).compress().to_bytes();
let mut hash = Sha512::new();
hash.update(public_nonce);
hash.update(self.public_key);
hash.update(&message);
let challenge = Scalar::from_bytes_mod_order_wide(&hash.finalize().into());
let mut scalar = Scalar::from_bytes_mod_order(self.private_key);
let mut response = challenge * scalar + nonce;
let mut signature = [0; 64];
signature[..32].copy_from_slice(&public_nonce);
signature[32..].copy_from_slice(response.as_bytes());
scalar.zeroize();
nonce.zeroize();
response.zeroize();
Proof {
myteamspeak_id: self.id(),
creation_time: self.creation_time,
public_key: BASE64_STANDARD.encode(self.public_key),
auth_signature: BASE64_STANDARD.encode(signature),
public_signature: BASE64_STANDARD.encode(&self.public_signature[..64]),
public_signature_certificate: BASE64_STANDARD.encode(&self.public_signature[64..]),
}
}
}
/// Public, connection-bound authentication values. Never contains private keys.
#[derive(Clone)]
pub struct Proof {
pub myteamspeak_id: String,
pub creation_time: u64,
pub public_key: String,
pub auth_signature: String,
pub public_signature: String,
pub public_signature_certificate: String,
}
impl fmt::Debug for Proof {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("Proof([REDACTED])") }
}
impl Proof {
/// Append the official case-sensitive wire fields to an outgoing command.
pub fn write_to(&self, packet: &mut OutCommand) {
packet.write_arg("myTeamspeakId", &self.myteamspeak_id);
packet.write_arg("acTime", &self.creation_time);
packet.write_arg("userPubKey", &self.public_key);
packet.write_arg("authSign", &self.auth_signature);
packet.write_arg("pubSign", &self.public_signature);
packet.write_arg("pubSignCert", &self.public_signature_certificate);
}
}
#[cfg(test)]
mod tests {
use super::*;
use tsproto_packets::packets::{Direction, Flags, PacketType};
fn hex<const N: usize>(value: &str) -> [u8; N] {
let mut bytes = [0; N];
for (i, byte) in bytes.iter_mut().enumerate() {
*byte = u8::from_str_radix(&value[i * 2..i * 2 + 2], 16).unwrap();
}
bytes
}
fn identity() -> Identity {
Identity::new(
vec![7; 33],
123456,
hex("ce92350b547b6cf028df0618bf9aba55f949930059308d83ebd727e13472ed99"),
std::array::from_fn(|i| i as u8 + 1),
vec![9; 65],
)
.unwrap()
}
#[test]
fn raw_scalar_signature_matches_independent_vector() {
// Python integer Edwards arithmetic + hashlib, independent of dalek.
let proof = identity().proof(&std::array::from_fn(|i| i as u8));
let expected = hex::<64>(
"d56e1808e1ded53e20fc2849f016603c88eefe0494d75e9b869653e2bacaa495c562b571289d88a561c0f4b568cf90cc515b557b6d4321962e94ccf85f105a08",
);
assert_eq!(BASE64_STANDARD.decode(proof.auth_signature).unwrap(), expected);
assert_ne!(
identity().proof(&[0; 64]).auth_signature,
identity().proof(&[1; 64]).auth_signature
);
}
#[test]
fn credentials_roundtrip_validate_and_redact() {
let identity = identity();
let stored = serde_json::to_value(&identity).unwrap();
let restored: Identity = serde_json::from_value(stored.clone()).unwrap();
assert_eq!(serde_json::to_value(&restored).unwrap(), stored);
assert_eq!(
identity.proof(&[0; 64]).auth_signature,
restored.proof(&[0; 64]).auth_signature
);
assert_eq!(format!("{:?}", restored), "Identity([REDACTED])");
assert_eq!(format!("{:?}", restored.proof(&[0; 64])), "Proof([REDACTED])");
for field in ["myts_id", "public_signature", "public_key", "private_key"] {
let mut invalid = stored.clone();
invalid[field] = serde_json::json!([]);
assert!(serde_json::from_value::<Identity>(invalid).is_err(), "{}", field);
}
for private in [vec![0; 32], vec![1; 32]] {
let mut invalid = stored.clone();
invalid["private_key"] = serde_json::json!(private);
assert!(serde_json::from_value::<Identity>(invalid).is_err());
}
for length in [64, 4097] {
let mut invalid = stored.clone();
invalid["public_signature"] = serde_json::json!(vec![9; length]);
assert!(serde_json::from_value::<Identity>(invalid).is_err());
}
}
#[test]
fn proof_writes_exact_public_wire_fields() {
let mut command =
OutCommand::new(Direction::C2S, Flags::empty(), PacketType::Command, "clientinit");
identity().proof(&[0; 64]).write_to(&mut command);
let packet = command.into_packet();
let wire = std::str::from_utf8(packet.content()).unwrap();
let fields: Vec<_> =
wire.split(' ').skip(1).map(|field| field.split('=').next().unwrap()).collect();
assert_eq!(fields, [
"myTeamspeakId",
"acTime",
"userPubKey",
"authSign",
"pubSign",
"pubSignCert"
]);
assert!(!wire.contains("private"));
}
}