forked from TuxCoding/FastLogin
Add comments, make cipher variable names clearer
This commit is contained in:
@ -175,16 +175,20 @@ public class VerifyResponseTask implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean enableEncryption(SecretKey loginKey) throws IllegalArgumentException {
|
private boolean enableEncryption(SecretKey loginKey) throws IllegalArgumentException {
|
||||||
|
// Initialize method reflections
|
||||||
if (encryptMethod == null) {
|
if (encryptMethod == null) {
|
||||||
Class<?> networkManagerClass = MinecraftReflection.getNetworkManagerClass();
|
Class<?> networkManagerClass = MinecraftReflection.getNetworkManagerClass();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Try to get the old (pre MC 1.16.4) encryption method
|
||||||
encryptMethod = FuzzyReflection.fromClass(networkManagerClass)
|
encryptMethod = FuzzyReflection.fromClass(networkManagerClass)
|
||||||
.getMethodByParameters("a", SecretKey.class);
|
.getMethodByParameters("a", SecretKey.class);
|
||||||
} catch (IllegalArgumentException exception) {
|
} catch (IllegalArgumentException exception) {
|
||||||
|
// Get the new encryption method
|
||||||
encryptMethod = FuzzyReflection.fromClass(networkManagerClass)
|
encryptMethod = FuzzyReflection.fromClass(networkManagerClass)
|
||||||
.getMethodByParameters("a", Cipher.class, Cipher.class);
|
.getMethodByParameters("a", Cipher.class, Cipher.class);
|
||||||
|
|
||||||
|
// Get the needed Cipher helper method (used to generate ciphers from login key)
|
||||||
Class<?> encryptionClass = MinecraftReflection.getMinecraftClass("MinecraftEncryption");
|
Class<?> encryptionClass = MinecraftReflection.getMinecraftClass("MinecraftEncryption");
|
||||||
cipherMethod = FuzzyReflection.fromClass(encryptionClass)
|
cipherMethod = FuzzyReflection.fromClass(encryptionClass)
|
||||||
.getMethodByParameters("a", int.class, Key.class);
|
.getMethodByParameters("a", int.class, Key.class);
|
||||||
@ -194,13 +198,17 @@ public class VerifyResponseTask implements Runnable {
|
|||||||
try {
|
try {
|
||||||
Object networkManager = this.getNetworkManager();
|
Object networkManager = this.getNetworkManager();
|
||||||
|
|
||||||
|
// If cipherMethod is null - use old encryption (pre MC 1.16.4), otherwise use the new cipher one
|
||||||
if (cipherMethod == null) {
|
if (cipherMethod == null) {
|
||||||
|
// Encrypt/decrypt packet flow, this behaviour is expected by the client
|
||||||
encryptMethod.invoke(networkManager, loginKey);
|
encryptMethod.invoke(networkManager, loginKey);
|
||||||
} else {
|
} else {
|
||||||
Object cipher = cipherMethod.invoke(null, 2, loginKey);
|
// Create ciphers from login key
|
||||||
Object cipher1 = cipherMethod.invoke(null, 1, loginKey);
|
Object decryptionCipher = cipherMethod.invoke(null, Cipher.DECRYPT_MODE, loginKey);
|
||||||
|
Object encryptionCipher = cipherMethod.invoke(null, Cipher.ENCRYPT_MODE, loginKey);
|
||||||
|
|
||||||
encryptMethod.invoke(networkManager, cipher, cipher1);
|
// Encrypt/decrypt packet flow, this behaviour is expected by the client
|
||||||
|
encryptMethod.invoke(networkManager, decryptionCipher, encryptionCipher);
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
disconnect("error-kick", false, "Couldn't enable encryption", ex);
|
disconnect("error-kick", false, "Couldn't enable encryption", ex);
|
||||||
|
Reference in New Issue
Block a user