From e74fa6c42dae9a59fe13860756ed67c3d9fef4ab Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Sun, 2 May 2021 13:07:04 -0400 Subject: [PATCH] Allow connections even if encryption failed to initialize post-1.16.220 (#2147) This allows Java 16 to still be compatible with Geyser. --- connector/pom.xml | 2 +- .../connector/utils/LoginEncryptionUtils.java | 23 ++++++++++++++++++- connector/src/main/resources/languages | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/connector/pom.xml b/connector/pom.xml index 90ee8a5c9..7d4bae7a0 100644 --- a/connector/pom.xml +++ b/connector/pom.xml @@ -32,7 +32,7 @@ com.github.CloudburstMC.Protocol bedrock-v431 - f8ecf54 + 9947665 compile diff --git a/connector/src/main/java/org/geysermc/connector/utils/LoginEncryptionUtils.java b/connector/src/main/java/org/geysermc/connector/utils/LoginEncryptionUtils.java index 3c093df94..1614f6191 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/LoginEncryptionUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/LoginEncryptionUtils.java @@ -60,6 +60,8 @@ import java.util.UUID; public class LoginEncryptionUtils { private static final ObjectMapper JSON_MAPPER = new ObjectMapper().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + private static boolean HAS_SENT_ENCRYPTION_MESSAGE = false; + private static boolean validateChainData(JsonNode data) throws Exception { ECPublicKey lastKey = null; boolean validChain = false; @@ -133,7 +135,18 @@ public class LoginEncryptionUtils { session.setClientData(JSON_MAPPER.convertValue(JSON_MAPPER.readTree(clientJwt.getPayload().toBytes()), BedrockClientData.class)); if (EncryptionUtils.canUseEncryption()) { - LoginEncryptionUtils.startEncryptionHandshake(session, identityPublicKey); + try { + LoginEncryptionUtils.startEncryptionHandshake(session, identityPublicKey); + } catch (Throwable e) { + // An error can be thrown on older Java 8 versions about an invalid key + if (connector.getConfig().isDebugMode()) { + e.printStackTrace(); + } + + sendEncryptionFailedMessage(connector); + } + } else { + sendEncryptionFailedMessage(connector); } } catch (Exception ex) { session.disconnect("disconnectionScreen.internalError.cantConnect"); @@ -155,6 +168,14 @@ public class LoginEncryptionUtils { session.sendUpstreamPacketImmediately(packet); } + private static void sendEncryptionFailedMessage(GeyserConnector connector) { + if (!HAS_SENT_ENCRYPTION_MESSAGE) { + connector.getLogger().warning(LanguageUtils.getLocaleStringLog("geyser.network.encryption.line_1")); + connector.getLogger().warning(LanguageUtils.getLocaleStringLog("geyser.network.encryption.line_2", "https://geysermc.org/supported_java")); + HAS_SENT_ENCRYPTION_MESSAGE = true; + } + } + private static final int AUTH_MSA_DETAILS_FORM_ID = 1334; private static final int AUTH_MSA_CODE_FORM_ID = 1335; private static final int AUTH_FORM_ID = 1336; diff --git a/connector/src/main/resources/languages b/connector/src/main/resources/languages index 3d3b60de7..96e7ed66c 160000 --- a/connector/src/main/resources/languages +++ b/connector/src/main/resources/languages @@ -1 +1 @@ -Subproject commit 3d3b60de724f3f552f351c5f400269fde7598b67 +Subproject commit 96e7ed66ccdafea0cc991b8004566d448e8f6e6a