diff --git a/build.gradle b/build.gradle index 6ff1831..95b0898 100644 --- a/build.gradle +++ b/build.gradle @@ -10,14 +10,14 @@ sourceCompatibility = 17 targetCompatibility = 17 group 'me.exzork.gcauth' -version '2.1.3' +version '2.1.4' repositories { mavenCentral() } dependencies { - implementation files('lib/grasscutter-1.0.3-dev.jar') + implementation files('lib/grasscutter-1.1.1-dev.jar') implementation 'org.springframework.security:spring-security-crypto:5.6.3' implementation 'commons-logging:commons-logging:1.2' implementation 'com.auth0:java-jwt:3.19.1' diff --git a/src/main/java/me/exzork/gcauth/Config.java b/src/main/java/me/exzork/gcauth/Config.java index 28ea88e..20c332a 100644 --- a/src/main/java/me/exzork/gcauth/Config.java +++ b/src/main/java/me/exzork/gcauth/Config.java @@ -1,5 +1,8 @@ package me.exzork.gcauth; +import me.exzork.gcauth.utils.Authentication; + public final class Config { public String Hash = "BCRYPT"; + public String jwtSecret = Authentication.generateRandomString(32); } diff --git a/src/main/java/me/exzork/gcauth/GCAuth.java b/src/main/java/me/exzork/gcauth/GCAuth.java index 216df4d..2ef1905 100644 --- a/src/main/java/me/exzork/gcauth/GCAuth.java +++ b/src/main/java/me/exzork/gcauth/GCAuth.java @@ -3,9 +3,9 @@ package me.exzork.gcauth; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import emu.grasscutter.Grasscutter; -import emu.grasscutter.net.proto.QueryCurrRegionHttpRspOuterClass; import emu.grasscutter.plugin.Plugin; import me.exzork.gcauth.handler.*; +import me.exzork.gcauth.utils.Authentication; import java.io.File; import java.io.FileReader; @@ -32,8 +32,9 @@ public class GCAuth extends Plugin { loadConfig(); if(Grasscutter.getDispatchServer().registerAuthHandler(new GCAuthAuthenticationHandler())) { Grasscutter.getLogger().info("[GCAuth] GCAuth Enabled!"); - - if(Grasscutter.getConfig().getDispatchOptions().AutomaticallyCreateAccounts) { + config.jwtSecret = Authentication.generateRandomString(32); + saveConfig(); + if(Grasscutter.getConfig().account.autoCreate) { Grasscutter.getLogger().warn("[GCAuth] GCAuth does not support automatic account creation. Please disable in the server's config.json or just ignore this warning."); } } else { @@ -65,5 +66,6 @@ public class GCAuth extends Plugin { Grasscutter.getLogger().error("[GCAuth] Unable to save config file."); } } - public static Config getConfig() {return config;} + public static Config getConfigStatic() {return config;} + public Config getConfig() {return config;} } diff --git a/src/main/java/me/exzork/gcauth/utils/Authentication.java b/src/main/java/me/exzork/gcauth/utils/Authentication.java index b55c4c2..918d3f3 100644 --- a/src/main/java/me/exzork/gcauth/utils/Authentication.java +++ b/src/main/java/me/exzork/gcauth/utils/Authentication.java @@ -13,6 +13,9 @@ import java.util.HashMap; public final class Authentication { public static final HashMap tokens = new HashMap(); private static Algorithm key = Algorithm.HMAC256(generateRandomString(32)); + public static Algorithm getKey() { + return key; + } public static Account getAccountByUsernameAndPassword(String username, String password) { Account account = DatabaseHelper.getAccountByName(username); @@ -55,7 +58,7 @@ public final class Authentication { } public static String generateHash(String password) { - return switch (GCAuth.getConfig().Hash.toLowerCase()) { + return switch (GCAuth.getConfigStatic().Hash.toLowerCase()) { case "bcrypt" -> new BCryptPasswordEncoder().encode(password); case "scrypt" -> new SCryptPasswordEncoder().encode(password); default -> password; @@ -63,7 +66,7 @@ public final class Authentication { } private static boolean verifyPassword(String password, String hash) { - return switch (GCAuth.getConfig().Hash.toLowerCase()) { + return switch (GCAuth.getConfigStatic().Hash.toLowerCase()) { case "bcrypt" -> new BCryptPasswordEncoder().matches(password, hash); case "scrypt" -> new SCryptPasswordEncoder().matches(password, hash); default -> password.equals(hash);