Fix input encryption IV after controller packets are sent

This commit is contained in:
Cameron Gutman 2016-03-29 19:55:31 -04:00
parent 34ef95926e
commit 82390ec9b9

View File

@ -9,6 +9,7 @@ import java.nio.ByteOrder;
import java.security.InvalidAlgorithmParameterException; import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
@ -239,6 +240,15 @@ public class ControllerStream {
// Send the packet over the control stream on Gen 5+ // Send the packet over the control stream on Gen 5+
if (context.serverGeneration >= ConnectionContext.SERVER_GENERATION_5) { if (context.serverGeneration >= ConnectionContext.SERVER_GENERATION_5) {
controlSender.sendInputPacket(sendBuffer.array(), (short) (paddedLength + 4)); controlSender.sendInputPacket(sendBuffer.array(), (short) (paddedLength + 4));
// For reasons that I can't understand, NVIDIA decides to use the last 16
// bytes of ciphertext in the most recent game controller packet as the IV for
// future encryption. I think it may be a buffer overrun on their end but we'll have
// to mimic it to work correctly.
if (context.serverGeneration >= ConnectionContext.SERVER_GENERATION_7 && paddedLength >= 32) {
cipher.initialize(context.riKey,
Arrays.copyOfRange(sendBuffer.array(), 4 + paddedLength - 16, 4 + paddedLength));
}
} }
else { else {
// Send the packet over the TCP connection on Gen 4 and below // Send the packet over the TCP connection on Gen 4 and below