myTS avatar, badges and User Tag from a saved session; banners; gateway logs and speed
Own account on TeamSpeak 6 servers:
- With only a saved session, the account's avatar and its certificate come
from myTeamSpeak's avatar service (requestContactsAvatar for the own myTS
ID), the signed badges from getSignedBadges and the User Tag's token from
/tschat requestSignedAllowedIdentifierList; no password sign-in needed.
- tsproto::myts::Certificate checks a certificate chain as the server does
(block types 4-7, leaf type 6, validity, key from the root, cofactorless
Ed25519); each part is sent with a certificate that verifies it, in
separate updatemytsdata commands when they differ, and cleared on sign-out.
- client_user_tag is set as the official client sets it
({"myts_token","tag","updated"}) on TeamSpeak 6 servers, after a
self-check of the token; cleared on sign-out or an account change.
- Settings -> My Account shows the User Tag and lets the user choose up to
three badges to show. The log says what the server published.
Banners:
- The URL (without query) is logged on the first failure; stalls, connect
failures and missing answers are named; 400/404/410 are retried after
15 minutes, then hourly; 429/503 honour Retry-After.
- Cached pictures are revalidated (ETag, Last-Modified); at most 6
downloads per host; a User-Agent with the app version.
- The desktop portal's proxy (Linux) and the system proxy (Windows, macOS)
are used, SOCKS included; redirects are followed hop by hop.
Gateway, client side:
- Only a refused login stops observing; retries after 1, 2, 5, 10, 20, then
30 s with jitter, at once when voice connects; a 30 s keepalive.
- Discovery asks DNS and the well-known endpoints at once; observing is not
restarted when the found list still holds the gateway in use.
- Info logs for discovery, attempts (with the stage that hung), connections,
losses and the first presence.
tsgw:
- Logging setup (log.level, log.file with size rotation, colour only on a
terminal) and lifecycle logs: startup summary, the address the server
sees for queries, WebSocket connections, logins, refusals, slow requests,
ServerQuery failures, relays and the observer.
- The lookup query connection reconnects after a TeamSpeak restart; query
connects time out after 10 s; a silent server cannot wedge a connection;
SIGTERM, startup while TeamSpeak is down and /health are handled.
- TCP_QUICKACK and one write per line: ~45 ms -> <2 ms per SSH command.
- One flood guard shared by all query connections (9 per 3 s, SSH auth
counted, every connection holds on a 524).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VZBWxxMsxUzp4PSTKVzbZN
This commit is contained in:
1 parent
1c2d5efd3a
commit
79a12654c8
56 files changed
+7405
-672
No files matched your search
@@ -61,7 +61,7 @@ pub use ts_bookkeeping::messages::s2c::InMessage;
|
||||
pub use ts_bookkeeping::*;
|
||||
pub use tsproto::resend::{ConnectionStats, PacketStat};
|
||||
pub use tsproto::Identity;
|
||||
pub use myts::MytsData;
|
||||
pub use myts::{MytsData, MytsUpdate, Signed, UserTag};
|
||||
pub use tsproto_types::errors::Error as TsError;
|
||||
|
||||
/// Wait this time for initserver, in seconds.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Voelin patch: connection-bound myTeamSpeak proof and live account changes.
|
||||
|
||||
use base64::prelude::*;
|
||||
use tsproto::myts::Identity;
|
||||
use tsproto_packets::packets::{Direction, Flags, OutCommand, PacketType};
|
||||
|
||||
@@ -14,36 +15,182 @@ impl ConnectOptions {
|
||||
}
|
||||
}
|
||||
|
||||
/// What a voice server is shown of the myTeamSpeak account (TeamSpeak 6),
|
||||
/// as myTeamSpeak signed it: the account's certificate and its avatar
|
||||
/// (`LoginSession.user_avatar` as it came). The server shows the avatar to
|
||||
/// everyone (`client_myteamspeak_avatar`).
|
||||
/// What a voice server is shown of the myTeamSpeak account (TeamSpeak 6)
|
||||
/// besides its myTS ID, as myTeamSpeak signed it for that ID: its avatar,
|
||||
/// its badges and its User Tag. The server checks the avatar and the badges
|
||||
/// with the one certificate of each `updatemytsdata` and shows nothing of
|
||||
/// what does not verify, so each comes with the certificate that verifies
|
||||
/// it. Viewers check the User Tag's token themselves.
|
||||
#[derive(Clone, Default, PartialEq, Eq)]
|
||||
pub struct MytsData {
|
||||
/// The raw myTS ID all of it is signed for: shown only on a connection
|
||||
/// that presents it.
|
||||
pub myts_id: Vec<u8>,
|
||||
/// An `AvatarData` as it came (`client_myteamspeak_avatar`).
|
||||
pub avatar: Signed,
|
||||
/// A `UserBadgesSignedList`, the badges chosen to show, in order
|
||||
/// (`client_signed_badges`).
|
||||
pub badges: Signed,
|
||||
/// The ids of those badges, as in the list: the server publishes the
|
||||
/// ones that verify.
|
||||
pub badge_ids: Vec<String>,
|
||||
pub user_tag: Option<UserTag>,
|
||||
}
|
||||
|
||||
/// Something signed and the certificate that verifies it; empty: nothing.
|
||||
#[derive(Clone, Default, PartialEq, Eq)]
|
||||
pub struct Signed {
|
||||
pub certificate: Vec<u8>,
|
||||
/// Empty: none.
|
||||
pub avatar: Vec<u8>,
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
/// The User Tag (`client_user_tag`): the account's primary chat identifier
|
||||
/// and the token that proves it (a `MatrixIdentifierToken` as it came).
|
||||
#[derive(Clone, Default, PartialEq, Eq)]
|
||||
pub struct UserTag {
|
||||
pub tag: String,
|
||||
pub token: Vec<u8>,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for MytsData {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("MytsData")
|
||||
.field("certificate", &self.certificate.len())
|
||||
.field("avatar", &self.avatar.len())
|
||||
.field("avatar", &self.avatar.data.len())
|
||||
.field("badges", &self.badge_ids)
|
||||
.field("user_tag", &self.user_tag.as_ref().map(|t| &t.tag))
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl Signed {
|
||||
pub fn is_empty(&self) -> bool { self.data.is_empty() }
|
||||
}
|
||||
|
||||
impl UserTag {
|
||||
/// `client_user_tag` as the official client sets it: compact JSON with
|
||||
/// the token (standard base64), the tag and when it was set (`updated`,
|
||||
/// milliseconds since 1970), in this order.
|
||||
pub fn value(&self, updated_ms: i64) -> String {
|
||||
let mut tag = String::with_capacity(self.tag.len());
|
||||
for c in self.tag.chars() {
|
||||
match c {
|
||||
'"' => tag.push_str("\\\""),
|
||||
'\\' => tag.push_str("\\\\"),
|
||||
'\n' => tag.push_str("\\n"),
|
||||
'\r' => tag.push_str("\\r"),
|
||||
'\t' => tag.push_str("\\t"),
|
||||
'\u{8}' => tag.push_str("\\b"),
|
||||
'\u{c}' => tag.push_str("\\f"),
|
||||
c if u32::from(c) < 0x20 => tag.push_str(&format!("\\u{:04x}", u32::from(c))),
|
||||
c => tag.push(c),
|
||||
}
|
||||
}
|
||||
format!(
|
||||
"{{\"myts_token\":\"{}\",\"tag\":\"{}\",\"updated\":{}}}",
|
||||
BASE64_STANDARD.encode(&self.token),
|
||||
tag,
|
||||
updated_ms
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// One `updatemytsdata`: a value is shown (checked with `certificate`), an
|
||||
/// empty one clears what is shown, `None` leaves it as it is.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
pub struct MytsUpdate {
|
||||
pub certificate: Vec<u8>,
|
||||
pub badges: Option<Vec<u8>>,
|
||||
pub avatar: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
/// What to do about one part of what is shown.
|
||||
enum Part<'a> {
|
||||
Keep,
|
||||
Show(&'a Signed),
|
||||
Clear,
|
||||
}
|
||||
|
||||
fn part<'a>(wanted: &'a Signed, shown: &Signed, again: bool) -> Part<'a> {
|
||||
if wanted.is_empty() {
|
||||
if shown.is_empty() { Part::Keep } else { Part::Clear }
|
||||
} else if again || wanted != shown {
|
||||
Part::Show(wanted)
|
||||
} else {
|
||||
Part::Keep
|
||||
}
|
||||
}
|
||||
|
||||
impl MytsData {
|
||||
/// The `updatemytsdata` commands that make a server that shows `shown`
|
||||
/// show `self`. `again`: everything once more, after a new account proof
|
||||
/// (`updatemytsid`), which the server does not check them for again.
|
||||
/// The avatar and the badges go together when one certificate verifies
|
||||
/// both (certificate, badges, avatar, as the official client sends
|
||||
/// them), apart otherwise; clearing needs no certificate.
|
||||
pub fn updates(&self, shown: &MytsData, again: bool) -> Vec<MytsUpdate> {
|
||||
let avatar = part(&self.avatar, &shown.avatar, again);
|
||||
let badges = part(&self.badges, &shown.badges, again);
|
||||
let mut updates = Vec::new();
|
||||
match (&badges, &avatar) {
|
||||
(Part::Show(badges), Part::Show(avatar)) if badges.certificate == avatar.certificate => {
|
||||
updates.push(MytsUpdate {
|
||||
certificate: avatar.certificate.clone(),
|
||||
badges: Some(badges.data.clone()),
|
||||
avatar: Some(avatar.data.clone()),
|
||||
});
|
||||
}
|
||||
_ => {
|
||||
if let Part::Show(avatar) = avatar {
|
||||
updates.push(MytsUpdate {
|
||||
certificate: avatar.certificate.clone(),
|
||||
avatar: Some(avatar.data.clone()),
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
if let Part::Show(badges) = badges {
|
||||
updates.push(MytsUpdate {
|
||||
certificate: badges.certificate.clone(),
|
||||
badges: Some(badges.data.clone()),
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
let clear_badges = matches!(badges, Part::Clear);
|
||||
let clear_avatar = matches!(avatar, Part::Clear);
|
||||
if clear_badges || clear_avatar {
|
||||
updates.push(MytsUpdate {
|
||||
certificate: Vec::new(),
|
||||
badges: if clear_badges { Some(Vec::new()) } else { None },
|
||||
avatar: if clear_avatar { Some(Vec::new()) } else { None },
|
||||
});
|
||||
}
|
||||
updates
|
||||
}
|
||||
}
|
||||
|
||||
impl Connection {
|
||||
/// Show the server the account's certificate and avatar
|
||||
/// Show the server the account's avatar or badges, or clear them
|
||||
/// (`updatemytsdata`), as the official client does once connected and
|
||||
/// after a sign-in, after the account proof (`updatemytsid`).
|
||||
/// Await the returned handle's `StreamItem::MessageResult` for the answer.
|
||||
pub fn send_myts_data(&mut self, data: &MytsData) -> Result<MessageHandle> {
|
||||
/// after a sign-in, after the account proof (`updatemytsid`). The server
|
||||
/// answers before the result: the own client's
|
||||
/// `client_myteamspeak_avatar` and `client_signed_badges`, empty for what
|
||||
/// did not verify. Await the returned handle's
|
||||
/// `StreamItem::MessageResult` for the answer.
|
||||
pub fn send_myts_update(&mut self, update: &MytsUpdate) -> Result<MessageHandle> {
|
||||
if !matches!(self.state, ConnectionState::Connected { .. }) {
|
||||
return Err(Error::NotConnected);
|
||||
}
|
||||
self.send_command_with_result(data_packet(data))
|
||||
self.send_command_with_result(data_packet(update))
|
||||
}
|
||||
|
||||
/// Set the User Tag (`clientupdate client_user_tag`), as built by
|
||||
/// [`UserTag::value`]; empty clears it. TeamSpeak 6 servers only.
|
||||
pub fn send_user_tag(&mut self, value: &str) -> Result<MessageHandle> {
|
||||
if !matches!(self.state, ConnectionState::Connected { .. }) {
|
||||
return Err(Error::NotConnected);
|
||||
}
|
||||
self.send_command_with_result(user_tag_packet(value))
|
||||
}
|
||||
|
||||
/// Publish a connection-bound account proof, or clear the account identity.
|
||||
@@ -66,14 +213,25 @@ impl Connection {
|
||||
}
|
||||
|
||||
/// The values are the raw bytes with TeamSpeak's escaping only (no
|
||||
/// base64), as the official client sends them; an empty avatar is left out.
|
||||
fn data_packet(data: &MytsData) -> OutCommand {
|
||||
/// base64), as the official client sends them; an empty one is the bare
|
||||
/// name, which clears.
|
||||
fn data_packet(update: &MytsUpdate) -> OutCommand {
|
||||
let mut packet =
|
||||
OutCommand::new(Direction::C2S, Flags::empty(), PacketType::Command, "updatemytsdata");
|
||||
packet.write_bin_arg("myts_certificate", &data.certificate);
|
||||
if !data.avatar.is_empty() {
|
||||
packet.write_bin_arg("myts_avatar", &data.avatar);
|
||||
packet.write_bin_arg("myts_certificate", &update.certificate);
|
||||
if let Some(badges) = &update.badges {
|
||||
packet.write_bin_arg("myts_signed_badge", badges);
|
||||
}
|
||||
if let Some(avatar) = &update.avatar {
|
||||
packet.write_bin_arg("myts_avatar", avatar);
|
||||
}
|
||||
packet
|
||||
}
|
||||
|
||||
fn user_tag_packet(value: &str) -> OutCommand {
|
||||
let mut packet =
|
||||
OutCommand::new(Direction::C2S, Flags::empty(), PacketType::Command, "clientupdate");
|
||||
packet.write_arg("client_user_tag", &value);
|
||||
packet
|
||||
}
|
||||
|
||||
@@ -93,20 +251,97 @@ fn update_packet(identity: Option<&Identity>, iv: &[u8; 64]) -> OutCommand {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn signed(certificate: &[u8], data: &[u8]) -> Signed {
|
||||
Signed { certificate: certificate.to_vec(), data: data.to_vec() }
|
||||
}
|
||||
|
||||
fn wire(update: &MytsUpdate) -> Vec<u8> { data_packet(update).into_packet().content().to_vec() }
|
||||
|
||||
#[test]
|
||||
fn account_data_goes_raw_and_escaped() {
|
||||
let data = MytsData {
|
||||
let update = MytsUpdate {
|
||||
certificate: b"a b/c|d\\\x07\x08\x00\xff".to_vec(),
|
||||
avatar: vec![0x0a, 0x02, b'h', b'i'],
|
||||
badges: Some(vec![0x0a, 0x01, b' ']),
|
||||
avatar: Some(vec![0x0a, 0x02, b'h', b'i']),
|
||||
};
|
||||
let packet = data_packet(&data).into_packet();
|
||||
assert_eq!(
|
||||
wire(&update),
|
||||
b"updatemytsdata myts_certificate=a\\sb\\/c\\pd\\\\\\a\\b\x00\xff \
|
||||
myts_signed_badge=\\n\x01\\s myts_avatar=\\n\x02hi"
|
||||
);
|
||||
// Without badges: the certificate and the avatar.
|
||||
let update = MytsUpdate { badges: None, ..update };
|
||||
assert!(!wire(&update).windows(17).any(|w| w == b"myts_signed_badge"));
|
||||
// Clearing: bare names, no certificate needed.
|
||||
let clear = MytsUpdate {
|
||||
certificate: Vec::new(),
|
||||
badges: Some(Vec::new()),
|
||||
avatar: Some(Vec::new()),
|
||||
};
|
||||
assert_eq!(wire(&clear), b"updatemytsdata myts_certificate myts_signed_badge myts_avatar");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn what_one_certificate_verifies_goes_together() {
|
||||
let data = MytsData {
|
||||
myts_id: vec![1; 33],
|
||||
avatar: signed(b"C", b"avatar"),
|
||||
badges: signed(b"C", b"badges"),
|
||||
badge_ids: vec!["b1".into()],
|
||||
user_tag: None,
|
||||
};
|
||||
let none = MytsData::default();
|
||||
assert_eq!(data.updates(&none, false), [MytsUpdate {
|
||||
certificate: b"C".to_vec(),
|
||||
badges: Some(b"badges".to_vec()),
|
||||
avatar: Some(b"avatar".to_vec()),
|
||||
}]);
|
||||
assert_eq!(
|
||||
wire(&data.updates(&none, false)[0]),
|
||||
b"updatemytsdata myts_certificate=C myts_signed_badge=badges myts_avatar=avatar"
|
||||
);
|
||||
// Unchanged: nothing, unless after a new account proof.
|
||||
assert!(data.updates(&data, false).is_empty());
|
||||
assert_eq!(data.updates(&data, true).len(), 1);
|
||||
// Two certificates: two commands, each with its own.
|
||||
let apart = MytsData { badges: signed(b"D", b"badges"), ..data.clone() };
|
||||
let updates: Vec<_> = apart.updates(&none, false).iter().map(wire).collect();
|
||||
assert_eq!(updates, [
|
||||
b"updatemytsdata myts_certificate=C myts_avatar=avatar".to_vec(),
|
||||
b"updatemytsdata myts_certificate=D myts_signed_badge=badges".to_vec(),
|
||||
]);
|
||||
// Only what changed.
|
||||
let newer = MytsData { avatar: signed(b"C", b"newer"), ..data.clone() };
|
||||
let updates: Vec<_> = newer.updates(&data, false).iter().map(wire).collect();
|
||||
assert_eq!(updates, [b"updatemytsdata myts_certificate=C myts_avatar=newer".to_vec()]);
|
||||
// What is no longer there is cleared; what never was is left alone.
|
||||
let fewer = MytsData { badges: Signed::default(), ..data.clone() };
|
||||
let updates: Vec<_> = fewer.updates(&data, true).iter().map(wire).collect();
|
||||
assert_eq!(updates, [
|
||||
b"updatemytsdata myts_certificate=C myts_avatar=avatar".to_vec(),
|
||||
b"updatemytsdata myts_certificate myts_signed_badge".to_vec(),
|
||||
]);
|
||||
let updates: Vec<_> = none.updates(&data, true).iter().map(wire).collect();
|
||||
assert_eq!(updates, [b"updatemytsdata myts_certificate myts_signed_badge myts_avatar".to_vec()]);
|
||||
assert!(none.updates(&none, true).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_user_tag_is_set_as_the_official_client_sets_it() {
|
||||
let tag = UserTag { tag: "alex@myteamspeak.com".into(), token: vec![0xfb, 0xff, 0x01, 0x02] };
|
||||
assert_eq!(
|
||||
tag.value(1_759_740_000_123),
|
||||
r#"{"myts_token":"+/8BAg==","tag":"alex@myteamspeak.com","updated":1759740000123}"#
|
||||
);
|
||||
let odd = UserTag { tag: "a\"b\\c\n\u{1}é".into(), token: Vec::new() };
|
||||
assert_eq!(odd.value(1), r#"{"myts_token":"","tag":"a\"b\\c\n\u0001é","updated":1}"#);
|
||||
// TeamSpeak's escaping on the wire; empty clears.
|
||||
let packet = user_tag_packet(&tag.value(5)).into_packet();
|
||||
assert_eq!(
|
||||
packet.content(),
|
||||
b"updatemytsdata myts_certificate=a\\sb\\/c\\pd\\\\\\a\\b\x00\xff myts_avatar=\\n\x02hi"
|
||||
&br#"clientupdate client_user_tag={"myts_token":"+\/8BAg==","tag":"alex@myteamspeak.com","updated":5}"#[..]
|
||||
);
|
||||
// Without an avatar: the certificate alone.
|
||||
let packet = data_packet(&MytsData { avatar: Vec::new(), ..data }).into_packet();
|
||||
assert!(!packet.content().windows(11).any(|w| w == b"myts_avatar"));
|
||||
assert_eq!(user_tag_packet("").into_packet().content(), b"clientupdate client_user_tag");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user