mirror of
https://github.com/ViaVersion/ViaProxy.git
synced 2024-11-23 16:08:20 -05:00
Migrated from Steveice10 MCAuthLib to Mojang AuthLib
This commit is contained in:
parent
e0aeb095f7
commit
83dc862c65
13 changed files with 127 additions and 60 deletions
25
build.gradle
25
build.gradle
|
@ -4,7 +4,9 @@ plugins {
|
||||||
id "net.kyori.blossom" version "1.3.1"
|
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"
|
compileJava.options.encoding = compileTestJava.options.encoding = javadoc.options.encoding = "UTF-8"
|
||||||
|
|
||||||
group = project.maven_group
|
group = project.maven_group
|
||||||
|
@ -32,6 +34,19 @@ repositories {
|
||||||
name = "ViaVersion"
|
name = "ViaVersion"
|
||||||
url "https://repo.viaversion.com"
|
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 {
|
dependencies {
|
||||||
|
@ -43,19 +58,19 @@ dependencies {
|
||||||
}
|
}
|
||||||
include "com.viaversion:viarewind-core:2.0.3-SNAPSHOT"
|
include "com.viaversion:viarewind-core:2.0.3-SNAPSHOT"
|
||||||
include "net.raphimc:ViaLegacy:2.1.0"
|
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"
|
exclude group: "org.slf4j", module: "slf4j-api"
|
||||||
}
|
}
|
||||||
|
|
||||||
include "com.google.code.gson:gson:2.10.1"
|
include "com.google.code.gson:gson:2.10.1"
|
||||||
include "com.formdev:flatlaf:3.0"
|
include "com.formdev:flatlaf:3.0"
|
||||||
include "com.google.guava:guava:31.1-jre"
|
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 "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-core:2.19.0"
|
||||||
include "org.apache.logging.log4j:log4j-slf4j-impl:2.19.0"
|
include "org.apache.logging.log4j:log4j-slf4j-impl:2.19.0"
|
||||||
include("com.github.GeyserMC:MCAuthLib:1.4") {
|
include "com/mojang:authlib:3.16.29"
|
||||||
exclude group: "com.google.code.gson", module: "gson"
|
|
||||||
}
|
|
||||||
include "net.lenni0451.classtransform:mixinstranslator:1.7.7"
|
include "net.lenni0451.classtransform:mixinstranslator:1.7.7"
|
||||||
include "net.lenni0451.classtransform:mixinsdummy:1.7.7"
|
include "net.lenni0451.classtransform:mixinsdummy:1.7.7"
|
||||||
include "net.lenni0451.classtransform:additionalclassprovider:1.7.7"
|
include "net.lenni0451.classtransform:additionalclassprovider:1.7.7"
|
||||||
|
|
|
@ -6,4 +6,4 @@ org.gradle.configureondemand=true
|
||||||
# Project properties
|
# Project properties
|
||||||
maven_name=ViaProxy
|
maven_name=ViaProxy
|
||||||
maven_group=net.raphimc
|
maven_group=net.raphimc
|
||||||
maven_version=3.0.6
|
maven_version=3.0.7
|
||||||
|
|
|
@ -12,6 +12,7 @@ import net.lenni0451.classtransform.additionalclassprovider.GuavaClassPathProvid
|
||||||
import net.lenni0451.classtransform.mixinstranslator.MixinsTranslator;
|
import net.lenni0451.classtransform.mixinstranslator.MixinsTranslator;
|
||||||
import net.lenni0451.classtransform.utils.loader.EnumLoaderPriority;
|
import net.lenni0451.classtransform.utils.loader.EnumLoaderPriority;
|
||||||
import net.lenni0451.classtransform.utils.loader.InjectionClassLoader;
|
import net.lenni0451.classtransform.utils.loader.InjectionClassLoader;
|
||||||
|
import net.lenni0451.classtransform.utils.tree.IClassProvider;
|
||||||
import net.lenni0451.reflect.ClassLoaders;
|
import net.lenni0451.reflect.ClassLoaders;
|
||||||
import net.raphimc.netminecraft.constants.MCPipeline;
|
import net.raphimc.netminecraft.constants.MCPipeline;
|
||||||
import net.raphimc.netminecraft.netty.connection.NetServer;
|
import net.raphimc.netminecraft.netty.connection.NetServer;
|
||||||
|
@ -41,7 +42,8 @@ public class ViaProxy {
|
||||||
public static ChannelGroup c2pChannels;
|
public static ChannelGroup c2pChannels;
|
||||||
|
|
||||||
public static void main(String[] args) throws Throwable {
|
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.addTransformerPreprocessor(new MixinsTranslator());
|
||||||
transformerManager.addTransformer("net.raphimc.viaproxy.injection.transformer.**");
|
transformerManager.addTransformer("net.raphimc.viaproxy.injection.transformer.**");
|
||||||
transformerManager.addTransformer("net.raphimc.viaproxy.injection.mixins.**");
|
transformerManager.addTransformer("net.raphimc.viaproxy.injection.mixins.**");
|
||||||
|
@ -66,6 +68,7 @@ public class ViaProxy {
|
||||||
}, "ViaProtocolHack-Loader");
|
}, "ViaProtocolHack-Loader");
|
||||||
Thread accountRefreshThread = new Thread(() -> {
|
Thread accountRefreshThread = new Thread(() -> {
|
||||||
saveManager.accountsSave.refreshAccounts();
|
saveManager.accountsSave.refreshAccounts();
|
||||||
|
saveManager.save();
|
||||||
}, "AccountRefresh");
|
}, "AccountRefresh");
|
||||||
Thread updateCheckThread = new Thread(() -> {
|
Thread updateCheckThread = new Thread(() -> {
|
||||||
if (VERSION.startsWith("$")) return; // Dev env check
|
if (VERSION.startsWith("$")) return; // Dev env check
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,32 +1,31 @@
|
||||||
package net.raphimc.viaproxy.protocolhack.providers;
|
package net.raphimc.viaproxy.protocolhack.providers;
|
||||||
|
|
||||||
import com.github.steveice10.mc.auth.exception.profile.ProfileException;
|
import com.mojang.authlib.Agent;
|
||||||
import com.github.steveice10.mc.auth.exception.profile.ProfileNotFoundException;
|
import com.mojang.authlib.ProfileLookupCallback;
|
||||||
import com.github.steveice10.mc.auth.service.ProfileService;
|
import com.mojang.authlib.properties.Property;
|
||||||
import com.github.steveice10.mc.auth.service.SessionService;
|
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.model.GameProfile;
|
||||||
import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.providers.GameProfileFetcher;
|
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.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
public class ViaProxyGameProfileFetcher extends GameProfileFetcher {
|
public class ViaProxyGameProfileFetcher extends GameProfileFetcher {
|
||||||
|
|
||||||
public static SessionService sessionService = new SessionService();
|
|
||||||
public static ProfileService profileService = new ProfileService();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUID loadMojangUUID(String playerName) throws ExecutionException, InterruptedException {
|
public UUID loadMojangUUID(String playerName) throws ExecutionException, InterruptedException {
|
||||||
final CompletableFuture<com.github.steveice10.mc.auth.data.GameProfile> future = new CompletableFuture<>();
|
final CompletableFuture<com.mojang.authlib.GameProfile> future = new CompletableFuture<>();
|
||||||
profileService.findProfilesByName(new String[]{playerName}, new ProfileService.ProfileLookupCallback() {
|
AuthLibServices.gameProfileRepository.findProfilesByNames(new String[]{playerName}, Agent.MINECRAFT, new ProfileLookupCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onProfileLookupSucceeded(com.github.steveice10.mc.auth.data.GameProfile profile) {
|
public void onProfileLookupSucceeded(com.mojang.authlib.GameProfile gameProfile) {
|
||||||
future.complete(profile);
|
future.complete(gameProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
future.completeExceptionally(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -37,12 +36,14 @@ public class ViaProxyGameProfileFetcher extends GameProfileFetcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GameProfile loadGameProfile(UUID uuid) throws ProfileException {
|
public GameProfile loadGameProfile(UUID uuid) {
|
||||||
final com.github.steveice10.mc.auth.data.GameProfile inProfile = new com.github.steveice10.mc.auth.data.GameProfile(uuid, null);
|
final com.mojang.authlib.GameProfile inProfile = new com.mojang.authlib.GameProfile(uuid, null);
|
||||||
final com.github.steveice10.mc.auth.data.GameProfile mojangProfile = sessionService.fillProfileProperties(inProfile);
|
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());
|
final GameProfile gameProfile = new GameProfile(mojangProfile.getName(), mojangProfile.getId());
|
||||||
for (com.github.steveice10.mc.auth.data.GameProfile.Property prop : mojangProfile.getProperties()) {
|
for (Map.Entry<String, Property> entry : mojangProfile.getProperties().entries()) {
|
||||||
|
final Property prop = entry.getValue();
|
||||||
gameProfile.addProperty(new GameProfile.Property(prop.getName(), prop.getValue(), prop.getSignature()));
|
gameProfile.addProperty(new GameProfile.Property(prop.getName(), prop.getValue(), prop.getSignature()));
|
||||||
}
|
}
|
||||||
return gameProfile;
|
return gameProfile;
|
||||||
|
|
|
@ -2,8 +2,8 @@ package net.raphimc.viaproxy.protocolhack.providers;
|
||||||
|
|
||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
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.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.ProxyConnection;
|
||||||
|
import net.raphimc.viaproxy.proxy.external_interface.ExternalInterface;
|
||||||
|
|
||||||
public class ViaProxyOldAuthProvider extends OldAuthProvider {
|
public class ViaProxyOldAuthProvider extends OldAuthProvider {
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package net.raphimc.viaproxy.proxy;
|
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.api.connection.UserConnection;
|
||||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||||
import com.viaversion.viaversion.libs.gson.JsonPrimitive;
|
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.packet.registry.PacketRegistryUtil;
|
||||||
import net.raphimc.netminecraft.util.ServerAddress;
|
import net.raphimc.netminecraft.util.ServerAddress;
|
||||||
import net.raphimc.viaprotocolhack.util.VersionEnum;
|
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.proxy.util.CloseAndReturn;
|
||||||
import net.raphimc.viaproxy.util.logging.Logger;
|
import net.raphimc.viaproxy.util.logging.Logger;
|
||||||
|
|
||||||
|
@ -185,7 +186,7 @@ public class ProxyConnection extends NetClient {
|
||||||
PacketTypes.writeString(disconnectPacketData, channel);
|
PacketTypes.writeString(disconnectPacketData, channel);
|
||||||
PacketTypes.writeVarInt(disconnectPacketData, id);
|
PacketTypes.writeVarInt(disconnectPacketData, id);
|
||||||
disconnectPacketData.writeBytes(data);
|
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;
|
break;
|
||||||
case PLAY:
|
case PLAY:
|
||||||
|
|
|
@ -23,10 +23,11 @@ import net.raphimc.viaproxy.ViaProxy;
|
||||||
import net.raphimc.viaproxy.cli.options.Options;
|
import net.raphimc.viaproxy.cli.options.Options;
|
||||||
import net.raphimc.viaproxy.plugins.PluginManager;
|
import net.raphimc.viaproxy.plugins.PluginManager;
|
||||||
import net.raphimc.viaproxy.plugins.events.PreConnectEvent;
|
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.LoginState;
|
||||||
import net.raphimc.viaproxy.proxy.ProxyConnection;
|
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.Proxy2ServerChannelInitializer;
|
||||||
import net.raphimc.viaproxy.proxy.proxy2server.Proxy2ServerHandler;
|
import net.raphimc.viaproxy.proxy.proxy2server.Proxy2ServerHandler;
|
||||||
import net.raphimc.viaproxy.proxy.util.CloseAndReturn;
|
import net.raphimc.viaproxy.proxy.util.CloseAndReturn;
|
||||||
|
@ -225,7 +226,7 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<IPacket> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleLoginKey(final C2SLoginKeyPacket1_7 packet) throws GeneralSecurityException, InterruptedException {
|
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);
|
final ByteBuf byteBuf = Unpooled.wrappedBuffer(packet.encryptedSecretKey);
|
||||||
this.proxyConnection.handleCustomPayload(PacketTypes.readVarInt(byteBuf), byteBuf);
|
this.proxyConnection.handleCustomPayload(PacketTypes.readVarInt(byteBuf), byteBuf);
|
||||||
return;
|
return;
|
||||||
|
@ -255,12 +256,12 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<IPacket> {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final String serverHash = new BigInteger(CryptUtil.computeServerIdHash("", KEY_PAIR.getPublic(), secretKey)).toString(16);
|
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) {
|
if (this.proxyConnection.getGameProfile() == null) {
|
||||||
Logger.u_err("auth", this.proxyConnection.getC2P().remoteAddress(), this.proxyConnection.getGameProfile(), "Invalid session");
|
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.");
|
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) {
|
} catch (Throwable e) {
|
||||||
throw new RuntimeException("Failed to make session request for user '" + userName + "'!", e);
|
throw new RuntimeException("Failed to make session request for user '" + userName + "'!", e);
|
||||||
}
|
}
|
||||||
|
@ -276,7 +277,7 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<IPacket> {
|
||||||
|
|
||||||
private boolean handlePlayCustomPayload(final ByteBuf packet) {
|
private boolean handlePlayCustomPayload(final ByteBuf packet) {
|
||||||
final String channel = PacketTypes.readString(packet, Short.MAX_VALUE); // channel
|
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 this.proxyConnection.handleCustomPayload(PacketTypes.readVarInt(packet), packet);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
}
|
|
@ -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.mojang.authlib.GameProfile;
|
||||||
import com.github.steveice10.mc.auth.util.UUIDSerializer;
|
import com.mojang.util.UUIDTypeAdapter;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import net.raphimc.netminecraft.packet.PacketTypes;
|
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.C2SLoginHelloPacket1_7;
|
||||||
import net.raphimc.netminecraft.packet.impl.login.C2SLoginKeyPacket1_19;
|
import net.raphimc.netminecraft.packet.impl.login.C2SLoginKeyPacket1_19;
|
||||||
import net.raphimc.viaproxy.cli.options.Options;
|
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.LocalSocketClient;
|
||||||
import net.raphimc.viaproxy.util.logging.Logger;
|
import net.raphimc.viaproxy.util.logging.Logger;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.security.KeyFactory;
|
import java.security.KeyFactory;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
|
@ -29,37 +27,24 @@ import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
public class ExternalInterface {
|
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 {
|
public static void fillPlayerData(final C2SLoginHelloPacket1_7 loginHello, final ProxyConnection proxyConnection) throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||||
proxyConnection.setLoginHelloPacket(loginHello);
|
proxyConnection.setLoginHelloPacket(loginHello);
|
||||||
if (proxyConnection.getLoginHelloPacket() instanceof C2SLoginHelloPacket1_19_3) {
|
if (proxyConnection.getLoginHelloPacket() instanceof C2SLoginHelloPacket1_19_3) {
|
||||||
proxyConnection.setGameProfile(new GameProfile(((C2SLoginHelloPacket1_19_3) proxyConnection.getLoginHelloPacket()).uuid, proxyConnection.getLoginHelloPacket().name));
|
proxyConnection.setGameProfile(new GameProfile(((C2SLoginHelloPacket1_19_3) proxyConnection.getLoginHelloPacket()).uuid, proxyConnection.getLoginHelloPacket().name));
|
||||||
} else {
|
} else {
|
||||||
proxyConnection.setGameProfile(new GameProfile((UUID) null, loginHello.name));
|
proxyConnection.setGameProfile(new GameProfile(null, loginHello.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Options.LOCAL_SOCKET_AUTH) {
|
if (Options.LOCAL_SOCKET_AUTH) {
|
||||||
String[] response = new LocalSocketClient(48941).request("getusername");
|
String[] response = new LocalSocketClient(48941).request("getusername");
|
||||||
if (response != null && response[0].equals("success")) {
|
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");
|
response = new LocalSocketClient(48941).request("get_public_key_data");
|
||||||
if (response != null && response[0].equals("success")) {
|
if (response != null && response[0].equals("success")) {
|
||||||
final String name = proxyConnection.getGameProfile().getName();
|
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 PublicKey publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(Base64.getDecoder().decode(response[2])));
|
||||||
final byte[] keySignature = Base64.getDecoder().decode(response[3]);
|
final byte[] keySignature = Base64.getDecoder().decode(response[3]);
|
||||||
final Instant expiresAt = Instant.ofEpochMilli(Long.parseLong(response[4]));
|
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");
|
Logger.u_info("auth", proxyConnection.getC2P().remoteAddress(), proxyConnection.getGameProfile(), "Trying to join online mode server");
|
||||||
if (Options.OPENAUTHMOD_AUTH) {
|
if (Options.OPENAUTHMOD_AUTH) {
|
||||||
try {
|
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 == null) throw new TimeoutException();
|
||||||
if (response.isReadable() && !response.readBoolean()) throw new TimeoutException();
|
if (response.isReadable() && !response.readBoolean()) throw new TimeoutException();
|
||||||
} catch (TimeoutException e) {
|
} catch (TimeoutException e) {
|
||||||
|
@ -92,7 +77,7 @@ public class ExternalInterface {
|
||||||
new LocalSocketClient(48941).request("authenticate", serverIdHash);
|
new LocalSocketClient(48941).request("authenticate", serverIdHash);
|
||||||
} else if (Options.MC_ACCOUNT != null && !Options.MC_ACCOUNT.prevResult().items().isEmpty()) {
|
} else if (Options.MC_ACCOUNT != null && !Options.MC_ACCOUNT.prevResult().items().isEmpty()) {
|
||||||
try {
|
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) {
|
} catch (Throwable e) {
|
||||||
proxyConnection.kickClient("§cFailed to authenticate with Mojang servers! Please try again later.");
|
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");
|
Logger.u_info("auth", proxyConnection.getC2P().remoteAddress(), proxyConnection.getGameProfile(), "Requesting nonce signature");
|
||||||
if (Options.OPENAUTHMOD_AUTH) {
|
if (Options.OPENAUTHMOD_AUTH) {
|
||||||
try {
|
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 == null) throw new TimeoutException();
|
||||||
if (!response.readBoolean()) throw new TimeoutException();
|
if (!response.readBoolean()) throw new TimeoutException();
|
||||||
packet.salt = response.readLong();
|
packet.salt = response.readLong();
|
|
@ -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
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
package net.raphimc.viaproxy.proxy.proxy2server;
|
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.ChannelFutureListener;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
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.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ProtocolMetadataStorage;
|
||||||
import net.raphimc.viaprotocolhack.util.VersionEnum;
|
import net.raphimc.viaprotocolhack.util.VersionEnum;
|
||||||
import net.raphimc.viaproxy.cli.options.Options;
|
import net.raphimc.viaproxy.cli.options.Options;
|
||||||
import net.raphimc.viaproxy.proxy.ExternalInterface;
|
|
||||||
import net.raphimc.viaproxy.proxy.ProxyConnection;
|
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.proxy.util.ExceptionUtil;
|
||||||
import net.raphimc.viaproxy.util.logging.Logger;
|
import net.raphimc.viaproxy.util.logging.Logger;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package net.raphimc.viaproxy.util.logging;
|
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 com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
import org.apache.logging.log4j.Level;
|
import org.apache.logging.log4j.Level;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
|
Loading…
Reference in a new issue