Skip to content

Commit

Permalink
Add option to forward the connection hostname over to the remote serv…
Browse files Browse the repository at this point in the history
…er (#2149)

Co-authored-by: Camotoy <[email protected]>
  • Loading branch information
rtm516 and Camotoy authored Apr 21, 2021
1 parent bb41c0f commit f0a002f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ interface IRemoteConfiguration {
boolean isPasswordAuthentication();

boolean isUseProxyProtocol();

boolean isForwardHost();
}

interface IUserAuthenticationInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ public static class RemoteConfiguration implements IRemoteConfiguration {

@JsonProperty("use-proxy-protocol")
private boolean useProxyProtocol = false;

@JsonProperty("forward-hostname")
private boolean forwardHost = false;
}

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,26 +693,41 @@ private void connectDownstream() {
@Override
public void packetSending(PacketSendingEvent event) {
//todo move this somewhere else
if (event.getPacket() instanceof HandshakePacket && floodgate) {
String encrypted = "";
try {
encrypted = EncryptionUtil.encryptBedrockData(publicKey, new BedrockData(
clientData.getGameVersion(),
authData.getName(),
authData.getXboxUUID(),
clientData.getDeviceOS().ordinal(),
clientData.getLanguageCode(),
clientData.getCurrentInputMode().ordinal(),
upstream.getAddress().getAddress().getHostAddress()
));
} catch (Exception e) {
connector.getLogger().error(LanguageUtils.getLocaleStringLog("geyser.auth.floodgate.encrypt_fail"), e);
if (event.getPacket() instanceof HandshakePacket) {
String addressSuffix;
if (floodgate) {
String encrypted = "";
try {
encrypted = EncryptionUtil.encryptBedrockData(publicKey, new BedrockData(
clientData.getGameVersion(),
authData.getName(),
authData.getXboxUUID(),
clientData.getDeviceOS().ordinal(),
clientData.getLanguageCode(),
clientData.getCurrentInputMode().ordinal(),
upstream.getAddress().getAddress().getHostAddress()
));
} catch (Exception e) {
connector.getLogger().error(LanguageUtils.getLocaleStringLog("geyser.auth.floodgate.encrypt_fail"), e);
}

addressSuffix = '\0' + BedrockData.FLOODGATE_IDENTIFIER + '\0' + encrypted;
} else {
addressSuffix = "";
}

HandshakePacket handshakePacket = event.getPacket();

String address;
if (connector.getConfig().getRemote().isForwardHost()) {
address = clientData.getServerAddress().split(":")[0];
} else {
address = handshakePacket.getHostname();
}

event.setPacket(new HandshakePacket(
handshakePacket.getProtocolVersion(),
handshakePacket.getHostname() + '\0' + BedrockData.FLOODGATE_IDENTIFIER + '\0' + encrypted,
address + addressSuffix,
handshakePacket.getPort(),
handshakePacket.getIntent()
));
Expand Down
3 changes: 3 additions & 0 deletions connector/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ remote:
# 2) You run Velocity or BungeeCord with the option enabled in the proxy's main config.
# IF YOU DON'T KNOW WHAT THIS IS, DON'T TOUCH IT!
use-proxy-protocol: false
# Forward the hostname that the Bedrock client used to connect over to the Java server
# This is designed to be used for forced hosts on proxies
forward-hostname: false

# Floodgate uses encryption to ensure use from authorised sources.
# This should point to the public key generated by Floodgate (Bungee or CraftBukkit)
Expand Down

0 comments on commit f0a002f

Please sign in to comment.