Skip to content

Commit

Permalink
feat: migrate key if old v4guard folder exists
Browse files Browse the repository at this point in the history
  • Loading branch information
zHackeed committed Dec 3, 2023
1 parent b2888f3 commit e50b281
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/io/v4guard/plugin/core/socket/Backend.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ private void connectToSocketWith(IO.Options options) {

private void initializeSecretKey() {
try {
// Migrate old key, kinda ugly but it works
if (CoreInstance.get().getPlugin().getDataFolder().getParentFile().toPath().resolve("v4Guard").toFile().exists()) {
File oldFolder = CoreInstance.get().getPlugin().getDataFolder().getParentFile().toPath().resolve("v4Guard").toFile();
File keyFile = new File(oldFolder, "vpn.key");

if (keyFile.exists()) {
UnifiedLogger.get().log(Level.INFO, "Migrating old key to new location");

writeSecretKey(Files.readString(keyFile.toPath()));
Files.delete(keyFile.toPath());
Files.delete(oldFolder.toPath());
}
}


File keyFile = new File(CoreInstance.get().getPlugin().getDataFolder(), "secret.key");
String secretKey = null;

Expand Down

0 comments on commit e50b281

Please sign in to comment.