forked from TuxCoding/FastLogin
Flip velocity check to scan for newer Paper configurations first
The PaperConfig class file still exists in newer versions
This commit is contained in:
@ -110,17 +110,17 @@ public class BungeeManager {
|
|||||||
throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException, ClassNotFoundException,
|
throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException, ClassNotFoundException,
|
||||||
NoSuchMethodException, InvocationTargetException {
|
NoSuchMethodException, InvocationTargetException {
|
||||||
try {
|
try {
|
||||||
if (isProxySupported("com.destroystokyo.paper.PaperConfig", "velocitySupport")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (ClassNotFoundException classNotFoundException) {
|
|
||||||
// try again using the newer Paper configuration
|
|
||||||
Class<?> globalConfig = Class.forName("io.papermc.paper.configuration.GlobalConfiguration");
|
Class<?> globalConfig = Class.forName("io.papermc.paper.configuration.GlobalConfiguration");
|
||||||
Object global = globalConfig.getDeclaredMethod("get").invoke(null);
|
Object global = globalConfig.getDeclaredMethod("get").invoke(null);
|
||||||
Object proxiesConfiguration = global.getClass().getDeclaredField("proxies").get(global);
|
Object proxiesConfiguration = global.getClass().getDeclaredField("proxies").get(global);
|
||||||
Object velocityConfig = proxiesConfiguration.getClass().getDeclaredField("velocity").get(proxiesConfiguration);
|
Object velocityConfig = proxiesConfiguration.getClass().getDeclaredField("velocity").get(proxiesConfiguration);
|
||||||
|
|
||||||
return velocityConfig.getClass().getDeclaredField("enabled").getBoolean(velocityConfig);
|
return velocityConfig.getClass().getDeclaredField("enabled").getBoolean(velocityConfig);
|
||||||
|
} catch (ClassNotFoundException classNotFoundException) {
|
||||||
|
// try again using the older Paper configuration, because the old class file still exists in newer versions
|
||||||
|
if (isProxySupported("com.destroystokyo.paper.PaperConfig", "velocitySupport")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -142,7 +142,7 @@ public class EncryptionUtilTest {
|
|||||||
assertThat(decryptSharedKey, is(secretKey));
|
assertThat(decryptSharedKey, is(secretKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] encrypt(PublicKey receiverKey, byte[] message)
|
private static byte[] encrypt(PublicKey receiverKey, byte... message)
|
||||||
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
|
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
|
||||||
IllegalBlockSizeException, BadPaddingException {
|
IllegalBlockSizeException, BadPaddingException {
|
||||||
var encryptCipher = Cipher.getInstance(receiverKey.getAlgorithm());
|
var encryptCipher = Cipher.getInstance(receiverKey.getAlgorithm());
|
||||||
@ -169,13 +169,14 @@ public class EncryptionUtilTest {
|
|||||||
assertThat(EncryptionUtil.getServerIdHashString(serverId, sharedSecret, serverPK), is(sessionHash));
|
assertThat(EncryptionUtil.getServerIdHashString(serverId, sharedSecret, serverPK), is(sessionHash));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getServerHash(String serverId, SecretKey sharedSecret, PublicKey serverPK) {
|
private static String getServerHash(CharSequence serverId, SecretKey sharedSecret, PublicKey serverPK) {
|
||||||
// https://wiki.vg/Protocol_Encryption#Client
|
// https://wiki.vg/Protocol_Encryption#Client
|
||||||
// sha1 := Sha1()
|
// sha1 := Sha1()
|
||||||
// sha1.update(ASCII encoding of the server id string from Encryption Request)
|
// sha1.update(ASCII encoding of the server id string from Encryption Request)
|
||||||
// sha1.update(shared secret)
|
// sha1.update(shared secret)
|
||||||
// sha1.update(server's encoded public key from Encryption Request)
|
// sha1.update(server's encoded public key from Encryption Request)
|
||||||
// hash := sha1.hexdigest() # String of hex characters
|
// hash := sha1.hexdigest() # String of hex characters
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
var hasher = Hashing.sha1().newHasher();
|
var hasher = Hashing.sha1().newHasher();
|
||||||
hasher.putString(serverId, StandardCharsets.US_ASCII);
|
hasher.putString(serverId, StandardCharsets.US_ASCII);
|
||||||
hasher.putBytes(sharedSecret.getEncoded());
|
hasher.putBytes(sharedSecret.getEncoded());
|
||||||
@ -197,7 +198,7 @@ public class EncryptionUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testServerIdHashWrongServerKey() throws Exception {
|
public void testServerIdHashWrongServerKey() {
|
||||||
var serverId = "";
|
var serverId = "";
|
||||||
var sharedSecret = generateSharedKey();
|
var sharedSecret = generateSharedKey();
|
||||||
var serverPK = EncryptionUtil.generateKeyPair().getPublic();
|
var serverPK = EncryptionUtil.generateKeyPair().getPublic();
|
||||||
|
Reference in New Issue
Block a user