Refactor cipher logic.

This commit is contained in:
Andrew Steinborn
2018-08-04 00:09:25 -04:00
parent 6f3397f76f
commit 9438d087e2
6 changed files with 37 additions and 3 deletions

View File

@@ -54,6 +54,7 @@ public class VelocityServer {
public void start() {
logger.info("Using {}", Natives.compressor.getLoadedVariant());
logger.info("Using {}", Natives.cipher.getLoadedVariant());
// Create a key pair
logger.info("Booting up Velocity...");

View File

@@ -2,6 +2,7 @@ package com.velocitypowered.proxy.connection;
import com.google.common.base.Preconditions;
import com.velocitypowered.natives.compression.VelocityCompressor;
import com.velocitypowered.natives.encryption.VelocityCipherFactory;
import com.velocitypowered.natives.util.Natives;
import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.protocol.PacketWrapper;
@@ -205,8 +206,9 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
public void enableEncryption(byte[] secret) throws GeneralSecurityException {
SecretKey key = new SecretKeySpec(secret, "AES");
VelocityCipher decryptionCipher = new JavaVelocityCipher(false, key);
VelocityCipher encryptionCipher = new JavaVelocityCipher(true, key);
VelocityCipherFactory factory = Natives.cipher.get();
VelocityCipher decryptionCipher = factory.forDecryption(key);
VelocityCipher encryptionCipher = factory.forEncryption(key);
channel.pipeline().addBefore(FRAME_DECODER, CIPHER_DECODER, new MinecraftCipherDecoder(decryptionCipher));
channel.pipeline().addBefore(FRAME_ENCODER, CIPHER_ENCODER, new MinecraftCipherEncoder(encryptionCipher));
}

View File

@@ -101,6 +101,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation {
}
public void handleConnectionException(ServerInfo info, Component disconnectReason) {
connectionInFlight = null;
if (connectedServer == null || connectedServer.getServerInfo().equals(info)) {
// The player isn't yet connected to a server or they are already connected to the server
// they're disconnected from.