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>
81 lines
3.9 KiB
Java
81 lines
3.9 KiB
Java
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);
|
|
}
|
|
}
|