geforkt von Mirrors/Paper
Add Velocity IP Forwarding Support
While Velocity supports BungeeCord-style IP forwarding, it is not secure. Users have a lot of problems setting up firewalls or setting up plugins like IPWhitelist. Further, the BungeeCord IP forwarding protocol still retains essentially its original form, when there is brand new support for custom login plugin messages in 1.13. Velocity's modern IP forwarding uses an HMAC-SHA256 code to ensure authenticity of messages, is packed into a binary format that is smaller than BungeeCord's forwarding, and is integrated into the Minecraft login process by using the 1.13 login plugin message packet.
Dieser Commit ist enthalten in:
Ursprung
63ca8a9302
Commit
a1051ff388
@ -232,7 +232,7 @@
|
||||
} catch (IOException ioexception) {
|
||||
DedicatedServer.LOGGER.warn("**** FAILED TO BIND TO PORT!");
|
||||
DedicatedServer.LOGGER.warn("The exception was: {}", ioexception.toString());
|
||||
@@ -156,21 +282,31 @@
|
||||
@@ -156,21 +282,38 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -242,14 +242,21 @@
|
||||
+ this.server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.STARTUP);
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
+ // Paper start - Add Velocity IP Forwarding Support
|
||||
+ boolean usingProxy = org.spigotmc.SpigotConfig.bungee || io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled;
|
||||
+ String proxyFlavor = (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled) ? "Velocity" : "BungeeCord";
|
||||
+ String proxyLink = (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled) ? "https://docs.papermc.io/velocity/security" : "http://www.spigotmc.org/wiki/firewall-guide/";
|
||||
+ // Paper end - Add Velocity IP Forwarding Support
|
||||
if (!this.usesAuthentication()) {
|
||||
DedicatedServer.LOGGER.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!");
|
||||
DedicatedServer.LOGGER.warn("The server will make no attempt to authenticate usernames. Beware.");
|
||||
- DedicatedServer.LOGGER.warn("While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect with any username they choose.");
|
||||
+ // Spigot start
|
||||
+ if (org.spigotmc.SpigotConfig.bungee) {
|
||||
+ DedicatedServer.LOGGER.warn("Whilst this makes it possible to use BungeeCord, unless access to your server is properly restricted, it also opens up the ability for hackers to connect with any username they choose.");
|
||||
+ DedicatedServer.LOGGER.warn("Please see http://www.spigotmc.org/wiki/firewall-guide/ for further information.");
|
||||
+ // Paper start - Add Velocity IP Forwarding Support
|
||||
+ if (usingProxy) {
|
||||
+ DedicatedServer.LOGGER.warn("Whilst this makes it possible to use " + proxyFlavor + ", unless access to your server is properly restricted, it also opens up the ability for hackers to connect with any username they choose.");
|
||||
+ DedicatedServer.LOGGER.warn("Please see " + proxyLink + " for further information.");
|
||||
+ // Paper end - Add Velocity IP Forwarding Support
|
||||
+ } else {
|
||||
+ DedicatedServer.LOGGER.warn("While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect with any username they choose.");
|
||||
+ }
|
||||
@ -269,7 +276,7 @@
|
||||
this.debugSampleSubscriptionTracker = new DebugSampleSubscriptionTracker(this.getPlayerList());
|
||||
this.tickTimeLogger = new RemoteSampleLogger(TpsDebugDimensions.values().length, this.debugSampleSubscriptionTracker, RemoteDebugSampleType.TICK_TIME);
|
||||
long i = Util.getNanos();
|
||||
@@ -178,13 +314,13 @@
|
||||
@@ -178,13 +321,13 @@
|
||||
SkullBlockEntity.setup(this.services, this);
|
||||
GameProfileCache.setUsesAuthentication(this.usesAuthentication());
|
||||
DedicatedServer.LOGGER.info("Preparing level \"{}\"", this.getLevelIdName());
|
||||
@ -285,7 +292,7 @@
|
||||
}
|
||||
|
||||
if (dedicatedserverproperties.enableQuery) {
|
||||
@@ -197,7 +333,7 @@
|
||||
@@ -197,7 +340,7 @@
|
||||
this.rconThread = RconThread.create(this);
|
||||
}
|
||||
|
||||
@ -294,7 +301,7 @@
|
||||
Thread thread1 = new Thread(new ServerWatchdog(this));
|
||||
|
||||
thread1.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandlerWithName(DedicatedServer.LOGGER));
|
||||
@@ -215,6 +351,12 @@
|
||||
@@ -215,6 +358,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
@ -307,7 +314,7 @@
|
||||
@Override
|
||||
public boolean isSpawningMonsters() {
|
||||
return this.settings.getProperties().spawnMonsters && super.isSpawningMonsters();
|
||||
@@ -227,7 +369,7 @@
|
||||
@@ -227,7 +376,7 @@
|
||||
|
||||
@Override
|
||||
public void forceDifficulty() {
|
||||
@ -316,7 +323,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -286,13 +428,14 @@
|
||||
@@ -286,13 +435,14 @@
|
||||
}
|
||||
|
||||
if (this.rconThread != null) {
|
||||
@ -333,7 +340,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -302,19 +445,29 @@
|
||||
@@ -302,19 +452,29 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -369,7 +376,7 @@
|
||||
}
|
||||
|
||||
}
|
||||
@@ -383,7 +536,7 @@
|
||||
@@ -383,7 +543,7 @@
|
||||
|
||||
@Override
|
||||
public boolean isUnderSpawnProtection(ServerLevel world, BlockPos pos, Player player) {
|
||||
@ -378,7 +385,7 @@
|
||||
return false;
|
||||
} else if (this.getPlayerList().getOps().isEmpty()) {
|
||||
return false;
|
||||
@@ -453,7 +606,11 @@
|
||||
@@ -453,7 +613,11 @@
|
||||
public boolean enforceSecureProfile() {
|
||||
DedicatedServerProperties dedicatedserverproperties = this.getProperties();
|
||||
|
||||
@ -391,7 +398,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -541,16 +698,52 @@
|
||||
@@ -541,16 +705,52 @@
|
||||
|
||||
@Override
|
||||
public String getPluginNames() {
|
||||
@ -448,7 +455,7 @@
|
||||
}
|
||||
|
||||
public void storeUsingWhiteList(boolean useWhitelist) {
|
||||
@@ -660,4 +853,15 @@
|
||||
@@ -660,4 +860,15 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@
|
||||
private static final int MAX_TICKS_BEFORE_LOGIN = 600;
|
||||
private final byte[] challenge;
|
||||
final MinecraftServer server;
|
||||
@@ -57,9 +86,11 @@
|
||||
@@ -57,9 +86,12 @@
|
||||
@Nullable
|
||||
String requestedUsername;
|
||||
@Nullable
|
||||
@ -66,10 +66,11 @@
|
||||
private final boolean transferred;
|
||||
+ private ServerPlayer player; // CraftBukkit
|
||||
+ public boolean iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation = false; // Paper - username validation overriding
|
||||
+ private int velocityLoginMessageId = -1; // Paper - Add Velocity IP Forwarding Support
|
||||
|
||||
public ServerLoginPacketListenerImpl(MinecraftServer server, Connection connection, boolean transferred) {
|
||||
this.state = ServerLoginPacketListenerImpl.State.HELLO;
|
||||
@@ -72,10 +103,24 @@
|
||||
@@ -72,10 +104,24 @@
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
@ -94,7 +95,7 @@
|
||||
if (this.state == ServerLoginPacketListenerImpl.State.WAITING_FOR_DUPE_DISCONNECT && !this.isPlayerAlreadyInWorld((GameProfile) Objects.requireNonNull(this.authenticatedProfile))) {
|
||||
this.finishLoginAndWaitForClient(this.authenticatedProfile);
|
||||
}
|
||||
@@ -86,6 +131,13 @@
|
||||
@@ -86,6 +132,13 @@
|
||||
|
||||
}
|
||||
|
||||
@ -108,7 +109,7 @@
|
||||
@Override
|
||||
public boolean isAcceptingMessages() {
|
||||
return this.connection.isConnected();
|
||||
@@ -120,7 +172,13 @@
|
||||
@@ -120,7 +173,13 @@
|
||||
@Override
|
||||
public void handleHello(ServerboundHelloPacket packet) {
|
||||
Validate.validState(this.state == ServerLoginPacketListenerImpl.State.HELLO, "Unexpected hello packet", new Object[0]);
|
||||
@ -123,11 +124,21 @@
|
||||
this.requestedUsername = packet.name();
|
||||
GameProfile gameprofile = this.server.getSingleplayerProfile();
|
||||
|
||||
@@ -131,7 +189,26 @@
|
||||
@@ -131,7 +190,36 @@
|
||||
this.state = ServerLoginPacketListenerImpl.State.KEY;
|
||||
this.connection.send(new ClientboundHelloPacket("", this.server.getKeyPair().getPublic().getEncoded(), this.challenge, true));
|
||||
} else {
|
||||
- this.startClientVerification(UUIDUtil.createOfflineProfile(this.requestedUsername));
|
||||
+ // Paper start - Add Velocity IP Forwarding Support
|
||||
+ if (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled) {
|
||||
+ this.velocityLoginMessageId = java.util.concurrent.ThreadLocalRandom.current().nextInt();
|
||||
+ net.minecraft.network.FriendlyByteBuf buf = new net.minecraft.network.FriendlyByteBuf(io.netty.buffer.Unpooled.buffer());
|
||||
+ buf.writeByte(com.destroystokyo.paper.proxy.VelocityProxy.MAX_SUPPORTED_FORWARDING_VERSION);
|
||||
+ net.minecraft.network.protocol.login.ClientboundCustomQueryPacket packet1 = new net.minecraft.network.protocol.login.ClientboundCustomQueryPacket(this.velocityLoginMessageId, new net.minecraft.network.protocol.login.ClientboundCustomQueryPacket.PlayerInfoChannelPayload(com.destroystokyo.paper.proxy.VelocityProxy.PLAYER_INFO_CHANNEL, buf));
|
||||
+ this.connection.send(packet1);
|
||||
+ return;
|
||||
+ }
|
||||
+ // Paper end - Add Velocity IP Forwarding Support
|
||||
+ // CraftBukkit start
|
||||
+ // Paper start - Cache authenticator threads
|
||||
+ authenticatorPool.execute(new Runnable() {
|
||||
@ -151,7 +162,7 @@
|
||||
}
|
||||
|
||||
}
|
||||
@@ -144,10 +221,24 @@
|
||||
@@ -144,10 +232,24 @@
|
||||
|
||||
private void verifyLoginAndFinishConnectionSetup(GameProfile profile) {
|
||||
PlayerList playerlist = this.server.getPlayerList();
|
||||
@ -179,7 +190,7 @@
|
||||
} else {
|
||||
if (this.server.getCompressionThreshold() >= 0 && !this.connection.isMemoryConnection()) {
|
||||
this.connection.send(new ClientboundLoginCompressionPacket(this.server.getCompressionThreshold()), PacketSendListener.thenRun(() -> {
|
||||
@@ -155,12 +246,12 @@
|
||||
@@ -155,12 +257,12 @@
|
||||
}));
|
||||
}
|
||||
|
||||
@ -194,7 +205,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +286,8 @@
|
||||
@@ -195,7 +297,8 @@
|
||||
throw new IllegalStateException("Protocol error", cryptographyexception);
|
||||
}
|
||||
|
||||
@ -204,7 +215,7 @@
|
||||
public void run() {
|
||||
String s1 = (String) Objects.requireNonNull(ServerLoginPacketListenerImpl.this.requestedUsername, "Player name not initialized");
|
||||
|
||||
@@ -205,11 +297,17 @@
|
||||
@@ -205,11 +308,17 @@
|
||||
if (profileresult != null) {
|
||||
GameProfile gameprofile = profileresult.profile();
|
||||
|
||||
@ -223,7 +234,7 @@
|
||||
} else {
|
||||
ServerLoginPacketListenerImpl.this.disconnect(Component.translatable("multiplayer.disconnect.unverified_username"));
|
||||
ServerLoginPacketListenerImpl.LOGGER.error("Username '{}' tried to join with an invalid session", s1);
|
||||
@@ -217,11 +315,16 @@
|
||||
@@ -217,11 +326,16 @@
|
||||
} catch (AuthenticationUnavailableException authenticationunavailableexception) {
|
||||
if (ServerLoginPacketListenerImpl.this.server.isSingleplayer()) {
|
||||
ServerLoginPacketListenerImpl.LOGGER.warn("Authentication servers are down but will let them in anyway!");
|
||||
@ -242,7 +253,7 @@
|
||||
}
|
||||
|
||||
}
|
||||
@@ -232,11 +335,54 @@
|
||||
@@ -232,23 +346,118 @@
|
||||
|
||||
return ServerLoginPacketListenerImpl.this.server.getPreventProxyConnections() && socketaddress instanceof InetSocketAddress ? ((InetSocketAddress) socketaddress).getAddress() : null;
|
||||
}
|
||||
@ -255,6 +266,12 @@
|
||||
- thread.start();
|
||||
+ // CraftBukkit start
|
||||
+ private GameProfile callPlayerPreLoginEvents(GameProfile gameprofile) throws Exception { // Paper - Add more fields to AsyncPlayerPreLoginEvent
|
||||
+ // Paper start - Add Velocity IP Forwarding Support
|
||||
+ if (ServerLoginPacketListenerImpl.this.velocityLoginMessageId == -1 && io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled) {
|
||||
+ disconnect("This server requires you to connect with Velocity.");
|
||||
+ return gameprofile;
|
||||
+ }
|
||||
+ // Paper end - Add Velocity IP Forwarding Support
|
||||
+ String playerName = gameprofile.getName();
|
||||
+ java.net.InetAddress address = ((java.net.InetSocketAddress) this.connection.getRemoteAddress()).getAddress();
|
||||
+ java.util.UUID uniqueId = gameprofile.getId();
|
||||
@ -300,7 +317,53 @@
|
||||
|
||||
@Override
|
||||
public void handleCustomQueryPacket(ServerboundCustomQueryAnswerPacket packet) {
|
||||
@@ -245,10 +391,11 @@
|
||||
+ // Paper start - Add Velocity IP Forwarding Support
|
||||
+ if (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled && packet.transactionId() == this.velocityLoginMessageId) {
|
||||
+ ServerboundCustomQueryAnswerPacket.QueryAnswerPayload payload = (ServerboundCustomQueryAnswerPacket.QueryAnswerPayload)packet.payload();
|
||||
+ if (payload == null) {
|
||||
+ this.disconnect("This server requires you to connect with Velocity.");
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ net.minecraft.network.FriendlyByteBuf buf = payload.buffer;
|
||||
+
|
||||
+ if (!com.destroystokyo.paper.proxy.VelocityProxy.checkIntegrity(buf)) {
|
||||
+ this.disconnect("Unable to verify player details");
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ int version = buf.readVarInt();
|
||||
+ if (version > com.destroystokyo.paper.proxy.VelocityProxy.MAX_SUPPORTED_FORWARDING_VERSION) {
|
||||
+ throw new IllegalStateException("Unsupported forwarding version " + version + ", wanted upto " + com.destroystokyo.paper.proxy.VelocityProxy.MAX_SUPPORTED_FORWARDING_VERSION);
|
||||
+ }
|
||||
+
|
||||
+ java.net.SocketAddress listening = this.connection.getRemoteAddress();
|
||||
+ int port = 0;
|
||||
+ if (listening instanceof java.net.InetSocketAddress) {
|
||||
+ port = ((java.net.InetSocketAddress) listening).getPort();
|
||||
+ }
|
||||
+ this.connection.address = new java.net.InetSocketAddress(com.destroystokyo.paper.proxy.VelocityProxy.readAddress(buf), port);
|
||||
+
|
||||
+ this.authenticatedProfile = com.destroystokyo.paper.proxy.VelocityProxy.createProfile(buf);
|
||||
+
|
||||
+ //TODO Update handling for lazy sessions, might not even have to do anything?
|
||||
+
|
||||
+ // Proceed with login
|
||||
+ authenticatorPool.execute(() -> {
|
||||
+ try {
|
||||
+ final GameProfile gameprofile = this.callPlayerPreLoginEvents(this.authenticatedProfile);
|
||||
+ ServerLoginPacketListenerImpl.LOGGER.info("UUID of player {} is {}", gameprofile.getName(), gameprofile.getId());
|
||||
+ ServerLoginPacketListenerImpl.this.startClientVerification(gameprofile);
|
||||
+ } catch (Exception ex) {
|
||||
+ disconnect("Failed to verify username!");
|
||||
+ server.server.getLogger().log(java.util.logging.Level.WARNING, "Exception verifying " + this.authenticatedProfile.getName(), ex);
|
||||
+ }
|
||||
+ });
|
||||
+ return;
|
||||
+ }
|
||||
+ // Paper end - Add Velocity IP Forwarding Support
|
||||
this.disconnect(ServerCommonPacketListenerImpl.DISCONNECT_UNEXPECTED_QUERY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleLoginAcknowledgement(ServerboundLoginAcknowledgedPacket packet) {
|
||||
@ -313,7 +376,7 @@
|
||||
|
||||
this.connection.setupInboundProtocol(ConfigurationProtocols.SERVERBOUND, serverconfigurationpacketlistenerimpl);
|
||||
serverconfigurationpacketlistenerimpl.startConfiguration();
|
||||
@@ -264,12 +411,44 @@
|
||||
@@ -264,12 +473,44 @@
|
||||
|
||||
@Override
|
||||
public void handleCookieResponse(ServerboundCookieResponsePacket packet) {
|
||||
|
@ -0,0 +1,86 @@
|
||||
package com.destroystokyo.paper.proxy;
|
||||
|
||||
import io.papermc.paper.configuration.GlobalConfiguration;
|
||||
import com.google.common.net.InetAddresses;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import java.net.InetAddress;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.UUID;
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.protocol.login.custom.CustomQueryPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.ProfilePublicKey;
|
||||
|
||||
/**
|
||||
* While Velocity supports BungeeCord-style IP forwarding, it is not secure. Users
|
||||
* have a lot of problems setting up firewalls or setting up plugins like IPWhitelist.
|
||||
* Further, the BungeeCord IP forwarding protocol still retains essentially its original
|
||||
* form, when there is brand-new support for custom login plugin messages in 1.13.
|
||||
* <p>
|
||||
* Velocity's modern IP forwarding uses an HMAC-SHA256 code to ensure authenticity
|
||||
* of messages, is packed into a binary format that is smaller than BungeeCord's
|
||||
* forwarding, and is integrated into the Minecraft login process by using the 1.13
|
||||
* login plugin message packet.
|
||||
*/
|
||||
public class VelocityProxy {
|
||||
private static final int SUPPORTED_FORWARDING_VERSION = 1;
|
||||
public static final int MODERN_FORWARDING_WITH_KEY = 2;
|
||||
public static final int MODERN_FORWARDING_WITH_KEY_V2 = 3;
|
||||
public static final int MODERN_LAZY_SESSION = 4;
|
||||
public static final byte MAX_SUPPORTED_FORWARDING_VERSION = MODERN_LAZY_SESSION;
|
||||
public static final ResourceLocation PLAYER_INFO_CHANNEL = ResourceLocation.fromNamespaceAndPath("velocity", "player_info");
|
||||
|
||||
public static boolean checkIntegrity(final FriendlyByteBuf buf) {
|
||||
final byte[] signature = new byte[32];
|
||||
buf.readBytes(signature);
|
||||
|
||||
final byte[] data = new byte[buf.readableBytes()];
|
||||
buf.getBytes(buf.readerIndex(), data);
|
||||
|
||||
try {
|
||||
final Mac mac = Mac.getInstance("HmacSHA256");
|
||||
mac.init(new SecretKeySpec(GlobalConfiguration.get().proxies.velocity.secret.getBytes(java.nio.charset.StandardCharsets.UTF_8), "HmacSHA256"));
|
||||
final byte[] mySignature = mac.doFinal(data);
|
||||
if (!MessageDigest.isEqual(signature, mySignature)) {
|
||||
return false;
|
||||
}
|
||||
} catch (final InvalidKeyException | NoSuchAlgorithmException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static InetAddress readAddress(final FriendlyByteBuf buf) {
|
||||
return InetAddresses.forString(buf.readUtf(Short.MAX_VALUE));
|
||||
}
|
||||
|
||||
public static GameProfile createProfile(final FriendlyByteBuf buf) {
|
||||
final GameProfile profile = new GameProfile(buf.readUUID(), buf.readUtf(16));
|
||||
readProperties(buf, profile);
|
||||
return profile;
|
||||
}
|
||||
|
||||
private static void readProperties(final FriendlyByteBuf buf, final GameProfile profile) {
|
||||
final int properties = buf.readVarInt();
|
||||
for (int i1 = 0; i1 < properties; i1++) {
|
||||
final String name = buf.readUtf(Short.MAX_VALUE);
|
||||
final String value = buf.readUtf(Short.MAX_VALUE);
|
||||
final String signature = buf.readBoolean() ? buf.readUtf(Short.MAX_VALUE) : null;
|
||||
profile.getProperties().put(name, new Property(name, value, signature));
|
||||
}
|
||||
}
|
||||
|
||||
public static ProfilePublicKey.Data readForwardedKey(FriendlyByteBuf buf) {
|
||||
return new ProfilePublicKey.Data(buf);
|
||||
}
|
||||
|
||||
public static UUID readSignerUuidOrElse(FriendlyByteBuf buf, UUID orElse) {
|
||||
return buf.readBoolean() ? buf.readUUID() : orElse;
|
||||
}
|
||||
}
|
@ -848,7 +848,7 @@ public final class CraftServer implements Server {
|
||||
@Override
|
||||
public long getConnectionThrottle() {
|
||||
// Spigot Start - Automatically set connection throttle for bungee configurations
|
||||
if (org.spigotmc.SpigotConfig.bungee) {
|
||||
if (org.spigotmc.SpigotConfig.bungee || io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled) { // Paper - Add Velocity IP Forwarding Support
|
||||
return -1;
|
||||
} else {
|
||||
return this.configuration.getInt("settings.connection-throttle");
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren