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
+101
-10
@@ -76,9 +76,30 @@ Every login, post and settings change is written to the audit table.
|
||||
`permoverview`, `banlist`, `clientmove`, `sendtextmessage`,
|
||||
`servergroupsbyclientid` and `channelgroupclientlist`, e.g. a dedicated
|
||||
login in the Server Admin group.
|
||||
3. Put the gateway's IP into `query_ip_allowlist.txt` and set
|
||||
`query.allowlisted = true`. Otherwise the server's flood protection
|
||||
(10 commands / 3 s) applies and bans the gateway under load.
|
||||
3. Put the address the server sees for the gateway into the server's
|
||||
`query_ip_allowlist.txt` and set `query.allowlisted = true`. The server's
|
||||
flood protection counts the query commands of each address, all of
|
||||
tsgw's connections together and the SSH login included: it refuses the
|
||||
10th command within 3 seconds and asks to wait, and two more commands
|
||||
during the wait get the address banned for 600 seconds. tsgw logs the
|
||||
address when it starts ("the TeamSpeak server sees the gateway's queries
|
||||
coming from this address"):
|
||||
- tsgw on the server's machine: `127.0.0.1`, which the file lists by
|
||||
default.
|
||||
- tsgw in a Docker container with bridge networking: the container's
|
||||
or the bridge's address (e.g. `172.17.0.2`), not `127.0.0.1`. Add
|
||||
that address, or run the container with `--network host`.
|
||||
|
||||
The server reads the file again within seconds, without a restart; that
|
||||
also lifts a 600 s ban. Do not set `allowlisted = true` without the
|
||||
entry in the file: tsgw then sends at full speed until the server
|
||||
refuses a command, and an older tsgw got the address banned that way.
|
||||
Now it stops at the first refusal and logs "the server limits this
|
||||
address although it was taken to be on its query allowlist". Without
|
||||
the allowlist tsgw stays under the limit itself (9 commands per 3 s
|
||||
over all its connections) and, after a refusal (other query tools on
|
||||
the same address count too), sends nothing on any connection for at
|
||||
least 3 s, so logins are slower when many happen at once.
|
||||
4. Each relayed channel is one more query connection. Keep
|
||||
`relay.max_channel_relays` below the server's per-IP connection limit.
|
||||
Relays count toward a channel's max clients unless their group has
|
||||
@@ -105,8 +126,13 @@ changes: what is published takes the place of what was found before (a
|
||||
lookup that finds nothing keeps it). Every gateway found is kept and
|
||||
tried in turn, best first, each for up to 20 seconds; the first that logs
|
||||
in is used, and the log file names those it passed over (URL and error).
|
||||
Only when all of them fail does it wait (2, 5, 15, 30, then every 60
|
||||
seconds) and start over; users see nothing of it.
|
||||
Only when all of them fail does it wait (1, 2, 5, 10, 20, then every 30
|
||||
seconds, give or take 30 %; at once when voice connects) and start over;
|
||||
users see nothing of it. Only a refused login ends it (bad signature,
|
||||
security level too low, banned, not allowed); a gateway that cannot do the
|
||||
login yet (for example an identity the server has not seen) is tried again.
|
||||
Once connected, the client pings the gateway every 30 seconds and connects
|
||||
again after 60 seconds without an answer.
|
||||
|
||||
**DNS records** (preferred). An SRV record names the gateway's host and
|
||||
port, the service name says whether it speaks TLS:
|
||||
@@ -150,9 +176,10 @@ gateway's host (`gw.example.org`) with one upstream, tsgw's plain address
|
||||
(`<tsgw host>:7788`), "Proxy Target require TLS Connection" off,
|
||||
WebSockets on, and a certificate for the host (ACME). If the rule also
|
||||
has an uptime monitor, point it at `/health` (tsgw's `/` answers 404).
|
||||
Check from outside: `curl https://gw.example.org/health` prints `ok`;
|
||||
Zoraxy's own `404 page not found` there means no rule matched the host or
|
||||
the request went to another upstream. Then set `listen.public_url =
|
||||
Check from outside: `curl https://gw.example.org/health` prints `ok` (or
|
||||
what is missing while tsgw is not logged in to the TeamSpeak server, see
|
||||
[Logs](#logs)); Zoraxy's own `404 page not found` there means no rule
|
||||
matched the host or the request went to another upstream. Then set `listen.public_url =
|
||||
"wss://gw.example.org/v1"` in tsgw.toml, so its own answer points at the
|
||||
proxy.
|
||||
|
||||
@@ -214,11 +241,74 @@ the unit to `/etc/systemd/system/`.
|
||||
|
||||
```sh
|
||||
docker load -i tsgw-image.tar.gz # or: docker build -f crates/voelin-gateway/Dockerfile -t tsgw .
|
||||
docker run -v $PWD/tsgw.toml:/etc/tsgw/tsgw.toml -e TSGW_QUERY_PASSWORD=… -p 7788:7788 tsgw
|
||||
docker run -d --name tsgw --init --restart unless-stopped \
|
||||
-v $PWD/tsgw.toml:/etc/tsgw/tsgw.toml:ro -v tsgw-data:/var/lib/tsgw \
|
||||
-e TSGW_QUERY_PASSWORD=… -p 7788:7788 tsgw
|
||||
docker logs -f tsgw
|
||||
```
|
||||
|
||||
The volume keeps the database (`/var/lib/tsgw/tsgw.db`: login tokens,
|
||||
history, settings changed at runtime) when the container is replaced.
|
||||
`--init` passes `docker stop` on to tsgw and cleans up after it;
|
||||
`--restart unless-stopped` brings it back after a crash or a reboot. With
|
||||
bridge networking (the default) see step 3 of [Setup](#setup) about the
|
||||
address the TeamSpeak server sees.
|
||||
|
||||
**From source:** `cargo run --release -p voelin-gateway -- --config tsgw.toml`.
|
||||
|
||||
## Logs
|
||||
|
||||
tsgw logs to standard output: `journalctl -u tsgw -f` under systemd,
|
||||
`docker logs -f tsgw` in a container (colours only on a terminal; `NO_COLOR`
|
||||
turns them off there too). At the default level it logs:
|
||||
|
||||
- at start: the version and settings in use (whether a query password is
|
||||
set, never the password itself), the query login and how long it took,
|
||||
the address the TeamSpeak server sees for the gateway (with a hint when
|
||||
`query.allowlisted` is off), "listening" with the URL apps are given;
|
||||
- each app connection: its address, `X-Forwarded-For` and `User-Agent`,
|
||||
then logins (unique id, nickname, signature or token, how long it took),
|
||||
refused logins with the reason, requests slower than 1 s and the close
|
||||
(reason, how long it was open). Every line of a connection carries its
|
||||
number and address (`ws{id=12 peer=…}`);
|
||||
- ServerQuery: failed commands (by name), each wait the server's flood
|
||||
protection asks for, relays opened and closed, the watcher connecting
|
||||
and losing its connection (with the attempt and the next wait), the
|
||||
lookup connection lost and restored.
|
||||
|
||||
More detail with `log.level` (`TSGW_LOG_LEVEL`; without it `RUST_LOG`):
|
||||
|
||||
| Setting | Shows |
|
||||
|---|---|
|
||||
| `TSGW_LOG_LEVEL=debug` | also every request and its time, ServerQuery connections opening and closing |
|
||||
| `TSGW_LOG_LEVEL=info,voelin_query=trace` | every query command sent and answered, with its time and the connection it went over (`lookup`, `observer`, `relay <channel>`) |
|
||||
| `TSGW_LOG_LEVEL=warn` | only problems |
|
||||
|
||||
Libraries that log every packet (`russh`, `hyper`, `h2`, `tower`,
|
||||
`tungstenite`) stay at warnings unless the setting names them
|
||||
(`debug,russh=debug`). Under systemd put the variable into
|
||||
`/etc/tsgw/tsgw.env`, in a container pass `-e TSGW_LOG_LEVEL=…`.
|
||||
|
||||
`log.file` (`TSGW_LOG_FILE`) writes the log to a file as well. tsgw appends
|
||||
to it, also across restarts; at 20 MB it moves to `tsgw.1.log` (older ones
|
||||
one further along, 5 files in all) and a new one starts. A relative path is
|
||||
relative to the working directory, `/var/lib/tsgw` under systemd and in the
|
||||
container (`TSGW_LOG_FILE=logs/tsgw.log` with the volume above). The systemd
|
||||
unit can also write `/var/log/tsgw`. If the file cannot be opened, tsgw
|
||||
says so and logs to standard output only.
|
||||
|
||||
While the TeamSpeak server cannot be reached (not started yet, restarting),
|
||||
tsgw listens anyway and logs in as soon as it can, waiting 1, 2, 3, 5, 10,
|
||||
then 30 seconds between attempts (longer if the server's flood protection
|
||||
asks for it). Apps that connect meanwhile wait up to 10 seconds, then are
|
||||
told to try again. A query connection the server drops is opened again the
|
||||
same way, and relays that someone still reads or that are pinned come back.
|
||||
Opening a query connection (connecting, logging in, selecting the server)
|
||||
gives up after 10 seconds, so a server that does not answer holds up
|
||||
nothing for long. `/health` answers
|
||||
`ok` while the gateway is logged in and watching the server, otherwise 503
|
||||
and what is missing (`starting: …`, `query: down, observer: up`).
|
||||
|
||||
## Visibility
|
||||
|
||||
Query clients are not hidden by the server; official clients hide them from
|
||||
@@ -234,7 +324,8 @@ query clients sees that it came from a query session.
|
||||
|
||||
- **Bootstrap** keys are needed before the database opens: `gateway_id`,
|
||||
`server.voice_port`, `query.*` (transport, address, login, password,
|
||||
`allowlisted`), `listen.bind`, `listen.public_url` and `history.path`.
|
||||
`allowlisted`), `listen.bind`, `listen.public_url`, `history.path` and
|
||||
`log.level`, `log.file` ([Logs](#logs)).
|
||||
They come from the file, the environment or the command line and apply
|
||||
at start; changing them needs a restart.
|
||||
- Everything else (history, relays, features, permission rules, quotas,
|
||||
|
||||
@@ -111,25 +111,73 @@ URL.
|
||||
### Presenting the account's avatar, and other clients' avatars (TeamSpeak 6)
|
||||
|
||||
Voice servers show the account's avatar (and the blurred banner behind it
|
||||
in the client-info view) from what the client sends once connected, not
|
||||
from `clientinit` (the official 6.0.0-beta4.1 client never sets
|
||||
`client_myteamspeak_avatar` or `client_signed_badges` itself):
|
||||
in the client-info view) and badges from what the client sends once
|
||||
connected, not from `clientinit` (the official 6.0.0-beta4.1 client never
|
||||
sets `client_myteamspeak_avatar` or `client_signed_badges` itself):
|
||||
|
||||
updatemytsdata myts_certificate=<cert> [myts_signed_badge=<list>] [myts_avatar=<AvatarData>]
|
||||
|
||||
built at 0x1f38520: `myts_certificate` is `LoginSession.mytsid_user_cert.cert`,
|
||||
`myts_avatar` the serialized `LoginSession.user_avatar` (`AvatarData` with its
|
||||
timestamp and myTeamSpeak's signature, which covers `AvatarInfo`, the myTS
|
||||
id and the timestamp), `myts_signed_badge` a `UserBadgesSignedList` from
|
||||
`getSignedBadges`. The values are the raw bytes with TeamSpeak's escaping
|
||||
only (`\a` and `\b` included), no base64. It is sent once the connection is
|
||||
established, after a sign-in (after `updatemytsid`), after an avatar upload
|
||||
and after a badge change. Voelin sends the certificate and the avatar: both
|
||||
come only from a password sign-in (`LoginSession`, fields 10 and 11), the
|
||||
avatar sliced out of the response as it came (encoding it again would drop
|
||||
fields this version does not know and break the signature). They are kept
|
||||
in `<data>/account/presentation.json` (public data) and sent to every
|
||||
connection that presents the account; a refusal is only logged.
|
||||
built at 0x1f38520: `myts_certificate` is the inner `MyTSUserCertificate.cert`
|
||||
bytes, `myts_avatar` a serialized `AvatarData` (its `AvatarInfo`, a timestamp
|
||||
and myTeamSpeak's signature), `myts_signed_badge` a `UserBadgesSignedList`
|
||||
of the badges the user chose (at most three, in the chosen order; none
|
||||
until chosen). The values are the raw bytes with TeamSpeak's escaping only
|
||||
(`\a` and `\b` included), no base64. The official client sends it once
|
||||
connected, after a sign-in (after `updatemytsid`), after an avatar upload
|
||||
and after a badge change.
|
||||
|
||||
What the TeamSpeak 6 server (6.0.0-beta13.1) does with it: it parses the
|
||||
certificate as a TeamSpeak license chain, requires the leaf to be valid now,
|
||||
of block type 6 (`MYTSID_SIGN`; types 4 to 7 carry nothing after the 42-byte
|
||||
header), the chain to lead to TeamSpeak's root and the key not to be on
|
||||
myTeamSpeak's revocation list, and takes the leaf's derived Ed25519 key. It
|
||||
verifies the avatar's signature over `SerializeAsString(AvatarInfo) ||
|
||||
myTS ID (33 bytes) || timestamp (u64, big-endian)` and each badge's over
|
||||
`uuid (16 bytes) || sign_timestamp (u64, big-endian) || myTS ID`, the myTS
|
||||
ID being the one it holds for the client at that moment. What does not
|
||||
verify is silently emptied (`client_myteamspeak_avatar` /
|
||||
`client_signed_badges` become empty, answer `error id=0`); only an unusable
|
||||
certificate with a non-empty value is refused, with 1538 (also when the
|
||||
server could not load the revocation list). The server echoes both
|
||||
properties for the client before its answer. A bare parameter clears it
|
||||
without a certificate; an absent one is left alone. `updatemytsid` does
|
||||
not check them again, so they are sent again after it.
|
||||
|
||||
Voelin does the same checks locally (`tsproto::myts::Certificate`,
|
||||
`voelin_myts::choose_avatar`, `choose_badges_certificate`) to choose, for
|
||||
the avatar and for the chosen badges, a certificate that verifies them,
|
||||
from those at hand: the last password sign-in's (`LoginSession` fields 10
|
||||
and 11, the avatar as it came), the one myTeamSpeak's avatar service hands
|
||||
out with the avatar, and the myTS ID's `pubSignCert` when its leaf is of
|
||||
type 6. Since a server verifies with the one certificate of each command,
|
||||
the avatar and the badges go in separate commands when they need different
|
||||
certificates (one command, certificate, badges, avatar, when one verifies
|
||||
both). A badge id must be in the 36-character form with hyphens: the server
|
||||
reads it with Boost's `uuid` parser, which throws on anything else, so such
|
||||
a badge is never sent. After sending, Voelin logs whether the server shows
|
||||
them, or why not, and names the badges it dropped (`client_signed_badges`
|
||||
lists the ids that verified). Each connection sends only what changed, all
|
||||
of it again after `updatemytsid` or a reconnect, and clears with bare
|
||||
parameters what it showed and should no longer show: on a sign-out or an
|
||||
account change, `updatemytsdata myts_certificate myts_signed_badge
|
||||
myts_avatar` (or only the parts it showed; both answer 0).
|
||||
|
||||
Without a password: `requestContactsAvatar` at `/user` with the account's own
|
||||
raw myTS ID (`RequestContactsAvatarInfoRequest{session, id:
|
||||
[AvatarRequestID{key: Any(…AvatarRequestID.MYTSKey{id})}]}`) answers the
|
||||
account's `AvatarData` as it came, whose `optional` field holds
|
||||
`OptionalAvatarDataContactInfo{mytsid, user_cert}`; `user_cert` is checked
|
||||
by the official client with the same function as the login certificate. An
|
||||
unknown session gets an empty answer, like an account without an avatar, so
|
||||
an empty answer means "nothing learned" and never clears what is kept.
|
||||
`getSignedBadges(Session)` at `/user` answers `UserBadgesSignedResponse{list,
|
||||
error_code}` (109 for an unknown session); each `SignedUserBadge` is kept as
|
||||
it came. Voelin asks both after a password sign-in, after a checked saved
|
||||
session and then daily, and keeps the answers in
|
||||
`<data>/account/presentation.json` (public data); the chosen badges are kept
|
||||
per account in `<data>/account/badges.json`, across sign-outs. A chosen
|
||||
badge myTeamSpeak no longer lists takes none of the three places, and is
|
||||
dropped from the choice the next time the user changes it.
|
||||
|
||||
Other clients' avatars arrive as `client_myteamspeak_avatar`, plain text
|
||||
`<state>,<url>;<state>,<url>…` with myTeamSpeak's `AvatarState` numbers
|
||||
@@ -140,11 +188,6 @@ offline; the server's own avatar (`client_flag_avatar`) wins when it loads.
|
||||
Voelin downloads it (HTTPS, 4 MiB) where the server's is not shown: none
|
||||
set, no voice connection (observing), or its download gave up.
|
||||
|
||||
`client_user_tag` (the "User Tag", a TeamSpeak chat alias) is set by the
|
||||
client as JSON `{"myts_token":…,"tag":…,"updated":<ms>}` with a token from
|
||||
`requestSignedAllowedIdentifierList` at `/tschat`; receivers show it only
|
||||
after verifying the token. Voelin does not set it yet.
|
||||
|
||||
`requestAvatarSignedUrl` is not a download call: it signs *upload* links.
|
||||
In the TS6 6.0.0-beta4.1 Linux client, `Account_Manager_Impl::
|
||||
request_avatar_signed_urls`'s reply goes only to `upload_avatar`, whose
|
||||
@@ -164,6 +207,37 @@ session deletion; storage or remote errors are reported. A late completion
|
||||
cannot sign a canceled operation back in. Server identities and bookmark
|
||||
nicknames remain independent of the primary app profile.
|
||||
|
||||
### The User Tag (TeamSpeak 6)
|
||||
|
||||
`client_user_tag` is the account's primary TeamSpeak chat identifier
|
||||
(`name@myteamspeak.com`): the entry with `primary` set in
|
||||
`getActiveIdentifierList` at `/tschat` (Voelin falls back to
|
||||
`getAccountData`'s active identifiers). The token that proves it comes from
|
||||
`requestSignedAllowedIdentifierList` at `/tschat`; both take
|
||||
`AuthenticatedUser{session}` only (no chat account, `matrix_id` never set)
|
||||
and answer an `ErrorHandling` whose `return_code` must be 1 (5: the session
|
||||
expired). The token is a `MatrixIdentifierToken{signature, sign_certificate,
|
||||
timestamp, tags}`, kept as it came. Viewers (the official client's
|
||||
`verifyIdentifierToken`) parse `sign_certificate` as a license chain from
|
||||
TeamSpeak's root, require its leaf to be valid now (any block type), verify
|
||||
the Ed25519 signature over `SerializeAsString(tags) || timestamp (u64,
|
||||
big-endian) || myTS ID` with the myTS ID the client shows the server
|
||||
(`client_myteamspeak_id`), and require the tag to be one of the tags. They
|
||||
verify once per change of the property, and only if they have a TeamSpeak
|
||||
chat connection themselves. The value is compact JSON in this key order:
|
||||
|
||||
{"myts_token":"<standard padded base64 of the token>","tag":"<tag>","updated":<ms since 1970>}
|
||||
|
||||
sent as `clientupdate client_user_tag=<value>` (TeamSpeak escaping, so `/`
|
||||
goes as `\/`), once connected and after every `updatemytsid`, on servers
|
||||
that know the property (protocol 8, TeamSpeak 6; on protocol 7 the official
|
||||
client mirrors the JSON into `client_meta_data`, which Voelin leaves to its
|
||||
own identification). A bare `clientupdate client_user_tag` clears it, on
|
||||
sign-out or account change. The server stores and relays the value without
|
||||
checks (about 8 KB at most). Voelin checks the token itself before using it,
|
||||
asks for a new one when it would not hold three days later, and shows the
|
||||
tag in Settings → My Account.
|
||||
|
||||
### Authenticated account identity on voice servers
|
||||
|
||||
The account UUID is a profile identifier, not the authenticated `myTS ID`.
|
||||
|
||||
Reference in new issue
Block a user