From 83dc862c65b03fd49ba5ce318e16f6d298195078 Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Wed, 11 Jan 2023 20:02:03 +0100 Subject: [PATCH] Migrated from Steveice10 MCAuthLib to Mojang AuthLib --- build.gradle | 25 ++++++++++--- gradle.properties | 2 +- .../java/net/raphimc/viaproxy/ViaProxy.java | 5 ++- .../YggdrasilServicesKeyInfoTransformer.java | 24 +++++++++++++ .../providers/ViaProxyGameProfileFetcher.java | 33 ++++++++--------- .../providers/ViaProxyOldAuthProvider.java | 2 +- .../viaproxy/proxy/ProxyConnection.java | 5 +-- .../client2proxy/Client2ProxyHandler.java | 13 +++---- .../external_interface/AuthLibServices.java | 17 +++++++++ .../ExternalInterface.java | 35 ++++++------------- .../OpenAuthModConstants.java | 20 +++++++++++ .../proxy2server/Proxy2ServerHandler.java | 4 +-- .../raphimc/viaproxy/util/logging/Logger.java | 2 +- 13 files changed, 127 insertions(+), 60 deletions(-) create mode 100644 src/main/java/net/raphimc/viaproxy/injection/transformer/YggdrasilServicesKeyInfoTransformer.java create mode 100644 src/main/java/net/raphimc/viaproxy/proxy/external_interface/AuthLibServices.java rename src/main/java/net/raphimc/viaproxy/proxy/{ => external_interface}/ExternalInterface.java (74%) create mode 100644 src/main/java/net/raphimc/viaproxy/proxy/external_interface/OpenAuthModConstants.java diff --git a/build.gradle b/build.gradle index 3578537..b8abc4f 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,9 @@ plugins { id "net.kyori.blossom" version "1.3.1" } -java.toolchain.languageVersion = JavaLanguageVersion.of(8) +java.toolchain.languageVersion = JavaLanguageVersion.of(17) +compileJava.sourceCompatibility = JavaVersion.VERSION_1_8 +compileJava.targetCompatibility = JavaVersion.VERSION_1_8 compileJava.options.encoding = compileTestJava.options.encoding = javadoc.options.encoding = "UTF-8" group = project.maven_group @@ -32,6 +34,19 @@ repositories { name = "ViaVersion" url "https://repo.viaversion.com" } + ivy { // This workaround is needed as gradle does not allow to include Java 17 dependencies in a Java 8 project + name = "Mojang" + url "https://libraries.minecraft.net" + patternLayout { + artifact MAVEN_ARTIFACT_PATTERN + } + metadataSources { + it.artifact() + } + content { + includeGroup "com/mojang" + } + } } dependencies { @@ -43,19 +58,19 @@ dependencies { } include "com.viaversion:viarewind-core:2.0.3-SNAPSHOT" include "net.raphimc:ViaLegacy:2.1.0" - include("net.raphimc:ViaProtocolHack:2.1.0") { + include("net.raphimc:ViaProtocolHack:2.1.1") { exclude group: "org.slf4j", module: "slf4j-api" } include "com.google.code.gson:gson:2.10.1" include "com.formdev:flatlaf:3.0" include "com.google.guava:guava:31.1-jre" + include "org.apache.commons:commons-lang3:3.12.0" + include "commons-io:commons-io:2.11.0" include "net.sf.jopt-simple:jopt-simple:5.0.4" include "org.apache.logging.log4j:log4j-core:2.19.0" include "org.apache.logging.log4j:log4j-slf4j-impl:2.19.0" - include("com.github.GeyserMC:MCAuthLib:1.4") { - exclude group: "com.google.code.gson", module: "gson" - } + include "com/mojang:authlib:3.16.29" include "net.lenni0451.classtransform:mixinstranslator:1.7.7" include "net.lenni0451.classtransform:mixinsdummy:1.7.7" include "net.lenni0451.classtransform:additionalclassprovider:1.7.7" diff --git a/gradle.properties b/gradle.properties index d755640..c5bd1bb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ org.gradle.configureondemand=true # Project properties maven_name=ViaProxy maven_group=net.raphimc -maven_version=3.0.6 +maven_version=3.0.7 diff --git a/src/main/java/net/raphimc/viaproxy/ViaProxy.java b/src/main/java/net/raphimc/viaproxy/ViaProxy.java index 6b000a8..67dad11 100644 --- a/src/main/java/net/raphimc/viaproxy/ViaProxy.java +++ b/src/main/java/net/raphimc/viaproxy/ViaProxy.java @@ -12,6 +12,7 @@ import net.lenni0451.classtransform.additionalclassprovider.GuavaClassPathProvid import net.lenni0451.classtransform.mixinstranslator.MixinsTranslator; import net.lenni0451.classtransform.utils.loader.EnumLoaderPriority; import net.lenni0451.classtransform.utils.loader.InjectionClassLoader; +import net.lenni0451.classtransform.utils.tree.IClassProvider; import net.lenni0451.reflect.ClassLoaders; import net.raphimc.netminecraft.constants.MCPipeline; import net.raphimc.netminecraft.netty.connection.NetServer; @@ -41,7 +42,8 @@ public class ViaProxy { public static ChannelGroup c2pChannels; public static void main(String[] args) throws Throwable { - final TransformerManager transformerManager = new TransformerManager(new GuavaClassPathProvider()); + final IClassProvider classProvider = new GuavaClassPathProvider(); + final TransformerManager transformerManager = new TransformerManager(classProvider); transformerManager.addTransformerPreprocessor(new MixinsTranslator()); transformerManager.addTransformer("net.raphimc.viaproxy.injection.transformer.**"); transformerManager.addTransformer("net.raphimc.viaproxy.injection.mixins.**"); @@ -66,6 +68,7 @@ public class ViaProxy { }, "ViaProtocolHack-Loader"); Thread accountRefreshThread = new Thread(() -> { saveManager.accountsSave.refreshAccounts(); + saveManager.save(); }, "AccountRefresh"); Thread updateCheckThread = new Thread(() -> { if (VERSION.startsWith("$")) return; // Dev env check diff --git a/src/main/java/net/raphimc/viaproxy/injection/transformer/YggdrasilServicesKeyInfoTransformer.java b/src/main/java/net/raphimc/viaproxy/injection/transformer/YggdrasilServicesKeyInfoTransformer.java new file mode 100644 index 0000000..1f0f07b --- /dev/null +++ b/src/main/java/net/raphimc/viaproxy/injection/transformer/YggdrasilServicesKeyInfoTransformer.java @@ -0,0 +1,24 @@ +package net.raphimc.viaproxy.injection.transformer; + +import com.mojang.authlib.yggdrasil.ServicesKeyInfo; +import com.mojang.authlib.yggdrasil.YggdrasilServicesKeyInfo; +import net.lenni0451.classtransform.annotations.CTransformer; +import net.lenni0451.classtransform.annotations.injection.COverride; +import net.lenni0451.reflect.stream.RStream; +import net.raphimc.netminecraft.netty.crypto.CryptUtil; + +import java.security.PublicKey; + +@CTransformer(YggdrasilServicesKeyInfo.class) +public abstract class YggdrasilServicesKeyInfoTransformer { + + @COverride + public static ServicesKeyInfo createFromResources() { + try { + return RStream.of(YggdrasilServicesKeyInfo.class).constructors().by(PublicKey.class).newInstance(CryptUtil.MOJANG_PUBLIC_KEY); + } catch (Throwable e) { + throw new AssertionError("Missing/invalid yggdrasil public key!", e); + } + } + +} diff --git a/src/main/java/net/raphimc/viaproxy/protocolhack/providers/ViaProxyGameProfileFetcher.java b/src/main/java/net/raphimc/viaproxy/protocolhack/providers/ViaProxyGameProfileFetcher.java index 54afe88..8e43667 100644 --- a/src/main/java/net/raphimc/viaproxy/protocolhack/providers/ViaProxyGameProfileFetcher.java +++ b/src/main/java/net/raphimc/viaproxy/protocolhack/providers/ViaProxyGameProfileFetcher.java @@ -1,32 +1,31 @@ package net.raphimc.viaproxy.protocolhack.providers; -import com.github.steveice10.mc.auth.exception.profile.ProfileException; -import com.github.steveice10.mc.auth.exception.profile.ProfileNotFoundException; -import com.github.steveice10.mc.auth.service.ProfileService; -import com.github.steveice10.mc.auth.service.SessionService; +import com.mojang.authlib.Agent; +import com.mojang.authlib.ProfileLookupCallback; +import com.mojang.authlib.properties.Property; +import com.mojang.authlib.yggdrasil.ProfileNotFoundException; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.model.GameProfile; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.providers.GameProfileFetcher; +import net.raphimc.viaproxy.proxy.external_interface.AuthLibServices; +import java.util.Map; import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; public class ViaProxyGameProfileFetcher extends GameProfileFetcher { - public static SessionService sessionService = new SessionService(); - public static ProfileService profileService = new ProfileService(); - @Override public UUID loadMojangUUID(String playerName) throws ExecutionException, InterruptedException { - final CompletableFuture future = new CompletableFuture<>(); - profileService.findProfilesByName(new String[]{playerName}, new ProfileService.ProfileLookupCallback() { + final CompletableFuture future = new CompletableFuture<>(); + AuthLibServices.gameProfileRepository.findProfilesByNames(new String[]{playerName}, Agent.MINECRAFT, new ProfileLookupCallback() { @Override - public void onProfileLookupSucceeded(com.github.steveice10.mc.auth.data.GameProfile profile) { - future.complete(profile); + public void onProfileLookupSucceeded(com.mojang.authlib.GameProfile gameProfile) { + future.complete(gameProfile); } @Override - public void onProfileLookupFailed(com.github.steveice10.mc.auth.data.GameProfile profile, Exception e) { + public void onProfileLookupFailed(com.mojang.authlib.GameProfile gameProfile, Exception e) { future.completeExceptionally(e); } }); @@ -37,12 +36,14 @@ public class ViaProxyGameProfileFetcher extends GameProfileFetcher { } @Override - public GameProfile loadGameProfile(UUID uuid) throws ProfileException { - final com.github.steveice10.mc.auth.data.GameProfile inProfile = new com.github.steveice10.mc.auth.data.GameProfile(uuid, null); - final com.github.steveice10.mc.auth.data.GameProfile mojangProfile = sessionService.fillProfileProperties(inProfile); + public GameProfile loadGameProfile(UUID uuid) { + final com.mojang.authlib.GameProfile inProfile = new com.mojang.authlib.GameProfile(uuid, null); + final com.mojang.authlib.GameProfile mojangProfile = AuthLibServices.sessionService.fillProfileProperties(inProfile, true); + if (mojangProfile.equals(inProfile)) throw new ProfileNotFoundException(); final GameProfile gameProfile = new GameProfile(mojangProfile.getName(), mojangProfile.getId()); - for (com.github.steveice10.mc.auth.data.GameProfile.Property prop : mojangProfile.getProperties()) { + for (Map.Entry entry : mojangProfile.getProperties().entries()) { + final Property prop = entry.getValue(); gameProfile.addProperty(new GameProfile.Property(prop.getName(), prop.getValue(), prop.getSignature())); } return gameProfile; diff --git a/src/main/java/net/raphimc/viaproxy/protocolhack/providers/ViaProxyOldAuthProvider.java b/src/main/java/net/raphimc/viaproxy/protocolhack/providers/ViaProxyOldAuthProvider.java index 396ae9e..258e0d5 100644 --- a/src/main/java/net/raphimc/viaproxy/protocolhack/providers/ViaProxyOldAuthProvider.java +++ b/src/main/java/net/raphimc/viaproxy/protocolhack/providers/ViaProxyOldAuthProvider.java @@ -2,8 +2,8 @@ package net.raphimc.viaproxy.protocolhack.providers; import com.viaversion.viaversion.api.connection.UserConnection; import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.providers.OldAuthProvider; -import net.raphimc.viaproxy.proxy.ExternalInterface; import net.raphimc.viaproxy.proxy.ProxyConnection; +import net.raphimc.viaproxy.proxy.external_interface.ExternalInterface; public class ViaProxyOldAuthProvider extends OldAuthProvider { diff --git a/src/main/java/net/raphimc/viaproxy/proxy/ProxyConnection.java b/src/main/java/net/raphimc/viaproxy/proxy/ProxyConnection.java index 96da01f..2f0b26b 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/ProxyConnection.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/ProxyConnection.java @@ -1,6 +1,6 @@ package net.raphimc.viaproxy.proxy; -import com.github.steveice10.mc.auth.data.GameProfile; +import com.mojang.authlib.GameProfile; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.libs.gson.JsonObject; import com.viaversion.viaversion.libs.gson.JsonPrimitive; @@ -24,6 +24,7 @@ import net.raphimc.netminecraft.packet.impl.status.S2CStatusResponsePacket; import net.raphimc.netminecraft.packet.registry.PacketRegistryUtil; import net.raphimc.netminecraft.util.ServerAddress; import net.raphimc.viaprotocolhack.util.VersionEnum; +import net.raphimc.viaproxy.proxy.external_interface.OpenAuthModConstants; import net.raphimc.viaproxy.proxy.util.CloseAndReturn; import net.raphimc.viaproxy.util.logging.Logger; @@ -185,7 +186,7 @@ public class ProxyConnection extends NetClient { PacketTypes.writeString(disconnectPacketData, channel); PacketTypes.writeVarInt(disconnectPacketData, id); disconnectPacketData.writeBytes(data); - this.c2p.writeAndFlush(new S2CLoginDisconnectPacket(messageToJson("§cYou need to install OpenAuthMod in order to join this server.§k\n" + Base64.getEncoder().encodeToString(ByteBufUtil.getBytes(disconnectPacketData)) + "\n" + ExternalInterface.OPENAUTHMOD_LEGACY_MAGIC_STRING))).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); + this.c2p.writeAndFlush(new S2CLoginDisconnectPacket(messageToJson("§cYou need to install OpenAuthMod in order to join this server.§k\n" + Base64.getEncoder().encodeToString(ByteBufUtil.getBytes(disconnectPacketData)) + "\n" + OpenAuthModConstants.LEGACY_MAGIC_STRING))).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); } break; case PLAY: diff --git a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java index 2e67ab2..f805fdd 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java @@ -23,10 +23,11 @@ import net.raphimc.viaproxy.ViaProxy; import net.raphimc.viaproxy.cli.options.Options; import net.raphimc.viaproxy.plugins.PluginManager; import net.raphimc.viaproxy.plugins.events.PreConnectEvent; -import net.raphimc.viaproxy.protocolhack.providers.ViaProxyGameProfileFetcher; -import net.raphimc.viaproxy.proxy.ExternalInterface; import net.raphimc.viaproxy.proxy.LoginState; import net.raphimc.viaproxy.proxy.ProxyConnection; +import net.raphimc.viaproxy.proxy.external_interface.AuthLibServices; +import net.raphimc.viaproxy.proxy.external_interface.ExternalInterface; +import net.raphimc.viaproxy.proxy.external_interface.OpenAuthModConstants; import net.raphimc.viaproxy.proxy.proxy2server.Proxy2ServerChannelInitializer; import net.raphimc.viaproxy.proxy.proxy2server.Proxy2ServerHandler; import net.raphimc.viaproxy.proxy.util.CloseAndReturn; @@ -225,7 +226,7 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler { } private void handleLoginKey(final C2SLoginKeyPacket1_7 packet) throws GeneralSecurityException, InterruptedException { - if (this.proxyConnection.getClientVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2) && new String(packet.encryptedNonce, StandardCharsets.UTF_8).equals(ExternalInterface.OPENAUTHMOD_DATA_CHANNEL)) { // 1.8-1.12.2 OpenAuthMod response handling + if (this.proxyConnection.getClientVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2) && new String(packet.encryptedNonce, StandardCharsets.UTF_8).equals(OpenAuthModConstants.DATA_CHANNEL)) { // 1.8-1.12.2 OpenAuthMod response handling final ByteBuf byteBuf = Unpooled.wrappedBuffer(packet.encryptedSecretKey); this.proxyConnection.handleCustomPayload(PacketTypes.readVarInt(byteBuf), byteBuf); return; @@ -255,12 +256,12 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler { try { final String serverHash = new BigInteger(CryptUtil.computeServerIdHash("", KEY_PAIR.getPublic(), secretKey)).toString(16); - this.proxyConnection.setGameProfile(ViaProxyGameProfileFetcher.sessionService.getProfileByServer(userName, serverHash)); + this.proxyConnection.setGameProfile(AuthLibServices.sessionService.hasJoinedServer(this.proxyConnection.getGameProfile(), serverHash, this.proxyConnection.getC2P().remoteAddress().getAddress())); if (this.proxyConnection.getGameProfile() == null) { Logger.u_err("auth", this.proxyConnection.getC2P().remoteAddress(), this.proxyConnection.getGameProfile(), "Invalid session"); this.proxyConnection.kickClient("§cInvalid session! Please restart minecraft (and the launcher) and try again."); } - Logger.u_info("auth", this.proxyConnection.getC2P().remoteAddress(), this.proxyConnection.getGameProfile(), "Authenticated as " + this.proxyConnection.getGameProfile().getIdAsString()); + Logger.u_info("auth", this.proxyConnection.getC2P().remoteAddress(), this.proxyConnection.getGameProfile(), "Authenticated as " + this.proxyConnection.getGameProfile().getId().toString()); } catch (Throwable e) { throw new RuntimeException("Failed to make session request for user '" + userName + "'!", e); } @@ -276,7 +277,7 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler { private boolean handlePlayCustomPayload(final ByteBuf packet) { final String channel = PacketTypes.readString(packet, Short.MAX_VALUE); // channel - if (channel.equals(ExternalInterface.OPENAUTHMOD_DATA_CHANNEL)) { + if (channel.equals(OpenAuthModConstants.DATA_CHANNEL)) { return this.proxyConnection.handleCustomPayload(PacketTypes.readVarInt(packet), packet); } return false; diff --git a/src/main/java/net/raphimc/viaproxy/proxy/external_interface/AuthLibServices.java b/src/main/java/net/raphimc/viaproxy/proxy/external_interface/AuthLibServices.java new file mode 100644 index 0000000..b6ceb0c --- /dev/null +++ b/src/main/java/net/raphimc/viaproxy/proxy/external_interface/AuthLibServices.java @@ -0,0 +1,17 @@ +package net.raphimc.viaproxy.proxy.external_interface; + +import com.mojang.authlib.GameProfileRepository; +import com.mojang.authlib.HttpAuthenticationService; +import com.mojang.authlib.minecraft.MinecraftSessionService; +import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService; + +import java.net.Proxy; +import java.util.UUID; + +public class AuthLibServices { + + public static final HttpAuthenticationService authenticationService = new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString()); + public static final MinecraftSessionService sessionService = authenticationService.createMinecraftSessionService(); + public static final GameProfileRepository gameProfileRepository = authenticationService.createProfileRepository(); + +} diff --git a/src/main/java/net/raphimc/viaproxy/proxy/ExternalInterface.java b/src/main/java/net/raphimc/viaproxy/proxy/external_interface/ExternalInterface.java similarity index 74% rename from src/main/java/net/raphimc/viaproxy/proxy/ExternalInterface.java rename to src/main/java/net/raphimc/viaproxy/proxy/external_interface/ExternalInterface.java index 4586e0e..461dd4d 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/ExternalInterface.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/external_interface/ExternalInterface.java @@ -1,7 +1,7 @@ -package net.raphimc.viaproxy.proxy; +package net.raphimc.viaproxy.proxy.external_interface; -import com.github.steveice10.mc.auth.data.GameProfile; -import com.github.steveice10.mc.auth.util.UUIDSerializer; +import com.mojang.authlib.GameProfile; +import com.mojang.util.UUIDTypeAdapter; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import net.raphimc.netminecraft.packet.PacketTypes; @@ -9,12 +9,10 @@ import net.raphimc.netminecraft.packet.impl.login.C2SLoginHelloPacket1_19_3; import net.raphimc.netminecraft.packet.impl.login.C2SLoginHelloPacket1_7; import net.raphimc.netminecraft.packet.impl.login.C2SLoginKeyPacket1_19; import net.raphimc.viaproxy.cli.options.Options; -import net.raphimc.viaproxy.protocolhack.providers.ViaProxyGameProfileFetcher; +import net.raphimc.viaproxy.proxy.ProxyConnection; import net.raphimc.viaproxy.util.LocalSocketClient; import net.raphimc.viaproxy.util.logging.Logger; -import java.math.BigInteger; -import java.nio.charset.StandardCharsets; import java.security.KeyFactory; import java.security.NoSuchAlgorithmException; import java.security.PublicKey; @@ -29,37 +27,24 @@ import java.util.concurrent.TimeoutException; public class ExternalInterface { - public static final String OPENAUTHMOD_BASE_CHANNEL = "oam:"; - public static final byte[] OPENAUTHMOD_LEGACY_MAGIC_BYTES = new byte[]{2, 20, 12, 3}; // 1.8 - 1.12.2 - public static final String OPENAUTHMOD_LEGACY_MAGIC_STRING = new String(OPENAUTHMOD_LEGACY_MAGIC_BYTES, StandardCharsets.UTF_8); // 1.8 - 1.12.2 - public static final int OPENAUTHMOD_LEGACY_MAGIC_INT = new BigInteger(OPENAUTHMOD_LEGACY_MAGIC_BYTES).intValueExact(); // 1.8 - 1.12.2 - - // Request - public static final String OPENAUTHMOD_JOIN_CHANNEL = OPENAUTHMOD_BASE_CHANNEL + "join"; // 1.8 - latest - public static final String OPENAUTHMOD_SIGN_NONCE_CHANNEL = OPENAUTHMOD_BASE_CHANNEL + "sign_nonce"; // 1.19 - latest - - // Response - public static final String OPENAUTHMOD_DATA_CHANNEL = OPENAUTHMOD_BASE_CHANNEL + "data"; // 1.8 - latest - - public static void fillPlayerData(final C2SLoginHelloPacket1_7 loginHello, final ProxyConnection proxyConnection) throws NoSuchAlgorithmException, InvalidKeySpecException { proxyConnection.setLoginHelloPacket(loginHello); if (proxyConnection.getLoginHelloPacket() instanceof C2SLoginHelloPacket1_19_3) { proxyConnection.setGameProfile(new GameProfile(((C2SLoginHelloPacket1_19_3) proxyConnection.getLoginHelloPacket()).uuid, proxyConnection.getLoginHelloPacket().name)); } else { - proxyConnection.setGameProfile(new GameProfile((UUID) null, loginHello.name)); + proxyConnection.setGameProfile(new GameProfile(null, loginHello.name)); } if (Options.LOCAL_SOCKET_AUTH) { String[] response = new LocalSocketClient(48941).request("getusername"); if (response != null && response[0].equals("success")) { - proxyConnection.setGameProfile(new GameProfile((UUID) null, response[1])); + proxyConnection.setGameProfile(new GameProfile(null, response[1])); } response = new LocalSocketClient(48941).request("get_public_key_data"); if (response != null && response[0].equals("success")) { final String name = proxyConnection.getGameProfile().getName(); - final UUID uuid = UUIDSerializer.fromString(response[1].replaceFirst("(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)", "$1-$2-$3-$4-$5")); + final UUID uuid = UUIDTypeAdapter.fromString(response[1]); final PublicKey publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(Base64.getDecoder().decode(response[2]))); final byte[] keySignature = Base64.getDecoder().decode(response[3]); final Instant expiresAt = Instant.ofEpochMilli(Long.parseLong(response[4])); @@ -82,7 +67,7 @@ public class ExternalInterface { Logger.u_info("auth", proxyConnection.getC2P().remoteAddress(), proxyConnection.getGameProfile(), "Trying to join online mode server"); if (Options.OPENAUTHMOD_AUTH) { try { - final ByteBuf response = proxyConnection.sendCustomPayload(OPENAUTHMOD_JOIN_CHANNEL, PacketTypes.writeString(Unpooled.buffer(), serverIdHash)).get(6, TimeUnit.SECONDS); + final ByteBuf response = proxyConnection.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) { @@ -92,7 +77,7 @@ public class ExternalInterface { new LocalSocketClient(48941).request("authenticate", serverIdHash); } else if (Options.MC_ACCOUNT != null && !Options.MC_ACCOUNT.prevResult().items().isEmpty()) { try { - ViaProxyGameProfileFetcher.sessionService.joinServer(new GameProfile(Options.MC_ACCOUNT.id(), Options.MC_ACCOUNT.name()), Options.MC_ACCOUNT.prevResult().prevResult().access_token(), serverIdHash); + AuthLibServices.sessionService.joinServer(new GameProfile(Options.MC_ACCOUNT.id(), Options.MC_ACCOUNT.name()), Options.MC_ACCOUNT.prevResult().prevResult().access_token(), serverIdHash); } catch (Throwable e) { proxyConnection.kickClient("§cFailed to authenticate with Mojang servers! Please try again later."); } @@ -105,7 +90,7 @@ public class ExternalInterface { Logger.u_info("auth", proxyConnection.getC2P().remoteAddress(), proxyConnection.getGameProfile(), "Requesting nonce signature"); if (Options.OPENAUTHMOD_AUTH) { try { - final ByteBuf response = proxyConnection.sendCustomPayload(OPENAUTHMOD_SIGN_NONCE_CHANNEL, PacketTypes.writeByteArray(Unpooled.buffer(), nonce)).get(5, TimeUnit.SECONDS); + final ByteBuf response = proxyConnection.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(); diff --git a/src/main/java/net/raphimc/viaproxy/proxy/external_interface/OpenAuthModConstants.java b/src/main/java/net/raphimc/viaproxy/proxy/external_interface/OpenAuthModConstants.java new file mode 100644 index 0000000..af7c903 --- /dev/null +++ b/src/main/java/net/raphimc/viaproxy/proxy/external_interface/OpenAuthModConstants.java @@ -0,0 +1,20 @@ +package net.raphimc.viaproxy.proxy.external_interface; + +import java.math.BigInteger; +import java.nio.charset.StandardCharsets; + +public class OpenAuthModConstants { + + public static final String BASE_CHANNEL = "oam:"; + public static final byte[] LEGACY_MAGIC_BYTES = new byte[]{2, 20, 12, 3}; // 1.8 - 1.12.2 + public static final String LEGACY_MAGIC_STRING = new String(LEGACY_MAGIC_BYTES, StandardCharsets.UTF_8); // 1.8 - 1.12.2 + public static final int LEGACY_MAGIC_INT = -new BigInteger(LEGACY_MAGIC_BYTES).intValueExact(); // 1.8 - 1.12.2 + + // Request + public static final String JOIN_CHANNEL = BASE_CHANNEL + "join"; // 1.8 - latest + public static final String SIGN_NONCE_CHANNEL = BASE_CHANNEL + "sign_nonce"; // 1.19 - latest + + // Response + public static final String DATA_CHANNEL = BASE_CHANNEL + "data"; // 1.8 - latest + +} diff --git a/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/Proxy2ServerHandler.java b/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/Proxy2ServerHandler.java index 9d6e3e3..12b19fa 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/Proxy2ServerHandler.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/proxy2server/Proxy2ServerHandler.java @@ -1,6 +1,6 @@ package net.raphimc.viaproxy.proxy.proxy2server; -import com.github.steveice10.mc.auth.data.GameProfile; +import com.mojang.authlib.GameProfile; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; @@ -13,8 +13,8 @@ import net.raphimc.netminecraft.packet.impl.login.*; import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ProtocolMetadataStorage; import net.raphimc.viaprotocolhack.util.VersionEnum; import net.raphimc.viaproxy.cli.options.Options; -import net.raphimc.viaproxy.proxy.ExternalInterface; import net.raphimc.viaproxy.proxy.ProxyConnection; +import net.raphimc.viaproxy.proxy.external_interface.ExternalInterface; import net.raphimc.viaproxy.proxy.util.ExceptionUtil; import net.raphimc.viaproxy.util.logging.Logger; diff --git a/src/main/java/net/raphimc/viaproxy/util/logging/Logger.java b/src/main/java/net/raphimc/viaproxy/util/logging/Logger.java index 5b5bee5..500e7be 100644 --- a/src/main/java/net/raphimc/viaproxy/util/logging/Logger.java +++ b/src/main/java/net/raphimc/viaproxy/util/logging/Logger.java @@ -1,6 +1,6 @@ package net.raphimc.viaproxy.util.logging; -import com.github.steveice10.mc.auth.data.GameProfile; +import com.mojang.authlib.GameProfile; import com.viaversion.viaversion.api.connection.UserConnection; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager;