Skip to content

Commit

Permalink
Allow connections even if encryption failed to initialize post-1.16.2…
Browse files Browse the repository at this point in the history
…20 (#2147)

This allows Java 16 to still be compatible with Geyser.
  • Loading branch information
Camotoy authored May 2, 2021
1 parent 1301cd9 commit e74fa6c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<dependency>
<groupId>com.github.CloudburstMC.Protocol</groupId>
<artifactId>bedrock-v431</artifactId>
<version>f8ecf54</version>
<version>9947665</version>
<scope>compile</scope>
<exclusions>
<exclusion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
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;
Expand Down Expand Up @@ -133,7 +135,18 @@ private static void encryptConnectionWithCert(GeyserConnector connector, GeyserS
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");
Expand All @@ -155,6 +168,14 @@ private static void startEncryptionHandshake(GeyserSession session, PublicKey ke
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;
Expand Down

0 comments on commit e74fa6c

Please sign in to comment.