myTeamSpeak: announce the account ID to servers

Signs clientinit with the account's Ed25519 key over the connection
challenge, honours the per-bookmark switch, sends updatemytsid on
sign-in/out, and connects without the ID when myTeamSpeak is unreachable.
Verified live against server.lixko.eu.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-10 20:04:59 +00:00
co-authored by Claude Opus 5.5
parent ca86c510b7
commit 801dfa39ab
14 changed files with 754 additions and 16 deletions
@@ -0,0 +1,80 @@
package eu.lixko.ts3j.client.myts;
import Punisher.NaCl.Internal.Ed25519Ref10.GroupElementP3;
import Punisher.NaCl.Internal.Ed25519Ref10.GroupOperations;
import Punisher.NaCl.Internal.Ed25519Ref10.ScalarOperations;
import org.bouncycastle.math.ec.rfc8032.Ed25519;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Arrays;
import java.util.Base64;
import java.util.HexFormat;
/** Offline RE fixture, not application integration. See myteamspeak_server_signin.md. */
public class MyTsAuthCheck {
private static byte[] hash(String algorithm, byte[]... parts) throws Exception {
MessageDigest digest = MessageDigest.getInstance(algorithm);
for (byte[] part : parts) digest.update(part);
return digest.digest();
}
private static byte[] point(byte[] scalar) {
GroupElementP3 point = new GroupElementP3();
GroupOperations.ge_scalarmult_base(point, scalar, 0);
byte[] encoded = new byte[32];
GroupOperations.ge_p3_tobytes(encoded, 0, point);
return encoded;
}
static byte[] sign(byte[] scalar, byte[] publicKey, byte[] message) throws Exception {
byte[] r = hash("SHA-512", scalar, message);
ScalarOperations.sc_reduce(r);
byte[] R = point(r);
byte[] k = hash("SHA-512", R, publicKey, message);
ScalarOperations.sc_reduce(k);
byte[] s = new byte[32];
ScalarOperations.sc_muladd(s, k, scalar, r);
byte[] signature = Arrays.copyOf(R, 64);
System.arraycopy(s, 0, signature, 32, 32);
Arrays.fill(r, (byte) 0);
Arrays.fill(k, (byte) 0);
Arrays.fill(s, (byte) 0);
return signature;
}
private static void check(boolean ok, String description) {
if (!ok) throw new AssertionError(description);
System.out.println("PASS: " + description);
}
public static void main(String[] args) throws Exception {
HexFormat hex = HexFormat.of();
// Existing throwaway-account fixture from the earlier capture.
byte[] itemKey = hex.parseHex("22efa5d631ddaa11ec97ccb82846b4d24598a9376319f444b5065cd47b391b2d");
byte[] encrypted = Base64.getDecoder().decode(
"oMyzSUejPJPlg40t4mlEFGYFDYJdgKGuLDhWAhfD2VXnlk2fwf+lf7Wi5RMv2zsrk78mBCiQ9TSwQjFaIs7JrMUItZrc6kTsxZwWTPOetTpxebk7wMShPgPyOMqN+Nr68shjWCtXGH8G4E/kVtxIzw==");
byte[] scalar = MyTsCrypto.decryptItem(encrypted, itemKey);
byte[] publicKey = hex.parseHex("4ffcab6e0aeefbcbc0b4bbbe25b7e36c171016f73a65c3a71dd4bb5a9f5dab8e");
check(scalar.length == 32 && Arrays.equals(point(scalar), publicKey),
"private-key item unwrap passes integrity and a*B equals account public key");
byte[] seedPublicKey = new byte[32];
Ed25519.generatePublicKey(scalar, 0, seedPublicKey, 0);
check(!Arrays.equals(seedPublicKey, publicKey), "scalar is not a standard Ed25519 seed");
byte[] sharedIV = new byte[64];
for (int i = 0; i < sharedIV.length; i++) sharedIV[i] = (byte) i;
byte[] C = hash("SHA-256", hex.parseHex("300800000000"), sharedIV);
check(hex.formatHex(C).equals("d178cabdc4faa5bb033b175d2f691564975d38b48994ab8eaf93ee88f1bb73f8"),
"challenge matches native-emulation synthetic vector");
byte[] message = Arrays.copyOf(C, 45);
System.arraycopy("MyTeamSpeakID".getBytes(StandardCharsets.US_ASCII), 0, message, 32, 13);
byte[] signature = sign(scalar, publicKey, message);
check(Ed25519.verify(signature, 0, publicKey, 0, message, 0, message.length),
"existing ref10 arithmetic signs; stock Bouncy Castle verifies");
message[0] ^= 1;
check(!Ed25519.verify(signature, 0, publicKey, 0, message, 0, message.length),
"changed connection challenge is rejected");
Arrays.fill(scalar, (byte) 0);
Arrays.fill(itemKey, (byte) 0);
}
}
@@ -0,0 +1,89 @@
#!/usr/bin/env python3
"""Offline check of TS3 3.6.2's authSign challenge derivation (requires unicorn).
Run with the path to ts3client_linux_amd64. No account or network is used.
Emulates the actual packet-key derivation up to its hash call, replacing only
allocation, copying, freeing, and mutex functions. Addresses are version-specific.
"""
import hashlib
import struct
import sys
from unicorn import Uc, UC_ARCH_X86, UC_MODE_64, UC_HOOK_CODE
from unicorn.x86_const import (
UC_X86_REG_RAX, UC_X86_REG_RDI, UC_X86_REG_RSI, UC_X86_REG_RDX,
UC_X86_REG_RCX, UC_X86_REG_R8, UC_X86_REG_R9, UC_X86_REG_RSP,
UC_X86_REG_RIP,
)
def main(path):
with open(path, "rb") as binary:
data = binary.read()
assert data[:6] == b"\x7fELF\x02\x01", "Expected little-endian ELF64"
phoff = struct.unpack_from("<Q", data, 32)[0]
phsize, phnum = struct.unpack_from("<HH", data, 54)
uc = Uc(UC_ARCH_X86, UC_MODE_64)
uc.mem_map(0, 0x2100000)
for i in range(phnum):
kind, _, offset, addr, _, size, _, _ = struct.unpack_from(
"<IIQQQQQQ", data, phoff + i * phsize)
if kind == 1 and size:
uc.mem_write(addr, data[offset:offset + size])
for addr, expected in [(0x2e2211, b"sha256"), (0x2b2164, b"sha512")]:
assert bytes(uc.mem_read(addr, len(expected))) == expected
uc.mem_map(0x4000000, 0x1000000)
obj, shared, out, stack = 0x4000000, 0x4001000, 0x4002000, 0x4fff000
shared_iv = bytes(range(64))
uc.mem_write(shared, shared_iv)
uc.mem_write(obj + 0x1b8, struct.pack("<Q", shared))
uc.mem_write(obj + 0x1c0, struct.pack("<I", 2)) # 64-byte sharedIV
uc.mem_write(obj + 0x1e8, struct.pack("<II", 0, 123)) # AES128 / sentinel hash index
uc.mem_write(obj + 0x209, b"\x01")
uc.mem_write(obj + 0x310, struct.pack("<Q", 0x4003000)) # empty key cache
uc.mem_write(stack, struct.pack("<Q", 0x10000))
for reg, val in [(UC_X86_REG_RDI, out), (UC_X86_REG_RSI, obj),
(UC_X86_REG_RDX, 0), (UC_X86_REG_RCX, 0),
(UC_X86_REG_R8, 8), (UC_X86_REG_R9, 0),
(UC_X86_REG_RSP, stack)]:
uc.reg_write(reg, val)
heap = 0x4010000
captured = []
def hook(machine, address, size, user):
nonlocal heap
def ret(value=0):
sp = machine.reg_read(UC_X86_REG_RSP)
target = struct.unpack("<Q", machine.mem_read(sp, 8))[0]
machine.reg_write(UC_X86_REG_RSP, sp + 8)
machine.reg_write(UC_X86_REG_RAX, value)
machine.reg_write(UC_X86_REG_RIP, target)
if address in (0x1ae27a0, 0x1ae3f80): # operator new / new[]
ptr = heap
heap += (machine.reg_read(UC_X86_REG_RDI) + 31) & ~15
ret(ptr)
elif address in (0x1ae23a0, 0x1aeb290): # delete / mutex lock
ret()
elif address == 0x1ae3450: # memmove
dst, src, n = [machine.reg_read(r) for r in
(UC_X86_REG_RDI, UC_X86_REG_RSI, UC_X86_REG_RDX)]
if n:
machine.mem_write(dst, bytes(machine.mem_read(src, n)))
ret(dst)
elif address == 0x11ec190: # LibTomCrypt hash_memory
assert machine.reg_read(UC_X86_REG_RDI) == 123
ptr, n = [machine.reg_read(r) for r in (UC_X86_REG_RSI, UC_X86_REG_RDX)]
captured.append(bytes(machine.mem_read(ptr, n)))
machine.emu_stop()
elif address >= 0x1ae0000:
raise AssertionError(f"Unexpected external call: {address:x}")
uc.hook_add(UC_HOOK_CODE, hook)
uc.emu_start(0xff4770, 0x10000, count=100000)
assert captured == [bytes.fromhex("300800000000") + shared_iv], captured
print("Native hash input matches 30 08 00 00 00 00 || sharedIV")
print("Synthetic C:", hashlib.sha256(captured[0]).hexdigest())
if __name__ == "__main__":
main(sys.argv[1])
@@ -4,6 +4,11 @@ What the client has to send so that a server shows our `client_myteamspeak_id`,
official client does when a bookmark has "Enable myTeamSpeak features" on. Observed with TS3 3.6.2
signed in to the throwaway account against the test server, 2026-10-10.
**RE status:** both missing inputs are now recovered and checked offline. The private scalar
unwrap matches the captured account public key; the challenge derivation was exercised in the
actual desktop machine code under Unicorn. Application integration is implemented (see below)
and verified live against server.lixko.eu (2026-10-10). Reproduction programs are linked below.
## The switch
Connect dialog and bookmarks: **"Enable myTeamSpeak features"**, on by default. It is
@@ -24,19 +29,201 @@ for signing in or out while connected. It was not hit during a normal connect.
| `userPubKey` | base64, 32 bytes (Ed25519 public key) | known: login `myts_id_data.user_public_key (1)` |
| `pubSign` | base64, 64 bytes | known: first 64 bytes of login `myts_id_data.public_signature (5)` |
| `pubSignCert` | base64, 112 bytes (certificate naming "TeamSpeak Systems GmbH") | known: remaining 112 bytes of `public_signature (5)` |
| `authSign` | base64, 64 bytes | **unknown, still to find** |
| `authSign` | base64, 64 bytes | raw-scalar Ed25519 over `SHA256(30 08 00 00 00 00 || sharedIV) || "MyTeamSpeakID"` |
`acTime` example: creation time `1790376353` = `0x6AB6F9A1`; as big-endian u64
`a1f9b66a00000000` = `11671560475690139648`.
## Still to find: `authSign`
## `authSign` — reverse-engineered (static, 2026-10-10)
- It is made fresh for each connection. It is not part of the login reply, and replaying an old
one is not expected to work.
- Without valid data the server refuses the ID: `clientupdate client_myteamspeak_id=<anything>`
gives "invalid parameter".
- To find: what `authSign` covers and how the client produces it, using only what our existing
sign-in (`MyTeamSpeakLogin`) already holds.
`authSign` is an **Ed25519 signature** (64 bytes = `R||S`, base64) by the account's user key over a
per-connection message. It is made fresh per connection because the message embeds a
connection-derived challenge, so replaying an old one does not work.
### Where it is built
All six `clientinit`/`updatemytsid` parameters are assembled by one function (call it
`buildMytsidParams`) in the Android `libteamspeak_client.so` (x86-64) at **vaddr 0x813b40**, called
from 3 sites (0x81bda4, 0x81e677, 0x84f2c8 — the clientinit and updatemytsid paths). The desktop
`ts3client_linux_amd64` carries the same code (same strings + SHA-512 K-table). Its args:
- `arg0` (rdi) = the **user keypair** object. Two 32-byte `std::string` members:
`+0x20` = public key `A`, `+0x38` = **raw secret scalar `a`**. In the callers this object is at
`[conn+0x218]`.
- `arg1` (rsi) = the command/parameter map (values inserted via the helper at 0x8b1870).
- `arg2` (rdx) = a reference to a **shared pointer to the connection crypto object**, obtained
through the manager's `vtable+0x70`. It is **not a string**. The builder obtains packet-key
material from this object to construct `C`; see the corrected desktop trace below.
`myTeamspeakId`, `acTime`, `userPubKey`, `pubSign`, `pubSignCert` are just base64 of fields of the
`MyTeamSpeakIdData` struct (offsets 0, +0x18, +0x20, +0x50, +0x68). `authSign` is the odd one out:
its value is `base64(sig)` where `sig` is produced by the signer at **0x94a2a0** over the message
`M = C || "MyTeamSpeakID"` (the literal is appended to the challenge before signing).
### The signer (0x94a2a0) — deterministic Ed25519 over SHA-512
Reconstructed (hash factory 0x9430e0 with selector `1` = SHA-512; `R=r·B` via 0x94ee80;
reduce mod L via 0x94a7b0; `S=r+k·a` via 0x94b310):
```
r = SHA512(a || M) mod L # deterministic nonce, seeded by the raw scalar a
R = r · B # 32-byte encoded point -> sig[0:32]
k = SHA512(R || A || M) mod L
S = (r + k · a) mod L # -> sig[32:64]
authSign = base64(R || S)
```
Because `R = r·B` and `A = a·B`, this is a **standard, stock-verifiable Ed25519 signature over `M`
under public key `A`** — the server almost certainly just runs `ed25519_verify(authSign, M, A)`.
The signature equation is standard Ed25519, although nonce derivation and secret-key format differ
from RFC 8032. A standard verifier accepts this construction. We can reproduce the exact nonce
using the existing ref10 arithmetic; there is no need to rely on untested alternative nonces.
**Correction:** Bouncy Castle's public low-level signing overloads also take a seed. Passing `a`
as that seed hashes and clamps it again and gives the wrong key. Its raw-scalar signing internals
are private; stock TweetNaCl's signing entry point is seed-based too.
## Dynamic capture — scheme CONFIRMED live (2026-10-10)
Ran the official TS3 3.6.2 client under Xvfb (`GLIBC_TUNABLES=glibc.pthread.rseq=0` to stop a
`mutex lock failed` crash on new glibc; the xcb/libpci lib shim set from the prior harness), signed
in to the throwaway myTeamSpeak account, and connected to `server.lixko.eu:9987` with "Enable
myTeamSpeak features" on. gdb attached as root (yama scope=1 → `sudo gdb`), breakpoint at the signer.
**The server accepted the real `authSign` ("Connection established")**, so the model below is the live
protocol, not a guess.
Desktop addresses (PIE; add the load bias): signer **0x1196800** (= Android 0x94a2a0),
`buildMytsidParams` **0x1018580**, its clientinit caller **0x1020c3b**. At the signer: `rcx`=`A`,
`r8`=`a`, `rsi`/`rdx`=`M`, `rdi`=out(`R||S`).
### Ground truth (throwaway account)
```
a (secret scalar) = e02e4e5f22623f82389e469e56290ac046c13f7ecc6fde99d17360d1f4bfd67a
A (public key) = 4ffcab6e0aeefbcbc0b4bbbe25b7e36c171016f73a65c3a71dd4bb5a9f5dab8e
M = C || "MyTeamSpeakID" (C = 32 bytes, then the 13-byte ASCII literal; rdx = 45)
```
Verified offline (pure-Python Ed25519 + `cryptography`): **`A == a·B`** (so `a` is the raw Ed25519
scalar, `A` the public key), and the deterministic scheme above produces a signature that **passes
stock `Ed25519PublicKey(A).verify(sig, M)`**. This confirms compatibility with stock Ed25519
verification, not the server's exact implementation. `A` is the `userPubKey`/`user_public_key`
param (it is NOT the 31-byte body of the `myTeamspeakId`).
### `C` recovered: packet key + nonce for type 8, server direction, generation 0
For the captured AES-128/SHA-256 connection mode:
```
sharedIV = SHA512(encoded_Ed25519_DH_point) XOR (alpha[10] || beta[54])
C = SHA256(hex("30 08 00 00 00 00") || sharedIV)
M = C || ASCII("MyTeamSpeakID") # exactly 45 bytes, no NUL terminator
```
`sharedIV` is precisely ts3j's `SecureChannelParameters.ivStruct` / the value passed into
`PacketTransformation`. It is not the raw shared secret. `30` is the server-direction tag,
`08` is packet type 8, and the four zeros are the big-endian generation counter. Packet ID is
also zero, so the usual XOR of the first two key bytes changes nothing. Equivalently, obtain
`key || nonce` from `PacketTransformation.computeParameters` with a SERVER header of type 8,
generation 0 and packet ID 0. Do not use the CLIENT direction merely because we are the client.
Corrected desktop trace (all addresses are PIE-relative):
| Address | Evidence |
|---|---|
| `0x1020c05` | manager virtual call returns a shared pointer at `rsp+0x88` |
| `0x105a270` → `0x105ed30` | selects enum key 1 in map at manager `+0x110`; returns two pointers and increments reference count, **not a std::string** |
| `0x1018a57`–`0x1018a6f` | dereferences that shared pointer; calls `0xff4770(out, crypto, 0, 0, 8, 0)` |
| `0xff496d`–`0xff4a89` | builds direction/type/generation prefix `30 08 00 00 00 00` |
| `0xff4a92`–`0xff4b77` | appends bytes from crypto `+0x1b8`, 64 bytes for handshake mode 2/3, otherwise 20 |
| `0xff4ba9` | calls LibTomCrypt `hash_memory` with the configured hash selector |
| `0xfef971`–`0xfef97d` | cipher mode 0 selects the literal `sha256`; mode 1 selects `sha512` at `0xfef953` |
| `0xff4ed8`–`0xff4ee9` | XORs packet ID into the key's first two bytes (zero here) |
| `0x1018acc`–`0x1018bcb` | copies and concatenates key and nonce (16+16 bytes in mode 0; 32+32 in mode 1) |
| `0x1018ce3`–`0x1018cfb` | appends the 13-byte literal before signing |
The sharedIV buffer is XORed with the handshake secret at `0xff2a08` (64 bytes) through
`0x129b9d0`, an in-place XOR helper. The same buffer feeds ordinary packet key derivation.
This explains why searching the manager's inline memory for plain SHA-256 preimages failed:
the buffer is in a different object and the hash has a six-byte prefix.
The previous captures of different `C` values remain useful, but `C.bin`/`C_obj.bin` from the
old string-decoding harness are not reliable challenge dumps: those interpreted a shared pointer
as a libc++ string. The signer message captures (`msg*.bin`) are the reliable `C || literal` bytes.
The native code also supports a SHA-512, 32-byte key + 32-byte nonce mode; its binder would be
64 bytes and message 77 bytes. The observed session and current ts3j packet cipher use mode 0.
Do not generalize the 32-byte challenge to every possible negotiated cipher mode.
### Scalar unwrap recovered and verified
```
accountKey = PBKDF2_HMAC_SHA512(password, lower(email)+"ts3Encryption"+password, 10000, 32)
itemKey = MyTsCrypto.unwrapItemKey(accountKey, LoginSession.key)
a = MyTsCrypto.decryptItem(encrypted_user_private_key, itemKey)
assert len(a) == 32
assert encode(a * B) == user_public_key
```
The 112-byte blob is the existing item frame: `IV[16] || ciphertext[32] || SHA512(a)[64]`,
AES-256-CTR with little-endian counter increments. No additional KDF or scalar clamping occurs
after decryption. The captured blob passes the digest check and produces **exactly** the live
scalar above. Deriving a public key from that value as a Bouncy Castle seed produces a different
public key, independently confirming the distinction.
### Library choice and reproducible checks
Use existing JCA `MyTsCrypto` for key unwrap and existing ts3j ref10 primitives for signing:
`ScalarOperations.sc_reduce`, `GroupOperations.ge_scalarmult_base`,
`GroupOperations.ge_p3_tobytes`, and `ScalarOperations.sc_muladd`. The thin signing adapter is
in [MyTsAuthCheck.java](MyTsAuthCheck.java); it implements the formula above without new curve
arithmetic. `Punisher.NaCl.Ed25519.Sign` itself is also seed-based despite its parameter being
called `expandedPrivateKey`, so do not call it with `a || A`.
Bouncy Castle 1.86 can verify these signatures directly. Its public signer cannot sign from the
raw scalar; [upstream Ed25519 source](https://github.com/bcgit/bc-java/blob/main/core/src/main/java/org/bouncycastle/math/ec/rfc8032/Ed25519.java)
keeps the scalar-based `implSign` and base-point helpers private. Reflection into these internals
is unnecessary. This is plain Ed25519 verification, not Ed25519ph or Ed25519ctx; the literal is
part of the message, not an RFC 8032 context parameter.
From the workspace root, with ts3j compiled and BC 1.86 in the local Maven cache:
```sh
python3 ts3-client/docs/myteamspeak/check_native_challenge.py TeamSpeak3-Client-linux_amd64/ts3client_linux_amd64
mkdir -p /tmp/myts-auth-check
auth_cp="ts3j/target/classes:$HOME/.m2/repository/org/bouncycastle/bcprov-jdk18on/1.86/bcprov-jdk18on-1.86.jar"
javac -cp "$auth_cp" -d /tmp/myts-auth-check ts3-client/core/src/main/java/eu/lixko/ts3j/client/myts/MyTsCrypto.java ts3-client/docs/myteamspeak/MyTsAuthCheck.java
java -cp "/tmp/myts-auth-check:$auth_cp" eu.lixko.ts3j.client.myts.MyTsAuthCheck
```
The Python check requires Unicorn and executes the actual native packet-key routine with synthetic
sharedIV `00 01 … 3f`, stopping at the hash call. It asserts the exact hash input and checks the
native hash-name literals. Expected challenge:
`d178cabdc4faa5bb033b175d2f691564975d38b48994ab8eaf93ee88f1bb73f8`.
The Java check verifies the captured private-key unwrap/public-key relation, rejects the seed
interpretation, signs the synthetic challenge using existing arithmetic, verifies with stock BC,
and confirms that changing the challenge invalidates the signature. All checks passed.
**Live check (2026-10-10, server.lixko.eu, throwaway account):** our `clientinit` with the six
parameters makes the server report `client_myteamspeak_id`; without them it is absent; an
`updatemytsid` with empty values clears it and a freshly signed one sets it again, also on a
connection that started without it. A `clientinit` with one bit of `authSign` flipped still
connects but the server silently drops the ID, so the signature is checked.
Production integration now lives in `MyTeamSpeakIdentity`, `MyTeamSpeakLogin.serverIdentity`,
and ts3j's `addMyTeamSpeakParameters`. Desktop and Android provide the signed-in account to
the connection, honor the bookmark switch, and send `updatemytsid` on account changes.
The scalar is cached only in memory and wiped on sign-out/account replacement. The Connect
dialog also offers the feature switch. Automated tests cover the parser, signature, connection
binding, saved sign-in, and revocation.
### Capture harness notes (reusable)
- Official client: `GLIBC_TUNABLES=glibc.pthread.rseq=0`, `LD_LIBRARY_PATH` += the xcb/libpci shim
dir, `HOME`=throwaway profile, under Xvfb. License + "stay logged in" persist in `settings.db`, so
only the first run needs the EULA/login clicks.
- Do **not** `kill -9` gdb while it holds the inferior stopped — it crashes the client. Make the gdb
script `detach` + `quit` itself after the capture, or `kill -INT`.
- `std::string` (libc++): flag byte at +0; long if `flag&1` → size at +8, data ptr at +16; else short
→ size `flag>>1`, data at +1.
## Verification once it is known