From 801dfa39ab8bae65ecf5dcc88c4771c2b3229b9b Mon Sep 17 00:00:00 2001 From: ericek111 Date: Sat, 10 Oct 2026 20:04:59 +0000 Subject: [PATCH] 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 --- .../ts3j/client/android/SessionController.kt | 10 +- .../lixko/ts3j/client/myts/MyTeamSpeak.java | 33 ++- .../ts3j/client/myts/MyTeamSpeakIdentity.java | 88 ++++++++ .../ts3j/client/myts/MyTeamSpeakLogin.java | 43 ++++ .../ts3j/client/net/TeamspeakConnection.java | 59 +++++ .../ts3j/client/session/ServerSession.java | 1 + .../client/myts/MyTeamSpeakIdentityTest.java | 134 ++++++++++++ .../docs/myteamspeak/MyTsAuthCheck.java | 80 +++++++ .../myteamspeak/check_native_challenge.py | 89 ++++++++ .../myteamspeak/myteamspeak_server_signin.md | 203 +++++++++++++++++- .../lixko/ts3j/client/ui/ConnectDialog.java | 7 + .../eu/lixko/ts3j/client/ui/MainFrame.java | 20 +- .../eu/lixko/ts3j/client/ui/ServerTab.java | 1 + ts3j | 2 +- 14 files changed, 754 insertions(+), 16 deletions(-) create mode 100644 ts3-client/core/src/main/java/eu/lixko/ts3j/client/myts/MyTeamSpeakIdentity.java create mode 100644 ts3-client/core/src/test/java/eu/lixko/ts3j/client/myts/MyTeamSpeakIdentityTest.java create mode 100644 ts3-client/docs/myteamspeak/MyTsAuthCheck.java create mode 100644 ts3-client/docs/myteamspeak/check_native_challenge.py diff --git a/android/app/src/main/java/eu/lixko/ts3j/client/android/SessionController.kt b/android/app/src/main/java/eu/lixko/ts3j/client/android/SessionController.kt index 06ced19..a191a15 100644 --- a/android/app/src/main/java/eu/lixko/ts3j/client/android/SessionController.kt +++ b/android/app/src/main/java/eu/lixko/ts3j/client/android/SessionController.kt @@ -199,8 +199,11 @@ class SessionController(private val context: Context) { } fun connect(bookmark: Bookmark) { - start { it.start(bookmark.address, bookmark.port, bookmark.nickname.orEmpty(), bookmark.password, - bookmark.identityId, bookmark.channel, bookmark.channelPassword) } + start { + it.conn.setMyTeamSpeakFeatures(bookmark.myTeamSpeakFeatures) + it.start(bookmark.address, bookmark.port, bookmark.nickname.orEmpty(), bookmark.password, + bookmark.identityId, bookmark.channel, bookmark.channelPassword) + } } private fun start(host: String, port: Int, nickname: String, password: String, identityId: String, @@ -210,6 +213,7 @@ class SessionController(private val context: Context) { private fun start(connect: (ServerController) -> Unit) { val server = ServerController(nextId.incrementAndGet(), this) + server.conn.setMyTeamSpeakLogin(myTeamSpeak) sessions.add(server.session) _servers.update { it + server } _current.value = server @@ -452,6 +456,7 @@ class SessionController(private val context: Context) { withContext(Dispatchers.IO) { myTeamSpeak.signIn(email, password) } .also { _myTeamSpeakSignedIn.value = true + _servers.value.forEach { it.conn.updateMyTeamSpeak() } // Shared pictures that could not be had signed out. pictures.retryFailed() } @@ -467,6 +472,7 @@ class SessionController(private val context: Context) { suspend fun signOutMyTeamSpeak() { myTeamSpeak.signOut() _myTeamSpeakSignedIn.value = false + _servers.value.forEach { it.conn.updateMyTeamSpeak() } withContext(Dispatchers.IO) { attachments.close() } } diff --git a/ts3-client/core/src/main/java/eu/lixko/ts3j/client/myts/MyTeamSpeak.java b/ts3-client/core/src/main/java/eu/lixko/ts3j/client/myts/MyTeamSpeak.java index 5f0c25f..2c0e31a 100644 --- a/ts3-client/core/src/main/java/eu/lixko/ts3j/client/myts/MyTeamSpeak.java +++ b/ts3-client/core/src/main/java/eu/lixko/ts3j/client/myts/MyTeamSpeak.java @@ -118,7 +118,25 @@ public final class MyTeamSpeak { } /** A signed-in session: the bearer token later requests carry, and who it belongs to. */ - record Session(String id, AccountInfo info, byte[] keyPackage) { + record Session(String id, AccountInfo info, byte[] keyPackage, byte[] userId, long createdAt, + byte[] publicKey, byte[] encryptedPrivateKey, byte[] publicSignature) { + } + + /** Reads only the server identity; does not download cloud items. */ + MyTeamSpeakIdentity serverIdentity(Credentials credentials) throws IOException, MyTsException { + Session session = signIn(credentials); + byte[] itemKey = null; + try { + if (session.keyPackage == null) throw new MyTsException("The account has no encryption key", 0); + itemKey = MyTsCrypto.unwrapItemKey(credentials.accountKey(), session.keyPackage); + return new MyTeamSpeakIdentity(session.userId, session.createdAt, session.publicKey, + session.encryptedPrivateKey, session.publicSignature, itemKey); + } catch (GeneralSecurityException e) { + throw new MyTsException("Could not unlock the myTeamSpeak server identity", e); + } finally { + if (itemKey != null) java.util.Arrays.fill(itemKey, (byte) 0); + signOut(session.id); + } } /** Signs in; the caller ends the session with {@link #signOut}. */ @@ -129,6 +147,7 @@ public final class MyTeamSpeak { byte[] keyPackage = null; String session = "", username = "", uuid = ""; byte[] userId = null; + byte[] publicKey = null, encryptedPrivateKey = null, publicSignature = null; long createdAt = 0; int error = 0; while (reply.next()) { @@ -142,8 +161,17 @@ public final class MyTeamSpeak { ProtobufReader identity = reply.readMessage(); while (identity.next()) { switch (identity.fieldNumber()) { + case 1 -> publicKey = identity.readBytes(); + case 2 -> { + ProtobufReader key = identity.readMessage(); + while (key.next()) { + if (key.fieldNumber() == 1) encryptedPrivateKey = key.readBytes(); + else key.skip(); + } + } case 3 -> createdAt = identity.readVarint(); case 4 -> userId = identity.readBytes(); + case 5 -> publicSignature = identity.readBytes(); default -> identity.skip(); } } @@ -152,7 +180,8 @@ public final class MyTeamSpeak { } } if (error != LOGIN_OK) throw loginError(error); - return new Session(session, AccountInfo.of(username, uuid, userId, createdAt), keyPackage); + return new Session(session, AccountInfo.of(username, uuid, userId, createdAt), keyPackage, + userId, createdAt, publicKey, encryptedPrivateKey, publicSignature); } private List pull(String session, byte[] itemKey) throws IOException, MyTsException { diff --git a/ts3-client/core/src/main/java/eu/lixko/ts3j/client/myts/MyTeamSpeakIdentity.java b/ts3-client/core/src/main/java/eu/lixko/ts3j/client/myts/MyTeamSpeakIdentity.java new file mode 100644 index 0000000..feae722 --- /dev/null +++ b/ts3-client/core/src/main/java/eu/lixko/ts3j/client/myts/MyTeamSpeakIdentity.java @@ -0,0 +1,88 @@ +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 java.nio.charset.StandardCharsets; +import java.security.GeneralSecurityException; +import java.security.MessageDigest; +import java.util.Arrays; +import java.util.Base64; +import java.util.LinkedHashMap; +import java.util.Map; + +/** Account identity used to authenticate to voice servers. Never persisted or logged. */ +public final class MyTeamSpeakIdentity implements AutoCloseable { + private final byte[] scalar; + private final byte[] publicKey; + private final Map parameters; + private boolean closed; + + MyTeamSpeakIdentity(byte[] id, long created, byte[] publicKey, byte[] encryptedKey, + byte[] certificate, byte[] itemKey) throws GeneralSecurityException { + if (id == null || id.length != 33 || publicKey == null || publicKey.length != 32 + || encryptedKey == null || encryptedKey.length != 112 + || certificate == null || certificate.length != 176) + throw new GeneralSecurityException("Incomplete myTeamSpeak server identity"); + this.publicKey = publicKey.clone(); + scalar = MyTsCrypto.decryptItem(encryptedKey, itemKey); + if (!MessageDigest.isEqual(point(scalar), publicKey)) { + Arrays.fill(scalar, (byte) 0); + throw new GeneralSecurityException("myTeamSpeak private key does not match its public key"); + } + Base64.Encoder b64 = Base64.getEncoder(); + parameters = new LinkedHashMap<>(); + parameters.put("myTeamspeakId", b64.encodeToString(id)); + parameters.put("acTime", Long.toUnsignedString(Long.reverseBytes(created))); + parameters.put("userPubKey", b64.encodeToString(publicKey)); + parameters.put("pubSign", b64.encodeToString(Arrays.copyOf(certificate, 64))); + parameters.put("pubSignCert", b64.encodeToString(Arrays.copyOfRange(certificate, 64, 176))); + } + + /** Fresh signature for a handshake; closing the identity disables subsequent announcements. */ + public synchronized Map authenticate(byte[] challenge) { + if (closed) return Map.of(); + if (challenge.length != 32) throw new IllegalArgumentException("Expected a 32-byte connection challenge"); + byte[] message = Arrays.copyOf(challenge, 45); + System.arraycopy("MyTeamSpeakID".getBytes(StandardCharsets.US_ASCII), 0, message, 32, 13); + byte[] r = null, k = null, s = new byte[32]; + try { + MessageDigest hash = MessageDigest.getInstance("SHA-512"); + hash.update(scalar); + r = hash.digest(message); + ScalarOperations.sc_reduce(r); + byte[] R = point(r); + hash.update(R); + hash.update(publicKey); + k = hash.digest(message); + ScalarOperations.sc_reduce(k); + ScalarOperations.sc_muladd(s, k, scalar, r); + byte[] signature = Arrays.copyOf(R, 64); + System.arraycopy(s, 0, signature, 32, 32); + Map result = new LinkedHashMap<>(parameters); + result.put("authSign", Base64.getEncoder().encodeToString(signature)); + return result; + } catch (GeneralSecurityException e) { + throw new IllegalStateException("SHA-512 unavailable", e); + } finally { + if (r != null) Arrays.fill(r, (byte) 0); + if (k != null) Arrays.fill(k, (byte) 0); + Arrays.fill(s, (byte) 0); + } + } + + 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; + } + + @Override + public synchronized void close() { + closed = true; + Arrays.fill(scalar, (byte) 0); + } +} diff --git a/ts3-client/core/src/main/java/eu/lixko/ts3j/client/myts/MyTeamSpeakLogin.java b/ts3-client/core/src/main/java/eu/lixko/ts3j/client/myts/MyTeamSpeakLogin.java index e5a914e..3c7a7da 100644 --- a/ts3-client/core/src/main/java/eu/lixko/ts3j/client/myts/MyTeamSpeakLogin.java +++ b/ts3-client/core/src/main/java/eu/lixko/ts3j/client/myts/MyTeamSpeakLogin.java @@ -24,6 +24,14 @@ public final class MyTeamSpeakLogin { private final MyTeamSpeak service; private MyTeamSpeak.Credentials credentials; private String username = ""; + private MyTeamSpeakIdentity serverIdentity; + private final Object identityLoadLock = new Object(); + private long revision; + + /** Changes whenever the signed-in account changes, including sign-out. */ + public synchronized long revision() { + return revision; + } MyTeamSpeakLogin(File file, MyTeamSpeak service) { this.file = file; @@ -57,7 +65,10 @@ public final class MyTeamSpeakLogin { MyTeamSpeak.Credentials fresh = MyTeamSpeak.Credentials.derive(email.trim(), password); MyTeamSpeak.Account account = service.download(fresh); synchronized (this) { + if (serverIdentity != null) serverIdentity.close(); + serverIdentity = null; credentials = fresh; + revision++; username = account.username(); write(); } @@ -104,8 +115,40 @@ public final class MyTeamSpeakLogin { return service; } + /** Blocking account request on first use; cached in memory until sign-out. */ + public MyTeamSpeakIdentity serverIdentity() throws IOException, MyTsException { + synchronized (identityLoadLock) { + MyTeamSpeak.Credentials current; + synchronized (this) { + if (credentials == null) return null; + if (serverIdentity != null) return serverIdentity; + current = credentials; + } + MyTeamSpeakIdentity loaded; + try { + loaded = service.serverIdentity(current); + } catch (MyTsException e) { + synchronized (this) { + if (e.credentialsRejected() && credentials == current) signOut(); + } + throw e; + } + synchronized (this) { + if (credentials != current) { + loaded.close(); + return null; + } + serverIdentity = loaded; + return loaded; + } + } + } + public synchronized void signOut() { + if (serverIdentity != null) serverIdentity.close(); + serverIdentity = null; credentials = null; + revision++; username = ""; //noinspection ResultOfMethodCallIgnored file.delete(); diff --git a/ts3-client/core/src/main/java/eu/lixko/ts3j/client/net/TeamspeakConnection.java b/ts3-client/core/src/main/java/eu/lixko/ts3j/client/net/TeamspeakConnection.java index 46021bd..2bb1833 100644 --- a/ts3-client/core/src/main/java/eu/lixko/ts3j/client/net/TeamspeakConnection.java +++ b/ts3-client/core/src/main/java/eu/lixko/ts3j/client/net/TeamspeakConnection.java @@ -20,6 +20,8 @@ import eu.lixko.ts3j.client.chatlog.ChatLogStore; import eu.lixko.ts3j.client.config.Settings; import eu.lixko.ts3j.client.contacts.Contact; import eu.lixko.ts3j.client.contacts.ContactStore; +import eu.lixko.ts3j.client.myts.MyTeamSpeakIdentity; +import eu.lixko.ts3j.client.myts.MyTeamSpeakLogin; import eu.lixko.ts3j.client.net.avatar.Avatar; import eu.lixko.ts3j.client.net.avatar.AvatarNaming; import eu.lixko.ts3j.client.net.avatar.AvatarRepository; @@ -168,6 +170,51 @@ public final class TeamspeakConnection implements TS3Listener { private volatile long lastMutedTalkNanos; /** The server's error id for why the last connect was refused; 0 when it was not. */ private volatile int connectErrorId; + private volatile MyTeamSpeakLogin myTeamSpeak; + private volatile boolean myTeamSpeakFeatures = true; + private final Object myTeamSpeakUpdateLock = new Object(); + + public void setMyTeamSpeakLogin(MyTeamSpeakLogin login) { + myTeamSpeak = login; + } + + public void setMyTeamSpeakFeatures(boolean enabled) { + myTeamSpeakFeatures = enabled; + } + + public boolean isMyTeamSpeakFeaturesEnabled() { + return myTeamSpeakFeatures; + } + + /** Refreshes account authentication after sign-in/out while connected. */ + public void updateMyTeamSpeak() { + LocalTeamspeakClientSocket socket = client; + ExecutorService executor = actions; + if (!connected || socket == null || executor == null) return; + try { + executor.execute(() -> { + synchronized (myTeamSpeakUpdateLock) { + try { + var login = myTeamSpeak; + var account = myTeamSpeakFeatures && login != null ? login.serverIdentity() : null; + if (client != socket || !connected) return; + socket.setMyTeamSpeakAuthenticator(account == null ? null : account::authenticate); + SingleCommand command = new SingleCommand("updatemytsid", ProtocolRole.CLIENT); + socket.addMyTeamSpeakParameters(command); + if (command.toMap().isEmpty()) { + for (String name : new String[] {"myTeamspeakId", "acTime", "userPubKey", "pubSign", "pubSignCert", "authSign"}) + command.add(new CommandSingleParameter(name, "")); + } + socket.executeCommand(command).complete(); + } catch (Exception e) { + ui.onError("Could not update myTeamSpeak identity: " + messageChain(e)); + } + } + }); + } catch (RejectedExecutionException ignored) { + // The connection closed while scheduling the update. + } + } public TeamspeakConnection(Settings settings, AudioBackend audio, ConnectionListener ui, SoundNotifier sounds, ContactStore contacts) { @@ -289,6 +336,16 @@ public final class TeamspeakConnection implements TS3Listener { connected = false; safeCleanup(); try { + var login = myTeamSpeak; + long loginRevision = login == null ? 0 : login.revision(); + MyTeamSpeakIdentity account = null; + try { + if (myTeamSpeakFeatures && login != null) account = login.serverIdentity(); + } catch (Exception e) { + // The server connection does not depend on myTeamSpeak being reachable. + ui.onError("Connecting without myTeamSpeak identity: " + messageChain(e)); + } + if (connectAttempt != attempt) return; identity = withIdentity; serverHost = address; serverPort = port; @@ -321,6 +378,7 @@ public final class TeamspeakConnection implements TS3Listener { microphone.setMutedTalkListener(this::onTalkingWhileMuted); client = new LocalTeamspeakClientSocket(); + client.setMyTeamSpeakAuthenticator(account == null ? null : account::authenticate); eventExecutor = Executors.newSingleThreadExecutor(r -> { Thread t = new Thread(r, "ts3j-events"); t.setDaemon(true); @@ -374,6 +432,7 @@ public final class TeamspeakConnection implements TS3Listener { icons.retryFailed(); avatars.retryFailed(); connected = true; + if (login != null && login.revision() != loginRevision) updateMyTeamSpeak(); connectedAtMs = System.currentTimeMillis(); leaving = false; disconnectAnnounced = false; diff --git a/ts3-client/core/src/main/java/eu/lixko/ts3j/client/session/ServerSession.java b/ts3-client/core/src/main/java/eu/lixko/ts3j/client/session/ServerSession.java index 8770da3..6195089 100644 --- a/ts3-client/core/src/main/java/eu/lixko/ts3j/client/session/ServerSession.java +++ b/ts3-client/core/src/main/java/eu/lixko/ts3j/client/session/ServerSession.java @@ -152,6 +152,7 @@ public final class ServerSession { if (target == null) return null; Bookmark b = new Bookmark(title, target.address(), target.port(), target.nickname(), target.password()); b.identityId = identityId; + b.myTeamSpeakFeatures = conn.isMyTeamSpeakFeaturesEnabled(); b.channel = channel == null ? "" : channel; return b; } diff --git a/ts3-client/core/src/test/java/eu/lixko/ts3j/client/myts/MyTeamSpeakIdentityTest.java b/ts3-client/core/src/test/java/eu/lixko/ts3j/client/myts/MyTeamSpeakIdentityTest.java new file mode 100644 index 0000000..0d01f0d --- /dev/null +++ b/ts3-client/core/src/test/java/eu/lixko/ts3j/client/myts/MyTeamSpeakIdentityTest.java @@ -0,0 +1,134 @@ +package eu.lixko.ts3j.client.myts; + +import com.github.manevolent.ts3j.command.SingleCommand; +import com.github.manevolent.ts3j.protocol.ProtocolRole; +import com.github.manevolent.ts3j.protocol.socket.client.LocalTeamspeakClientSocket; +import com.github.manevolent.ts3j.util.Ts3Crypt; +import eu.lixko.ts3j.client.proto.ProtobufWriter; +import org.bouncycastle.math.ec.rfc8032.Ed25519; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import java.io.File; + +import java.security.GeneralSecurityException; +import java.util.Arrays; +import java.util.Base64; +import java.util.HexFormat; +import java.util.List; +import java.util.Map; +import java.util.ArrayList; + +import static org.junit.jupiter.api.Assertions.*; + +class MyTeamSpeakIdentityTest { + private static final byte[] PUBLIC = HexFormat.of().parseHex( + "4ffcab6e0aeefbcbc0b4bbbe25b7e36c171016f73a65c3a71dd4bb5a9f5dab8e"); + private static final byte[] ENCRYPTED = Base64.getDecoder().decode( + "oMyzSUejPJPlg40t4mlEFGYFDYJdgKGuLDhWAhfD2VXnlk2fwf+lf7Wi5RMv2zsrk78mBCiQ9TSwQjFaIs7JrMUItZrc6kTsxZwWTPOetTpxebk7wMShPgPyOMqN+Nr68shjWCtXGH8G4E/kVtxIzw=="); + private static final byte[] ID = Base64.getDecoder().decode("ASCwXERY29umCjNyMewplck8cVzzMx/Xsh8vab8V7grN"); + private static final byte[] CERT = new byte[176]; + static { + for (int i = 0; i < CERT.length; i++) CERT[i] = (byte) i; + } + + private static MyTeamSpeakIdentity identity() throws Exception { + return new MyTeamSpeakIdentity(ID, 1790376353L, PUBLIC, ENCRYPTED, CERT, MyTsCryptoTest.ITEM_KEY); + } + + @Test + void socketSignsEachHandshakeAndOmitsIdentityWhenDisabled() throws Exception { + LocalTeamspeakClientSocket socket = new LocalTeamspeakClientSocket(); // No transport is opened. + try (MyTeamSpeakIdentity identity = identity()) { + byte[] iv = new byte[64]; + for (int i = 0; i < iv.length; i++) iv[i] = (byte) i; + socket.setSecureParameters(new Ts3Crypt.SecureChannelParameters(new byte[8], iv)); + SingleCommand anonymous = new SingleCommand("clientinit", ProtocolRole.CLIENT); + socket.addMyTeamSpeakParameters(anonymous); + assertTrue(anonymous.toMap().isEmpty()); + + socket.setMyTeamSpeakAuthenticator(identity::authenticate); + SingleCommand command = new SingleCommand("clientinit", ProtocolRole.CLIENT); + socket.addMyTeamSpeakParameters(command); + Map p = command.toMap(); + assertEquals(6, p.size()); + assertEquals("11671560475690139648", p.get("acTime")); + assertArrayEquals(ID, Base64.getDecoder().decode(p.get("myTeamspeakId"))); + assertArrayEquals(Arrays.copyOf(CERT, 64), Base64.getDecoder().decode(p.get("pubSign"))); + assertArrayEquals(Arrays.copyOfRange(CERT, 64, 176), Base64.getDecoder().decode(p.get("pubSignCert"))); + byte[] message = HexFormat.of().parseHex( + "d178cabdc4faa5bb033b175d2f691564975d38b48994ab8eaf93ee88f1bb73f8" + + "4d795465616d537065616b4944"); + byte[] signature = Base64.getDecoder().decode(p.get("authSign")); + assertTrue(Ed25519.verify(signature, 0, PUBLIC, 0, message, 0, message.length)); + iv[0] ^= 1; + socket.setSecureParameters(new Ts3Crypt.SecureChannelParameters(new byte[8], iv)); + SingleCommand reconnect = new SingleCommand("clientinit", ProtocolRole.CLIENT); + socket.addMyTeamSpeakParameters(reconnect); + assertNotEquals(p.get("authSign"), reconnect.toMap().get("authSign")); + identity.close(); + SingleCommand signedOut = new SingleCommand("clientinit", ProtocolRole.CLIENT); + socket.addMyTeamSpeakParameters(signedOut); + assertTrue(signedOut.toMap().isEmpty()); + } + } + + @Test + void rejectsCorruptOrMismatchedPrivateKeys() { + byte[] broken = ENCRYPTED.clone(); + broken[20] ^= 1; + assertThrows(GeneralSecurityException.class, + () -> new MyTeamSpeakIdentity(ID, 0, PUBLIC, broken, CERT, MyTsCryptoTest.ITEM_KEY)); + assertThrows(GeneralSecurityException.class, + () -> new MyTeamSpeakIdentity(ID, 0, new byte[32], ENCRYPTED, CERT, MyTsCryptoTest.ITEM_KEY)); + assertThrows(GeneralSecurityException.class, + () -> new MyTeamSpeakIdentity(ID, 0, PUBLIC, null, CERT, MyTsCryptoTest.ITEM_KEY)); + } + + @Test + void parsesLoginIdentityAndEndsSessionWithoutDownloadingItems() throws Exception { + List calls = new ArrayList<>(); + MyTeamSpeak service = new MyTeamSpeak((endpoint, method, request) -> { + calls.add(method); + if (!method.equals("login")) return new byte[0]; + return new ProtobufWriter().varint(5, 200).string(2, "test-session") + .bytes(1, MyTsCryptoTest.KEY_PACKAGE) + .message(9, new ProtobufWriter().bytes(1, PUBLIC) + .message(2, new ProtobufWriter().bytes(1, ENCRYPTED)) + .varint(3, 1790376353L).bytes(4, ID).bytes(5, CERT)).toByteArray(); + }); + try (MyTeamSpeakIdentity identity = service.serverIdentity(MyTeamSpeakTest.credentials(MyTsCryptoTest.PASSWORD))) { + assertEquals(6, identity.authenticate(new byte[32]).size()); + } + assertEquals(List.of("login", "deleteSession"), calls); + } + + @Test + void savedLoginCachesIdentityAndSignOutRevokesIt(@TempDir File dir) throws Exception { + MyTeamSpeakTest.ReplayServer replay = new MyTeamSpeakTest.ReplayServer(); + MyTeamSpeak service = new MyTeamSpeak((endpoint, method, request) -> { + byte[] reply = replay.call(endpoint, method, request); + if (!method.equals("login")) return reply; + byte[] identity = new ProtobufWriter().message(9, new ProtobufWriter().bytes(1, PUBLIC) + .message(2, new ProtobufWriter().bytes(1, ENCRYPTED)) + .varint(3, 1790376353L).bytes(4, ID).bytes(5, CERT)).toByteArray(); + byte[] combined = Arrays.copyOf(reply, reply.length + identity.length); + System.arraycopy(identity, 0, combined, reply.length, identity.length); + return combined; + }); + File file = new File(dir, "account.properties"); + MyTeamSpeakLogin login = new MyTeamSpeakLogin(file, service); + assertNull(login.serverIdentity()); + login.signIn(MyTsCryptoTest.EMAIL, MyTsCryptoTest.PASSWORD); + login = new MyTeamSpeakLogin(file, service); // Restart with only the saved token/key. + MyTeamSpeakIdentity identity = login.serverIdentity(); + int calls = replay.calls.size(); + assertSame(identity, login.serverIdentity()); + assertEquals(calls, replay.calls.size()); + assertEquals(6, identity.authenticate(new byte[32]).size()); + login.signOut(); + assertNull(login.serverIdentity()); + assertTrue(identity.authenticate(new byte[32]).isEmpty()); + assertFalse(file.exists()); + } +} diff --git a/ts3-client/docs/myteamspeak/MyTsAuthCheck.java b/ts3-client/docs/myteamspeak/MyTsAuthCheck.java new file mode 100644 index 0000000..badd9b3 --- /dev/null +++ b/ts3-client/docs/myteamspeak/MyTsAuthCheck.java @@ -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); + } +} diff --git a/ts3-client/docs/myteamspeak/check_native_challenge.py b/ts3-client/docs/myteamspeak/check_native_challenge.py new file mode 100644 index 0000000..6003eb5 --- /dev/null +++ b/ts3-client/docs/myteamspeak/check_native_challenge.py @@ -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("= 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]) diff --git a/ts3-client/docs/myteamspeak/myteamspeak_server_signin.md b/ts3-client/docs/myteamspeak/myteamspeak_server_signin.md index 011148f..343314b 100644 --- a/ts3-client/docs/myteamspeak/myteamspeak_server_signin.md +++ b/ts3-client/docs/myteamspeak/myteamspeak_server_signin.md @@ -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=` - 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 diff --git a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ConnectDialog.java b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ConnectDialog.java index 82f1d42..a25a93a 100644 --- a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ConnectDialog.java +++ b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ConnectDialog.java @@ -26,6 +26,8 @@ public final class ConnectDialog extends JDialog { private final JTextField nickField; private final JPasswordField passwordField; private final IdentityChooser identityChooser; + private final javax.swing.JCheckBox myTeamSpeakFeatures = + new javax.swing.JCheckBox("Enable myTeamSpeak features", true); private boolean confirmed; @@ -62,6 +64,7 @@ public final class ConnectDialog extends JDialog { add(form, c, row++, "Nickname:", nickField); add(form, c, row++, "Password (optional):", passwordField); add(form, c, row++, "Identity:", identityChooser); + add(form, c, row++, "", myTeamSpeakFeatures); JPanel buttons = new JPanel(new BorderLayout()); JPanel right = new JPanel(); @@ -102,6 +105,10 @@ public final class ConnectDialog extends JDialog { return confirmed; } + public boolean isMyTeamSpeakFeaturesEnabled() { + return myTeamSpeakFeatures.isSelected(); + } + public String getAddress() { return addressField.getText().trim(); } diff --git a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/MainFrame.java b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/MainFrame.java index 7f57a82..f4470fa 100644 --- a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/MainFrame.java +++ b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/MainFrame.java @@ -790,7 +790,7 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener { dlg.setVisible(true); if (!dlg.isConfirmed()) return; startConnection(dlg.getAddress(), dlg.getPort(), dlg.getNickname(), dlg.getPassword(), - dlg.getIdentityId(), "", ""); + dlg.getIdentityId(), "", "", false, dlg.isMyTeamSpeakFeaturesEnabled()); } /** @@ -811,12 +811,18 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener { */ private void startConnection(String address, int port, String nickname, String password, String identityId, String channel, String channelPassword, boolean replaceCurrent) { + startConnection(address, port, nickname, password, identityId, channel, channelPassword, replaceCurrent, true); + } + + private void startConnection(String address, int port, String nickname, String password, String identityId, + String channel, String channelPassword, boolean replaceCurrent, boolean mytsFeatures) { settings.lastAddress = address + ":" + port; if (!nickname.isBlank()) settings.nickname = nickname; settings.serverPassword = password; settings.save(); ServerTab tab = (replaceCurrent && selected != null) ? selected : tabForNewConnection(); + tab.session().connection().setMyTeamSpeakFeatures(mytsFeatures); // The first connection to come up takes the microphone; later ones are muted // until the user activates them. if (sessions.microphoneOwner() == null) sessions.giveMicrophoneTo(tab.session()); @@ -846,13 +852,14 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener { } } ServerTab tab = tabForNewConnection(); + tab.session().connection().setMyTeamSpeakFeatures(true); if (sessions.microphoneOwner() == null) sessions.giveMicrophoneTo(tab.session()); tab.session().open(link, ""); } /** Connects on the current tab, leaving whatever server it is on. */ private void connectToBookmark(Bookmark b) { - startConnection(b.address, b.port, b.nickname == null ? "" : b.nickname, b.password, b.identityId, b.channel, b.channelPassword, true); + startConnection(b.address, b.port, b.nickname == null ? "" : b.nickname, b.password, b.identityId, b.channel, b.channelPassword, true, b.myTeamSpeakFeatures); } private void addCurrentServerBookmark() { @@ -1035,7 +1042,10 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener { /** Signed in to or out of myTeamSpeak: sharing in chat follows. */ private void myTeamSpeakChanged() { boolean signedIn = myTeamSpeak.isSignedIn(); - for (ServerTab tab : tabs) tab.chat().setSharingAvailable(signedIn); + for (ServerTab tab : tabs) { + tab.chat().setSharingAvailable(signedIn); + tab.session().connection().updateMyTeamSpeak(); + } if (signedIn) { pictures.retryFailed(); } else { @@ -1047,6 +1057,10 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener { return attachments; } + MyTeamSpeakLogin myTeamSpeakLogin() { + return myTeamSpeak; + } + /** Whether files can be shared in chat: that needs a myTeamSpeak account. */ boolean canShareFiles() { return myTeamSpeak.isSignedIn(); diff --git a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerTab.java b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerTab.java index 567dda1..c3b96bb 100644 --- a/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerTab.java +++ b/ts3-client/swing/src/main/java/eu/lixko/ts3j/client/ui/ServerTab.java @@ -78,6 +78,7 @@ final class ServerTab { ServerTabConnectionEvents events = new ServerTabConnectionEvents(host, this, settings); this.session = new ServerSession(settings, identities, audio, sounds, contacts, events); this.conn = session.connection(); + this.conn.setMyTeamSpeakLogin(host.myTeamSpeakLogin()); this.groupIcons = new GroupIcons(conn.getIcons()); this.chatPanel = new ChatPanel(host.chatZoom(), settings, pictures, conn::serverUniqueId); this.treeActions = new ServerTabTreeActions(host, this, conn, chatPanel, infoPanel, groupIcons); diff --git a/ts3j b/ts3j index 1430782..0549b6b 160000 --- a/ts3j +++ b/ts3j @@ -1 +1 @@ -Subproject commit 1430782e2ae5443317af8076ca31e28507b5bf11 +Subproject commit 0549b6bf028da44b8e316b5835652b4121dcc143