From 567ee472d6593290651953f4ce7f7a50cf4aff6b Mon Sep 17 00:00:00 2001 From: Manevolent Date: Wed, 25 Jul 2018 12:20:24 -0400 Subject: [PATCH] Trying more things. I think clientek is being rejected. --- .../protocol/client/LocalTeamspeakClient.java | 15 +++++++++- .../ts3j/protocol/header/PacketHeader.java | 9 ++++++ .../client/LocalClientHandlerConnecting.java | 29 +++++++++++++++---- .../transformation/PacketTransformation.java | 12 ++++++-- 4 files changed, 56 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/github/manevolent/ts3j/protocol/client/LocalTeamspeakClient.java b/src/main/java/com/github/manevolent/ts3j/protocol/client/LocalTeamspeakClient.java index dd2da4a..ff9f0db 100644 --- a/src/main/java/com/github/manevolent/ts3j/protocol/client/LocalTeamspeakClient.java +++ b/src/main/java/com/github/manevolent/ts3j/protocol/client/LocalTeamspeakClient.java @@ -7,12 +7,15 @@ import com.github.manevolent.ts3j.protocol.NetworkPacket; import com.github.manevolent.ts3j.protocol.ProtocolRole; import com.github.manevolent.ts3j.protocol.SocketRole; import com.github.manevolent.ts3j.protocol.header.ClientPacketHeader; +import com.github.manevolent.ts3j.protocol.header.HeaderFlag; import com.github.manevolent.ts3j.protocol.packet.Packet6Ack; import com.github.manevolent.ts3j.protocol.packet.PacketType; import com.github.manevolent.ts3j.protocol.packet.channel.PacketChannel; import com.github.manevolent.ts3j.protocol.packet.handler.client.LocalClientHandler; +import com.github.manevolent.ts3j.protocol.packet.transformation.PacketTransformation; import com.github.manevolent.ts3j.protocol.socket.LocalTeamspeakSocket; import com.github.manevolent.ts3j.protocol.packet.Packet; +import com.github.manevolent.ts3j.util.Ts3Crypt; import com.github.manevolent.ts3j.util.Ts3Logging; import java.io.IOException; @@ -72,6 +75,10 @@ public class LocalTeamspeakClient extends LocalEndpoint implements TeamspeakClie return clientOptions; } + public void setSecureParameters(Ts3Crypt.SecureChannelParameters parameters) { + getSocket().setPacketTransformation(new PacketTransformation(parameters.getIvStruct())); + } + /** * Sends a command to the remote server. * @param command Command to send. @@ -108,6 +115,7 @@ public class LocalTeamspeakClient extends LocalEndpoint implements TeamspeakClie * @param packet Packet to send * @throws IOException */ + int z = 0; public void send(Packet packet) throws IOException { // Construct header ClientPacketHeader header = new ClientPacketHeader(); @@ -117,10 +125,15 @@ public class LocalTeamspeakClient extends LocalEndpoint implements TeamspeakClie packet.setHeaderValues(header); + if (connectionState == ClientConnectionState.CONNECTING) { + header.setPacketId(z++); + header.setPacketFlag(HeaderFlag.NEW_PROTOCOL, true); + } + getSocket().send(header, packet); } - private void setConnectionState(ClientConnectionState state) { + public void setConnectionState(ClientConnectionState state) { synchronized (connectionStateLock) { if (state != this.connectionState) { Ts3Logging.debug("State changing: " + state.name()); diff --git a/src/main/java/com/github/manevolent/ts3j/protocol/header/PacketHeader.java b/src/main/java/com/github/manevolent/ts3j/protocol/header/PacketHeader.java index 43f5a00..491fd9e 100644 --- a/src/main/java/com/github/manevolent/ts3j/protocol/header/PacketHeader.java +++ b/src/main/java/com/github/manevolent/ts3j/protocol/header/PacketHeader.java @@ -10,6 +10,7 @@ public abstract class PacketHeader { private final ProtocolRole role; //private final byte[] DEFAULT_MAC = new byte[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}; // 8x0's + private int packetGeneration; private byte[] mac = new byte[8]; // 8 bytes private int packetId = 0; private PacketType type; @@ -100,4 +101,12 @@ public abstract class PacketHeader { public ProtocolRole getRole() { return role; } + + public int getGeneration() { + return packetGeneration; + } + + public void setGeneration(int packetGeneration) { + this.packetGeneration = packetGeneration; + } } diff --git a/src/main/java/com/github/manevolent/ts3j/protocol/packet/handler/client/LocalClientHandlerConnecting.java b/src/main/java/com/github/manevolent/ts3j/protocol/packet/handler/client/LocalClientHandlerConnecting.java index cef2880..d83acb3 100644 --- a/src/main/java/com/github/manevolent/ts3j/protocol/packet/handler/client/LocalClientHandlerConnecting.java +++ b/src/main/java/com/github/manevolent/ts3j/protocol/packet/handler/client/LocalClientHandlerConnecting.java @@ -5,6 +5,7 @@ import com.github.manevolent.ts3j.command.part.CommandSingleParameter; import com.github.manevolent.ts3j.license.License; import com.github.manevolent.ts3j.protocol.NetworkPacket; import com.github.manevolent.ts3j.protocol.ProtocolRole; +import com.github.manevolent.ts3j.protocol.client.ClientConnectionState; import com.github.manevolent.ts3j.protocol.client.LocalTeamspeakClient; import com.github.manevolent.ts3j.protocol.packet.Packet2Command; import com.github.manevolent.ts3j.protocol.packet.Packet8Init1; @@ -200,12 +201,30 @@ public class LocalClientHandlerConnecting extends LocalClientHandler { ); getClient().send(clientek); - Ts3Crypt.cryptoInit2(license, alphaBytes, omega, proof, beta, keyPair.getValue()); - - // send client init... - - // DONE! + Ts3Crypt.SecureChannelParameters secureChannelParameters = + Ts3Crypt.cryptoInit2(license, alphaBytes, omega, proof, beta, keyPair.getValue()); + Packet2Command clientinit = new Packet2Command(ProtocolRole.CLIENT); + clientinit.setText( + new SimpleCommand( + "clientinit", ProtocolRole.CLIENT, + new CommandSingleParameter("client_nickname", "test"), + new CommandSingleParameter("client_version", "3.0.19.3"), + new CommandSingleParameter("client_platform", "Windows"), + new CommandSingleParameter("client_version_sign", "a1OYzvM18mrmfUQBUgxYBxYz2DUU6y5k3/mEL6FurzU0y97Bd1FL7+PRpcHyPkg4R+kKAFZ1nhyzbgkGphDWDg=="), + new CommandSingleParameter("client_input_hardware", "true"), + new CommandSingleParameter("client_output_hardware", "false"), + new CommandSingleParameter("client_default_channel", ""), + new CommandSingleParameter("client_default_channel_password", ""), + new CommandSingleParameter("client_server_password", ""), + new CommandSingleParameter("client_nickname_phonetic", "test"), + new CommandSingleParameter("client_meta_data", ""), + new CommandSingleParameter("client_default_token", ""), + new CommandSingleParameter("client_key_offset", Long.toString(getClient().getLocalIdentity().getKeyOffset())), + new CommandSingleParameter("hwid", "87056c6e1268aaf5055abf8256415e0e,408978b6d98810cc03f0aa16a4c75600") + ).build() + ); + getClient().send(clientinit); } } } diff --git a/src/main/java/com/github/manevolent/ts3j/protocol/packet/transformation/PacketTransformation.java b/src/main/java/com/github/manevolent/ts3j/protocol/packet/transformation/PacketTransformation.java index 08f4b46..1dccad8 100644 --- a/src/main/java/com/github/manevolent/ts3j/protocol/packet/transformation/PacketTransformation.java +++ b/src/main/java/com/github/manevolent/ts3j/protocol/packet/transformation/PacketTransformation.java @@ -45,7 +45,7 @@ public class PacketTransformation { temporaryByteBuffer.put((byte) (header.getRole() == ProtocolRole.SERVER ? 0x30 : 0x31)); temporaryByteBuffer.put((byte) (header.getType().getIndex() & 0xFF)); - temporaryByteBuffer.put((byte) 0); // TODO generation + temporaryByteBuffer.put((byte) (header.getGeneration() & 0xFF)); if (key.length == 20) { //temporary[6 - 26] = SIV[0 - 20] @@ -76,7 +76,11 @@ public class PacketTransformation { Pair parameters = computeParameters(packet.getHeader()); // Write header (this is temporary) - ByteBuffer headerBuffer = packet.writeHeader(ByteBuffer.allocate(packet.getHeader().getSize())); + ByteBuffer headerBuffer = packet.writeHeader( + ByteBuffer + .allocate(packet.getHeader().getSize()) + .order(ByteOrder.BIG_ENDIAN) + ); // Get the header without a MAC for the associated text field byte[] headerWithoutMac = new byte[packet.getHeader().getSize() - MAC_LEN]; @@ -90,7 +94,7 @@ public class PacketTransformation { ); int dataLen = packet.getPacket().getSize(); - ByteBuffer packetBuffer = packet.writeBody(ByteBuffer.allocate(dataLen)); + ByteBuffer packetBuffer = packet.writeBody(ByteBuffer.allocate(dataLen).order(ByteOrder.BIG_ENDIAN)); byte[] result; int len; @@ -116,6 +120,8 @@ public class PacketTransformation { // Rest of header outputBuffer.put(headerWithoutMac); + Ts3Logging.debug("WRITE HEADER: " + Ts3Logging.getHex(outputBuffer.array(), headerBuffer.limit())); + // Encrypted body outputBuffer.put(result, 0, len - MAC_LEN);