Skip to content

Commit

Permalink
Moved OpenAuthMod authentication into its own ViaProxy plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Nov 30, 2024
1 parent e6dc79f commit b8a1a63
Show file tree
Hide file tree
Showing 18 changed files with 6 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,7 @@ public enum AuthMethod {
/**
* No authentication (Offline mode)
*/
NONE("tab.general.minecraft_account.option_no_account"),
/**
* Requires the OpenAuthMod client mod (https://modrinth.com/mod/openauthmod)
*/
OPENAUTHMOD("tab.general.minecraft_account.option_openauthmod");
NONE("tab.general.minecraft_account.option_no_account");

private final String guiTranslationKey;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ private void connect(final SocketAddress serverAddress, final ProtocolVersion se
this.proxyConnection.setUserOptions(userOptions);
this.proxyConnection.setC2pConnectionState(intendedState.getConnectionState());
this.proxyConnection.getPacketHandlers().add(new StatusPacketHandler(this.proxyConnection));
this.proxyConnection.getPacketHandlers().add(new OpenAuthModPacketHandler(this.proxyConnection));
if (ViaProxy.getConfig().shouldSupportSimpleVoiceChat() && serverVersion.newerThan(ProtocolVersion.v1_14) && clientVersion.newerThan(ProtocolVersion.v1_14)) {
this.proxyConnection.getPacketHandlers().add(new SimpleVoiceChatPacketHandler(this.proxyConnection));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,15 @@
import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_1;
import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_3;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.raphimc.minecraftauth.step.bedrock.StepMCChain;
import net.raphimc.minecraftauth.step.java.StepPlayerCertificates;
import net.raphimc.netminecraft.packet.PacketTypes;
import net.raphimc.netminecraft.packet.impl.login.C2SLoginHelloPacket;
import net.raphimc.netminecraft.packet.impl.login.C2SLoginKeyPacket;
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
import net.raphimc.viabedrock.protocol.storage.AuthChainData;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.plugins.events.FillPlayerDataEvent;
import net.raphimc.viaproxy.plugins.events.JoinServerRequestEvent;
import net.raphimc.viaproxy.protocoltranslator.viaproxy.ViaProxyConfig;
import net.raphimc.viaproxy.proxy.packethandler.OpenAuthModPacketHandler;
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
import net.raphimc.viaproxy.proxy.util.CloseAndReturn;
import net.raphimc.viaproxy.saves.impl.accounts.Account;
Expand All @@ -50,10 +45,7 @@
import java.security.SignatureException;
import java.time.Instant;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class ExternalInterface {

Expand Down Expand Up @@ -110,15 +102,7 @@ public static void fillPlayerData(final ProxyConnection proxyConnection) {
public static void joinServer(final String serverIdHash, final ProxyConnection proxyConnection) {
Logger.u_info("auth", proxyConnection, "Trying to join online mode server");
try {
if (ViaProxy.getConfig().getAuthMethod() == ViaProxyConfig.AuthMethod.OPENAUTHMOD) {
try {
final ByteBuf response = proxyConnection.getPacketHandler(OpenAuthModPacketHandler.class).sendCustomPayload(OpenAuthModConstants.JOIN_CHANNEL, PacketTypes.writeString(Unpooled.buffer(), serverIdHash)).get(6, TimeUnit.SECONDS);
if (response == null) throw new TimeoutException();
if (response.isReadable() && !response.readBoolean()) throw new TimeoutException();
} catch (TimeoutException e) {
proxyConnection.kickClient("§cAuthentication cancelled! You need to install OpenAuthMod in order to join this server.");
}
} else if (proxyConnection.getUserOptions().account() instanceof MicrosoftAccount microsoftAccount) {
if (proxyConnection.getUserOptions().account() instanceof MicrosoftAccount microsoftAccount) {
try {
AuthLibServices.SESSION_SERVICE.joinServer(microsoftAccount.getGameProfile(), microsoftAccount.getMcProfile().getMcToken().getAccessToken(), serverIdHash);
} catch (Throwable e) {
Expand All @@ -135,21 +119,11 @@ public static void joinServer(final String serverIdHash, final ProxyConnection p
}
}

public static void signNonce(final byte[] nonce, final C2SLoginKeyPacket packet, final ProxyConnection proxyConnection) throws InterruptedException, ExecutionException, SignatureException {
public static void signNonce(final byte[] nonce, final C2SLoginKeyPacket packet, final ProxyConnection proxyConnection) throws SignatureException {
Logger.u_info("auth", proxyConnection, "Requesting nonce signature");
final UserConnection user = proxyConnection.getUserConnection();

if (ViaProxy.getConfig().getAuthMethod() == ViaProxyConfig.AuthMethod.OPENAUTHMOD) {
try {
final ByteBuf response = proxyConnection.getPacketHandler(OpenAuthModPacketHandler.class).sendCustomPayload(OpenAuthModConstants.SIGN_NONCE_CHANNEL, PacketTypes.writeByteArray(Unpooled.buffer(), nonce)).get(5, TimeUnit.SECONDS);
if (response == null) throw new TimeoutException();
if (!response.readBoolean()) throw new TimeoutException();
packet.salt = response.readLong();
packet.signature = PacketTypes.readByteArray(response);
} catch (TimeoutException e) {
proxyConnection.kickClient("§cAuthentication cancelled! You need to install OpenAuthMod in order to join this server.");
}
} else if (user.has(ChatSession1_19_0.class)) {
if (user.has(ChatSession1_19_0.class)) {
final long salt = ThreadLocalRandom.current().nextLong();
packet.signature = user.get(ChatSession1_19_0.class).sign(updater -> {
updater.accept(nonce);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public boolean handleP2S(Packet packet, List<ChannelFutureListener> listeners) t
final byte[] encryptedNonce = CryptUtil.encryptData(publicKey, loginHelloPacket.nonce);

final C2SLoginKeyPacket loginKey = new C2SLoginKeyPacket(encryptedSecretKey, encryptedNonce);
if (this.proxyConnection.getServerVersion().newerThanOrEqualTo(ProtocolVersion.v1_19) && this.proxyConnection.getLoginHelloPacket().key != null) {
if (this.proxyConnection.getServerVersion().betweenInclusive(ProtocolVersion.v1_19, ProtocolVersion.v1_19_1) && this.proxyConnection.getLoginHelloPacket().key != null) {
ExternalInterface.signNonce(loginHelloPacket.nonce, loginKey, this.proxyConnection);
}
this.proxyConnection.getChannel().writeAndFlush(loginKey).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected void init(JPanel contentPane) {

int gridy = 0;
{
JLabel infoLabel = new JLabel("<html><p>" + I18n.get("tab.accounts.description.line1") + "</p><br><p>" + I18n.get("tab.accounts.description.line2") + "</p></html>");
JLabel infoLabel = new JLabel("<html><p>" + I18n.get("tab.accounts.description.line1") + "</p></html>");
GBC.create(body).grid(0, gridy++).weightx(1).insets(BORDER_PADDING, BORDER_PADDING, 0, BORDER_PADDING).fill(GBC.HORIZONTAL).add(infoLabel);
}
{
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/assets/viaproxy/language/cs_CZ.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ tab.general.server_version.label=Verze serveru:
tab.general.minecraft_account.label=Minecraft Účet:
tab.general.minecraft_account.option_no_account=Nepoužívat účet
tab.general.minecraft_account.option_select_account=Použít vybraný účet
tab.general.minecraft_account.option_openauthmod=Použít OpenAuthMod
tab.general.betacraft_auth.label=BetaCraft Auth (Classic)
tab.general.betacraft_auth.tooltip=Povolování BetaCraft Authentikace vám umožní připojit se na BetaCraft servery se zapnutým online módem.
tab.general.state.loading=Načítání ViaProxy...
Expand Down Expand Up @@ -43,7 +42,6 @@ tab.advanced.upload_latest_log.error_generic=Log nebylo možno nahrát: %s
tab.advanced.upload_latest_log.error_not_found=Log soubor nebyl nalezen.
tab.accounts.name=Účty
tab.accounts.description.line1=Pro připojení na online servery musíte přidat Microsoft účet. Můžete vybrat účet tím že na něj kliknete pravým tlačítkem myši. Vy výchozím nastavení bude vybrán první účet.
tab.accounts.description.line2=Pokud často měníte účet, můžete na svůj klient nainstalovat OpenAuthMod. Toto umožní ViaProxy použít účet který je použit na klientu.
tab.accounts.list.context_menu.select=Vybrat účet
tab.accounts.list.context_menu.remove=Vymazat
tab.accounts.list.context_menu.move_up=Posunout nahoru ↑
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/assets/viaproxy/language/de_DE.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ tab.general.server_version.label=Server Version:
tab.general.minecraft_account.label=Minecraft Konto:
tab.general.minecraft_account.option_no_account=Kein Konto verwenden
tab.general.minecraft_account.option_select_account=Ausgewähltes Konto verwenden
tab.general.minecraft_account.option_openauthmod=OpenAuthMod verwenden
tab.general.betacraft_auth.label=BetaCraft Authentifizierung (Classic)
tab.general.betacraft_auth.tooltip=Wenn du die BetaCraft Authentifizierung aktivierst, kannst du auf Classic Server, die Online Mode aktiviert haben joinen.
tab.general.state.loading=Lade ViaProxy...
Expand Down Expand Up @@ -52,7 +51,6 @@ tab.advanced.upload_latest_log.error_generic=Die Log-Datei konnte nicht hochgela
tab.advanced.upload_latest_log.error_not_found=Die Log-Datei konnte nicht gefunden werden.
tab.accounts.name=Konten
tab.accounts.description.line1=Um auf Online Mode Server zu joinen musst du ein Minecraft Konto im ViaProxy hinzufügen. Du kannst ein Konto auswählen indem du es rechtsklickst. Standardmäßig wird das erste verwendet.
tab.accounts.description.line2=Wenn du dein Konto oft änderst, kannst du stattdessen OpenAuthMod auf deinem Client installieren. Das erlaubt ViaProxy das aktuell eingeloggte Konto von deinem Client zu verwenden.
tab.accounts.list.context_menu.select=Konto auswählen
tab.accounts.list.context_menu.remove=Löschen
tab.accounts.list.context_menu.move_up=Nach oben schieben ↑
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/assets/viaproxy/language/en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ tab.general.server_version.label=Server Version:
tab.general.minecraft_account.label=Minecraft Account:
tab.general.minecraft_account.option_no_account=Use no account
tab.general.minecraft_account.option_select_account=Use selected account
tab.general.minecraft_account.option_openauthmod=Use OpenAuthMod
tab.general.betacraft_auth.label=BetaCraft Auth (Classic)
tab.general.betacraft_auth.tooltip=Enabling BetaCraft Auth allows you to join classic servers which have online mode enabled.
tab.general.state.loading=Loading ViaProxy...
Expand Down Expand Up @@ -52,7 +51,6 @@ tab.advanced.upload_latest_log.error_generic=The log file could not be uploaded:
tab.advanced.upload_latest_log.error_not_found=The log file could not be found.
tab.accounts.name=Accounts
tab.accounts.description.line1=To join online mode servers you have to add a minecraft account for ViaProxy to use. You can select an account by right clicking it. By default the first one will be used.
tab.accounts.description.line2=If you change your account frequently, you can install OpenAuthMod on your client. This allows ViaProxy to use the account you are logged in with on the client.
tab.accounts.list.context_menu.select=Select Account
tab.accounts.list.context_menu.remove=Remove
tab.accounts.list.context_menu.move_up=Move up ↑
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/assets/viaproxy/language/fr_FR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ tab.general.server_version.label=Vertion du serveur:
tab.general.minecraft_account.label=Compte Minecraft:
tab.general.minecraft_account.option_no_account=Pas de compte
tab.general.minecraft_account.option_select_account=compte selectionné
tab.general.minecraft_account.option_openauthmod=Utiliser OpenAuthMod
tab.general.betacraft_auth.label=BetaCraft Auth (Classic)
tab.general.betacraft_auth.tooltip=Activer BetaCraft Auth permet de se connecter a des serveurs classiques qui on le mode enligne activé.
tab.general.state.loading=Chargement de ViaProxy...
Expand Down Expand Up @@ -51,7 +50,6 @@ tab.advanced.upload_latest_log.error_generic=Le fichier de log n'as pas pu etre
tab.advanced.upload_latest_log.error_not_found=Le fichier de log est introuvable.
tab.accounts.name=Comptes
tab.accounts.description.line1=Pour rejoindre un serveur en ligne, ViaProxy a besoin d'un compre microsoft. Vous pouver selectionner un compte en faisant un clique droit dessu. Par default, le premier est selectionné.
tab.accounts.description.line2=Si vous changez souvent de compte, vous pouver installer OpenAuthMod (client). Cela permet a ViaProxy d'utiliser le compte avec lequelle vous etes connecté dans le client.
tab.accounts.list.context_menu.select=Selectioner ce compte
tab.accounts.list.context_menu.remove=Enlever
tab.accounts.list.context_menu.move_up=Envoyer vers le haut
Expand Down
Loading

0 comments on commit b8a1a63

Please sign in to comment.