From fbacafb752bdd79e730673d3f27d9c86d23a661b Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 2 Feb 2013 10:24:54 +1100 Subject: [PATCH] No excuses this time. --- .../java/net/md_5/bungee/EncryptionUtil.java | 29 ------------------- .../net/md_5/bungee/ServerConnection.java | 24 +-------------- 2 files changed, 1 insertion(+), 52 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java index 2ec09bca..8c684ae9 100644 --- a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java +++ b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java @@ -8,15 +8,11 @@ import java.net.URL; import java.net.URLEncoder; import java.security.InvalidKeyException; import java.security.Key; -import java.security.KeyFactory; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.security.PublicKey; import java.security.Security; -import java.security.spec.InvalidKeySpecException; -import java.security.spec.X509EncodedKeySpec; import java.util.Arrays; import java.util.Random; import javax.crypto.BadPaddingException; @@ -42,7 +38,6 @@ public class EncryptionUtil private static final Random random = new Random(); private static KeyPair keys; - private static SecretKey secret = new SecretKeySpec(new byte[16], "AES"); static { @@ -111,28 +106,4 @@ public class EncryptionUtil cip.init(forEncryption, new ParametersWithIV(new KeyParameter(shared.getEncoded()), shared.getEncoded())); return cip; } - - public static SecretKey getSecret() - { - return secret; - } - - public static PublicKey getPubkey(PacketFDEncryptionRequest request) throws InvalidKeySpecException, NoSuchAlgorithmException - { - return KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(request.publicKey)); - } - - public static byte[] encrypt(Key key, byte[] b) throws BadPaddingException, IllegalBlockSizeException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException - { - Cipher hasher = Cipher.getInstance("RSA"); - hasher.init(Cipher.ENCRYPT_MODE, key); - return hasher.doFinal(b); - } - - public static byte[] getShared(SecretKey key, PublicKey pubkey) throws BadPaddingException, IllegalBlockSizeException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException - { - Cipher cipher = Cipher.getInstance("RSA"); - cipher.init(Cipher.ENCRYPT_MODE, pubkey); - return cipher.doFinal(key.getEncoded()); - } } diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java index 92c79a7d..865aa44b 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java @@ -1,14 +1,10 @@ package net.md_5.bungee; -import java.io.DataInputStream; -import java.io.DataOutputStream; import java.io.OutputStream; import java.net.InetSocketAddress; import java.net.Socket; -import java.security.PublicKey; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; -import javax.crypto.SecretKey; import lombok.Getter; import net.md_5.bungee.api.Callback; import net.md_5.bungee.api.ChatColor; @@ -22,12 +18,9 @@ import net.md_5.bungee.packet.Packet1Login; import net.md_5.bungee.packet.Packet2Handshake; import net.md_5.bungee.packet.PacketCDClientStatus; import net.md_5.bungee.packet.PacketFAPluginMessage; -import net.md_5.bungee.packet.PacketFCEncryptionResponse; import net.md_5.bungee.packet.PacketFDEncryptionRequest; import net.md_5.bungee.packet.PacketFFKick; import net.md_5.bungee.packet.PacketInputStream; -import org.bouncycastle.crypto.io.CipherInputStream; -import org.bouncycastle.crypto.io.CipherOutputStream; /** * Class representing a connection from the proxy to the server; ie upstream. @@ -59,22 +52,7 @@ public class ServerConnection extends GenericConnection implements Server OutputStream out = socket.getOutputStream(); out.write(handshake.getPacket()); - PacketFDEncryptionRequest encryptRequest = new PacketFDEncryptionRequest(in.readPacket()); - - SecretKey myKey = EncryptionUtil.getSecret(); - PublicKey pub = EncryptionUtil.getPubkey(encryptRequest); - - PacketFCEncryptionResponse response = new PacketFCEncryptionResponse(EncryptionUtil.getShared(myKey, pub), EncryptionUtil.encrypt(pub, encryptRequest.verifyToken)); - out.write(response.getPacket()); - - int ciphId = Util.getId(in.readPacket()); - if (ciphId != 0xFC) - { - throw new RuntimeException("Server did not send encryption enable"); - } - - in = new PacketInputStream(new CipherInputStream(socket.getInputStream(), EncryptionUtil.getCipher(false, myKey))); - out = new CipherOutputStream(out, EncryptionUtil.getCipher(true, myKey)); + in.readPacket(); for (byte[] custom : user.loginPackets) {