No excuses this time.
This commit is contained in:
parent
c65a3ec55e
commit
fbacafb752
@ -8,15 +8,11 @@ import java.net.URL;
|
|||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
import java.security.Key;
|
import java.security.Key;
|
||||||
import java.security.KeyFactory;
|
|
||||||
import java.security.KeyPair;
|
import java.security.KeyPair;
|
||||||
import java.security.KeyPairGenerator;
|
import java.security.KeyPairGenerator;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.PublicKey;
|
|
||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
import java.security.spec.InvalidKeySpecException;
|
|
||||||
import java.security.spec.X509EncodedKeySpec;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import javax.crypto.BadPaddingException;
|
import javax.crypto.BadPaddingException;
|
||||||
@ -42,7 +38,6 @@ public class EncryptionUtil
|
|||||||
|
|
||||||
private static final Random random = new Random();
|
private static final Random random = new Random();
|
||||||
private static KeyPair keys;
|
private static KeyPair keys;
|
||||||
private static SecretKey secret = new SecretKeySpec(new byte[16], "AES");
|
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
@ -111,28 +106,4 @@ public class EncryptionUtil
|
|||||||
cip.init(forEncryption, new ParametersWithIV(new KeyParameter(shared.getEncoded()), shared.getEncoded()));
|
cip.init(forEncryption, new ParametersWithIV(new KeyParameter(shared.getEncoded()), shared.getEncoded()));
|
||||||
return cip;
|
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
package net.md_5.bungee;
|
package net.md_5.bungee;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.security.PublicKey;
|
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import javax.crypto.SecretKey;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.md_5.bungee.api.Callback;
|
import net.md_5.bungee.api.Callback;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
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.Packet2Handshake;
|
||||||
import net.md_5.bungee.packet.PacketCDClientStatus;
|
import net.md_5.bungee.packet.PacketCDClientStatus;
|
||||||
import net.md_5.bungee.packet.PacketFAPluginMessage;
|
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.PacketFDEncryptionRequest;
|
||||||
import net.md_5.bungee.packet.PacketFFKick;
|
import net.md_5.bungee.packet.PacketFFKick;
|
||||||
import net.md_5.bungee.packet.PacketInputStream;
|
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.
|
* 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();
|
OutputStream out = socket.getOutputStream();
|
||||||
|
|
||||||
out.write(handshake.getPacket());
|
out.write(handshake.getPacket());
|
||||||
PacketFDEncryptionRequest encryptRequest = new PacketFDEncryptionRequest(in.readPacket());
|
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));
|
|
||||||
|
|
||||||
for (byte[] custom : user.loginPackets)
|
for (byte[] custom : user.loginPackets)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user