Refactor cipher logic.
This commit is contained in:
@@ -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...");
|
||||
|
@@ -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));
|
||||
}
|
||||
|
@@ -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.
|
||||
|
Reference in New Issue
Block a user