mirror of
https://github.com/GeyserMC/Floodgate.git
synced 2026-01-06 15:42:03 +00:00
Generate new key when converting a pre-rewrite config. Bumped Geyser
This commit is contained in:
@@ -72,7 +72,7 @@ public final class ConfigLoader {
|
||||
try {
|
||||
// check and update if the config is outdated
|
||||
if (!newConfig) {
|
||||
updater.update(defaultConfigName);
|
||||
updater.update(this, defaultConfigName);
|
||||
}
|
||||
|
||||
FloodgateConfig config = ConfigInitializer.initializeFrom(
|
||||
@@ -93,31 +93,7 @@ public final class ConfigLoader {
|
||||
Path keyPath = dataFolder.resolve(configInstance.getKeyFileName());
|
||||
// don't assume that the key always exists with the existence of a config
|
||||
if (!Files.exists(keyPath)) {
|
||||
try {
|
||||
Key key = keyProducer.produce();
|
||||
cipher.init(key);
|
||||
|
||||
String test = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
byte[] encrypted = cipher.encryptFromString(test);
|
||||
String decrypted = cipher.decryptToString(encrypted);
|
||||
|
||||
if (!test.equals(decrypted)) {
|
||||
logger.error("Whoops, we tested the generated Floodgate keys but " +
|
||||
"the decrypted test message doesn't match the original.\n" +
|
||||
"Original message: " + test + "." +
|
||||
"Decrypted message: " + decrypted + ".\n" +
|
||||
"The encrypted message itself: " + new String(encrypted)
|
||||
);
|
||||
throw new RuntimeException(
|
||||
"Tested the generated public and private key but, " +
|
||||
"the decrypted message doesn't match the original!"
|
||||
);
|
||||
}
|
||||
|
||||
Files.write(keyPath, key.getEncoded());
|
||||
} catch (Exception exception) {
|
||||
logger.error("Error while creating key", exception);
|
||||
}
|
||||
generateKey(keyPath);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -131,4 +107,32 @@ public final class ConfigLoader {
|
||||
|
||||
return configInstance;
|
||||
}
|
||||
|
||||
public void generateKey(Path keyPath) {
|
||||
try {
|
||||
Key key = keyProducer.produce();
|
||||
cipher.init(key);
|
||||
|
||||
String test = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
byte[] encrypted = cipher.encryptFromString(test);
|
||||
String decrypted = cipher.decryptToString(encrypted);
|
||||
|
||||
if (!test.equals(decrypted)) {
|
||||
logger.error("Whoops, we tested the generated Floodgate keys but " +
|
||||
"the decrypted test message doesn't match the original.\n" +
|
||||
"Original message: " + test + "." +
|
||||
"Decrypted message: " + decrypted + ".\n" +
|
||||
"The encrypted message itself: " + new String(encrypted)
|
||||
);
|
||||
throw new RuntimeException(
|
||||
"Tested the generated public and private key but, " +
|
||||
"the decrypted message doesn't match the original!"
|
||||
);
|
||||
}
|
||||
|
||||
Files.write(keyPath, key.getEncoded());
|
||||
} catch (Exception exception) {
|
||||
logger.error("Error while creating key", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.geysermc.floodgate.api.logger.FloodgateLogger;
|
||||
import org.geysermc.floodgate.config.loader.ConfigLoader;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@@ -45,7 +46,7 @@ public final class ConfigUpdater {
|
||||
private final ConfigFileUpdater fileUpdater;
|
||||
private final FloodgateLogger logger;
|
||||
|
||||
public void update(String defaultConfigLocation) {
|
||||
public void update(ConfigLoader loader, String defaultConfigLocation) {
|
||||
Path configLocation = dataFolder.resolve("config.yml");
|
||||
|
||||
Map<String, Object> config;
|
||||
@@ -79,13 +80,27 @@ public final class ConfigUpdater {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
logger.warn("You're using a pre-rewrite config file, please note that Floodgate will " +
|
||||
"throw an exception if you didn't already update your Floodgate key" +
|
||||
"(across all your servers, including Geyser). " +
|
||||
"We'll still try to update the config," +
|
||||
"but please regenerate the keys if it failed before asking for support.");
|
||||
logger.warn("We've detected a pre-rewrite config file, please note that Floodgate " +
|
||||
"doesn't not work properly if you don't update your Floodgate key used on " +
|
||||
"all your servers (including Geyser). We'll try to update your Floodgate " +
|
||||
"config now and we'll also generate a new Floodgate key for you, but if " +
|
||||
"you're running a network or if you're running a Spigot server with " +
|
||||
"Geyser Standalone please update as you'll no longer be able to connect.");
|
||||
renames.put("enabled", "enable"); //todo make dump system and add a boolean 'found-legacy-key' or something like that
|
||||
renames.put("allowed", "allow-linking");
|
||||
|
||||
// relocate the old key so that they can restore it if it was a new key
|
||||
Path keyFilePath = dataFolder.resolve((String) config.get("key-file-name"));
|
||||
if (Files.exists(keyFilePath)) {
|
||||
try {
|
||||
Files.copy(keyFilePath, dataFolder.resolve("old-key.pem"));
|
||||
} catch (IOException exception) {
|
||||
throw new RuntimeException(
|
||||
"Failed to relocate the old key to make place for a new key",
|
||||
exception);
|
||||
}
|
||||
}
|
||||
loader.generateKey(keyFilePath);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user