From f62aa390d25b5e404405f6fe31d6d86f7a43450e Mon Sep 17 00:00:00 2001 From: Blue Kelp Date: Fri, 2 Aug 2019 13:15:32 -0700 Subject: [PATCH] support auto-login of configured users - fall back to window/form prompt if user is not configured --- .../geysermc/connector/GeyserConnector.java | 2 +- .../configuration/GeyserConfiguration.java | 4 +++ .../configuration/UserAuthenticationInfo.java | 31 +++++++++++++++++++ .../network/UpstreamPacketHandler.java | 22 ++++++++++++- .../connector/utils/LoginEncryptionUtils.java | 4 +-- connector/src/main/resources/config.yml | 13 ++++++++ 6 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 connector/src/main/java/org/geysermc/connector/configuration/UserAuthenticationInfo.java diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 639f5370..5f6f39a6 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -116,7 +116,7 @@ public class GeyserConnector implements Connector { config = FileUtils.loadConfig(configFile, GeyserConfiguration.class); } catch (IOException ex) { - logger.severe("Failed to create config.yml! Make sure it's up to date and writable!"); + logger.severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!"); shutdown(); } diff --git a/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java b/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java index fad95505..6d6185f0 100644 --- a/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java +++ b/connector/src/main/java/org/geysermc/connector/configuration/GeyserConfiguration.java @@ -28,12 +28,16 @@ package org.geysermc.connector.configuration; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Getter; +import java.util.Map; + @Getter public class GeyserConfiguration { private BedrockConfiguration bedrock; private RemoteConfiguration remote; + private Map userAuths; + @JsonProperty("ping-passthrough") private boolean pingPassthrough; diff --git a/connector/src/main/java/org/geysermc/connector/configuration/UserAuthenticationInfo.java b/connector/src/main/java/org/geysermc/connector/configuration/UserAuthenticationInfo.java new file mode 100644 index 00000000..e8ce1424 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/configuration/UserAuthenticationInfo.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.configuration; + +public class UserAuthenticationInfo { + public String email; + public String password; +} \ No newline at end of file diff --git a/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java b/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java index 4fbb520d..df150440 100644 --- a/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java @@ -28,6 +28,7 @@ package org.geysermc.connector.network; import com.nukkitx.protocol.bedrock.BedrockPacket; import com.nukkitx.protocol.bedrock.packet.*; import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.configuration.UserAuthenticationInfo; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.Registry; import org.geysermc.connector.utils.LoginEncryptionUtils; @@ -91,11 +92,30 @@ public class UpstreamPacketHandler extends LoggingPacketHandler { return LoginEncryptionUtils.authenticateFromForm(session, connector, packet.getFormData()); } + private boolean couldLoginUserByName(String bedrockUsername) { + if (connector.getConfig().getUserAuths() != null) { + UserAuthenticationInfo info = connector.getConfig().getUserAuths().get(bedrockUsername); + + if (info != null) { + connector.getLogger().debug("using stored credentials for bedrock user " + session.getAuthenticationData().getName()); + session.authenticate(info.email, info.password); + return true; + } + } + + return false; + } + @Override public boolean handle(MovePlayerPacket packet) { connector.getLogger().debug("Handled packet: " + packet.getClass().getSimpleName()); if (!session.isLoggedIn()) { - LoginEncryptionUtils.showLoginWindow(session); + // TODO it is safer to key authentication on something that won't change (UUID, not username) + if (!couldLoginUserByName(session.getAuthenticationData().getName())) { + LoginEncryptionUtils.showLoginWindow(session); + } + // else we were able to log the user in + return true; } return false; 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 868d7b49..48e5d515 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/LoginEncryptionUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/LoginEncryptionUtils.java @@ -150,10 +150,10 @@ public class LoginEncryptionUtils { return false; CustomFormResponse response = (CustomFormResponse) customFormWindow.getResponse(); - String username = response.getInputResponses().get(2); + String email = response.getInputResponses().get(2); String password = response.getInputResponses().get(3); - session.authenticate(username, password); + session.authenticate(email, password); // TODO should we clear the window cache in all cases or just if not already logged in? // Clear windows so authentication data isn't accidentally cached diff --git a/connector/src/main/resources/config.yml b/connector/src/main/resources/config.yml index 885e5cf7..50407177 100644 --- a/connector/src/main/resources/config.yml +++ b/connector/src/main/resources/config.yml @@ -21,6 +21,19 @@ remote: port: 25565 online-mode: false +## the Xbox/MCPE username is the key for the Java server auth-info +## this allows automatic configuration/login to the remote Java server +## if you are brave/stupid enough to put your Mojang account info into +## a config file +#userAuths: +# bluekelp2: # MCPE/Xbox username +# email: not_really_my_email_address_mr_minecrafter53267@gmail.com # Mojang account email address +# password: "this isn't really my password" +# +# herpderp40300499303040503030300500293858393589: +# email: herpderp@derpherp.com +# password: dooooo + # Relay the MOTD, player count and max players from the remote server ping-passthrough: false