Compare commits
2
Commits
1430782e2a
...
004aa41732
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
004aa41732 | ||
|
|
0549b6bf02 |
+16
-11
@@ -159,16 +159,7 @@ public class LocalClientHandlerConnecting extends LocalClientHandler {
|
|||||||
BigInteger x = new BigInteger(1, serverReplyStep3.getX());
|
BigInteger x = new BigInteger(1, serverReplyStep3.getX());
|
||||||
BigInteger n = new BigInteger(1, serverReplyStep3.getN());
|
BigInteger n = new BigInteger(1, serverReplyStep3.getN());
|
||||||
|
|
||||||
byte[] y = new byte[64];
|
byte[] y = unsigned64(x.modPow(BigInteger.valueOf(2L).pow(serverReplyStep3.getLevel()), n));
|
||||||
|
|
||||||
byte[] solution =
|
|
||||||
x.modPow(BigInteger.valueOf(2L).pow(serverReplyStep3.getLevel()), n).toByteArray();
|
|
||||||
|
|
||||||
System.arraycopy(
|
|
||||||
solution, Math.abs(solution.length - 64),
|
|
||||||
y, solution.length < 64 ? 64 - solution.length : 0,
|
|
||||||
solution.length < 64 ? solution.length : 64
|
|
||||||
);
|
|
||||||
|
|
||||||
// Build response
|
// Build response
|
||||||
PacketBody8Init1.Step4 step4 = new PacketBody8Init1.Step4();
|
PacketBody8Init1.Step4 step4 = new PacketBody8Init1.Step4();
|
||||||
@@ -355,8 +346,22 @@ public class LocalClientHandlerConnecting extends LocalClientHandler {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
Ts3Debugging.debug(clientinit.build());
|
getClient().addMyTeamSpeakParameters(clientinit);
|
||||||
|
Ts3Debugging.debug("Sending clientinit");
|
||||||
|
|
||||||
getClient().writePacket(new PacketBody2Command(ProtocolRole.CLIENT, clientinit));
|
getClient().writePacket(new PacketBody2Command(ProtocolRole.CLIENT, clientinit));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The puzzle's answer as 64 unsigned big-endian bytes. {@link BigInteger#toByteArray()}
|
||||||
|
* adds a sign byte when the top bit is set and drops leading zero bytes, so it can be
|
||||||
|
* 65 bytes or fewer than 64.
|
||||||
|
*/
|
||||||
|
static byte[] unsigned64(BigInteger value) {
|
||||||
|
byte[] bytes = value.toByteArray();
|
||||||
|
byte[] y = new byte[64];
|
||||||
|
int length = Math.min(bytes.length, 64);
|
||||||
|
System.arraycopy(bytes, bytes.length - length, y, 64 - length, length);
|
||||||
|
return y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -32,6 +32,12 @@ public class PacketTransformation {
|
|||||||
return fakeMac;
|
return fakeMac;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Connection binding used by myTeamSpeak, in the AES-128/SHA-256 protocol mode. */
|
||||||
|
public byte[] getMyTeamSpeakChallenge() {
|
||||||
|
return Ts3Crypt.hash256(ByteBuffer.allocate(6 + ivStruct.length)
|
||||||
|
.put(new byte[] {0x30, 8, 0, 0, 0, 0}).put(ivStruct).array());
|
||||||
|
}
|
||||||
|
|
||||||
public Pair<byte[], byte[]> computeParameters(PacketHeader header) {
|
public Pair<byte[], byte[]> computeParameters(PacketHeader header) {
|
||||||
ByteBuffer temporaryByteBuffer = ByteBuffer
|
ByteBuffer temporaryByteBuffer = ByteBuffer
|
||||||
.allocate(ivStruct.length == 20 ? 26 : 70)
|
.allocate(ivStruct.length == 20 ? 26 : 70)
|
||||||
|
|||||||
+17
@@ -3,6 +3,7 @@ package com.github.manevolent.ts3j.protocol.socket.client;
|
|||||||
import com.github.manevolent.ts3j.command.CommandException;
|
import com.github.manevolent.ts3j.command.CommandException;
|
||||||
|
|
||||||
import com.github.manevolent.ts3j.command.*;
|
import com.github.manevolent.ts3j.command.*;
|
||||||
|
import com.github.manevolent.ts3j.command.parameter.CommandSingleParameter;
|
||||||
import com.github.manevolent.ts3j.identity.Identity;
|
import com.github.manevolent.ts3j.identity.Identity;
|
||||||
import com.github.manevolent.ts3j.protocol.NetworkPacket;
|
import com.github.manevolent.ts3j.protocol.NetworkPacket;
|
||||||
import com.github.manevolent.ts3j.protocol.Packet;
|
import com.github.manevolent.ts3j.protocol.Packet;
|
||||||
@@ -36,6 +37,7 @@ import java.nio.*;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Server/client common abstract client socket, used to interact with the UDP connection. Provides most of the protocol
|
* Server/client common abstract client socket, used to interact with the UDP connection. Provides most of the protocol
|
||||||
@@ -165,6 +167,21 @@ public abstract class AbstractTeamspeakClientSocket
|
|||||||
setTransformation(new PacketTransformation(parameters.getIvStruct(), parameters.getFakeSignature()));
|
setTransformation(new PacketTransformation(parameters.getIvStruct(), parameters.getFakeSignature()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private volatile Function<byte[], Map<String, String>> myTeamSpeakAuthenticator;
|
||||||
|
|
||||||
|
/** Set before connecting; invoked after the handshake with this connection's challenge. */
|
||||||
|
public void setMyTeamSpeakAuthenticator(Function<byte[], Map<String, String>> authenticator) {
|
||||||
|
myTeamSpeakAuthenticator = authenticator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addMyTeamSpeakParameters(Command command) {
|
||||||
|
Function<byte[], Map<String, String>> authenticator = myTeamSpeakAuthenticator;
|
||||||
|
if (authenticator == null) return;
|
||||||
|
Map<String, String> parameters = authenticator.apply(transformation.getMyTeamSpeakChallenge());
|
||||||
|
for (Map.Entry<String, String> entry : parameters.entrySet())
|
||||||
|
command.add(new CommandSingleParameter(entry.getKey(), entry.getValue()));
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract NetworkPacket readNetworkPacket(int timeout) throws IOException;
|
protected abstract NetworkPacket readNetworkPacket(int timeout) throws IOException;
|
||||||
|
|
||||||
protected abstract void writeNetworkPacket(NetworkPacket packet) throws IOException;
|
protected abstract void writeNetworkPacket(NetworkPacket packet) throws IOException;
|
||||||
|
|||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
package com.github.manevolent.ts3j.protocol.packet.handler.client;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class PuzzleAnswerTest extends TestCase {
|
||||||
|
private static byte[] bytes(int length, int first) {
|
||||||
|
byte[] b = new byte[length];
|
||||||
|
Arrays.fill(b, (byte) 0x11);
|
||||||
|
b[0] = (byte) first;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Top bit set: toByteArray() gives 65 bytes, the first a sign byte. */
|
||||||
|
public void testDropsTheSignByte() {
|
||||||
|
byte[] answer = bytes(64, 0x80);
|
||||||
|
assertTrue(Arrays.equals(answer, LocalClientHandlerConnecting.unsigned64(new BigInteger(1, answer))));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testKeepsSixtyFourBytes() {
|
||||||
|
byte[] answer = bytes(64, 0x7f);
|
||||||
|
assertTrue(Arrays.equals(answer, LocalClientHandlerConnecting.unsigned64(new BigInteger(1, answer))));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A leading zero byte: toByteArray() gives 63 bytes, which used to fail the connect. */
|
||||||
|
public void testPadsAShortAnswerWithZeros() {
|
||||||
|
byte[] answer = bytes(64, 0x00);
|
||||||
|
answer[1] = 0x42;
|
||||||
|
assertTrue(Arrays.equals(answer, LocalClientHandlerConnecting.unsigned64(new BigInteger(1, answer))));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user