Setup encryption before possible disconnect (#1754)

This commit is contained in:
Wouter Gritter
2026-07-11 22:09:03 +02:00
committed by GitHub
parent 729a050662
commit b8d1f16b07
@@ -200,8 +200,12 @@ public class InitialLoginSessionHandler implements MinecraftSessionHandler {
}
byte[] decryptedSharedSecret = decryptRsa(serverKeyPair, packet.getSharedSecret());
String serverId = generateServerId(decryptedSharedSecret, serverKeyPair.getPublic());
// Go ahead and enable encryption. Once the client sends EncryptionResponse, encryption
// is enabled.
mcConnection.enableEncryption(decryptedSharedSecret);
String serverId = generateServerId(decryptedSharedSecret, serverKeyPair.getPublic());
String playerIp = ((InetSocketAddress) mcConnection.getRemoteAddress()).getHostString();
String url = String.format(MOJANG_HASJOINED_URL,
urlFormParameterEscaper().escape(login.getUsername()), serverId);
@@ -230,18 +234,6 @@ public class InitialLoginSessionHandler implements MinecraftSessionHandler {
return;
}
// Go ahead and enable encryption. Once the client sends EncryptionResponse, encryption
// is enabled.
try {
mcConnection.enableEncryption(decryptedSharedSecret);
} catch (GeneralSecurityException e) {
logger.error("Unable to enable encryption for connection", e);
// At this point, the connection is encrypted, but something's wrong on our side and
// we can't do anything about it.
mcConnection.close(true);
return;
}
if (response.statusCode() == 200) {
final GameProfile profile = GENERAL_GSON.fromJson(response.body(),
GameProfile.class);