mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-07-07 00:09:46 +03:00
Compare commits
15 commits
24f6b34e5a
...
5961777b52
Author | SHA1 | Date | |
---|---|---|---|
|
5961777b52 | ||
|
3f80d6318c | ||
|
7b7bd2480f | ||
|
124c384971 | ||
|
013f5490f9 | ||
|
5ebeaf8e6c | ||
|
c76aae76a5 | ||
|
261e16cecb | ||
|
3c9e009433 | ||
|
2379fe5798 | ||
|
05530b6664 | ||
|
8f20cbe104 | ||
|
66d8b9d9ca | ||
|
90ee90973e | ||
|
8bf58cff18 |
14 changed files with 160 additions and 54 deletions
1
.github/workflows/push.yml
vendored
1
.github/workflows/push.yml
vendored
|
@ -35,6 +35,7 @@ jobs:
|
|||
run: |
|
||||
mkdir -p artifacts/modules
|
||||
cd LaunchServer/build/libs
|
||||
mv proguard proguard-libraries
|
||||
zip -r -9 ../../../artifacts/libraries.zip * -x "LaunchServer.jar" -x "LaunchServer-clean.jar"
|
||||
cp LaunchServer.jar ../../../artifacts/LaunchServer.jar
|
||||
cd ../../..
|
||||
|
|
|
@ -338,6 +338,32 @@ public void invoke(String... args) throws Exception {
|
|||
}
|
||||
}
|
||||
});
|
||||
map.put("newSession", new SubCommand("[username/uuid] [isShadow] (CLIENT/API)", "create access/refresh token without password") {
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args, 2);
|
||||
String login = args[0];
|
||||
boolean isShadow = Boolean.parseBoolean(args[1]);
|
||||
User user;
|
||||
if(login.length() == 36) {
|
||||
UUID uuid = UUID.fromString(login);
|
||||
user = getUserByUUID(uuid);
|
||||
} else {
|
||||
user = getUserByUsername(login);
|
||||
}
|
||||
if(user == null) {
|
||||
logger.error("User {} not found", login);
|
||||
return;
|
||||
}
|
||||
var report = instance.sudo(user, isShadow);
|
||||
User user1 = report.session().getUser();
|
||||
logger.info("Created session {} for user {} ({})", report.session().getID(), user1.getUsername(), user.getUUID());
|
||||
logger.info("- AccessToken: {}", report.oauthAccessToken());
|
||||
logger.info("- RefreshToken: {}", report.oauthRefreshToken());
|
||||
logger.info("- ExpireIn: {}", report.oauthExpire());
|
||||
logger.info("- MinecraftAccessToken: {}", report.minecraftAccessToken());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return map;
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package pro.gravit.launchserver.auth.password;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bouncycastle.crypto.digests.SHA256Digest;
|
||||
import org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator;
|
||||
import org.bouncycastle.crypto.params.KeyParameter;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
public class DjangoPasswordVerifier extends PasswordVerifier {
|
||||
public final Integer DEFAULT_ITERATIONS = 10000;
|
||||
private static final Logger logger = LogManager.getLogger();
|
||||
private static final String algorithm = "pbkdf2_sha256";
|
||||
|
||||
public String getEncodedHash(String password, String salt, int iterations) {
|
||||
PKCS5S2ParametersGenerator generator = new PKCS5S2ParametersGenerator(new SHA256Digest());
|
||||
generator.init(password.getBytes(StandardCharsets.UTF_8), salt.getBytes(), iterations);
|
||||
byte[] dk = ((KeyParameter) generator.generateDerivedParameters(256)).getKey();
|
||||
byte[] hashBase64 = Base64.getEncoder().encode(dk);
|
||||
return new String(hashBase64);
|
||||
}
|
||||
|
||||
public String encode(String password, String salt, int iterations) {
|
||||
String hash = getEncodedHash(password, salt, iterations);
|
||||
return String.format("%s$%d$%s$%s", algorithm, iterations, salt, hash);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(String encryptedPassword, String password) {
|
||||
String[] params = encryptedPassword.split("\\$");
|
||||
if (params.length != 4) {
|
||||
logger.warn(" end 1 " + params.length);
|
||||
return false;
|
||||
}
|
||||
int iterations = Integer.parseInt(params[1]);
|
||||
String salt = params[2];
|
||||
String hash = encode(password, salt, iterations);
|
||||
return hash.equals(encryptedPassword);
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ public static void registerProviders() {
|
|||
providers.register("bcrypt", BCryptPasswordVerifier.class);
|
||||
providers.register("accept", AcceptPasswordVerifier.class);
|
||||
providers.register("reject", RejectPasswordVerifier.class);
|
||||
providers.register("django", DjangoPasswordVerifier.class);
|
||||
registeredProviders = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,9 @@ public static void registerHandlers() {
|
|||
|
||||
public abstract boolean allowGetAccessToken(AuthResponse.AuthContext context);
|
||||
public boolean allowJoinServer(Client client) {
|
||||
if(client.permissions != null && client.permissions.hasPerm("launchserver.debug.joinserver")) {
|
||||
return client.isAuth;
|
||||
}
|
||||
return client.isAuth && client.type == AuthResponse.ConnectTypes.CLIENT;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,19 +29,14 @@
|
|||
import java.util.UUID;
|
||||
|
||||
public class ClientRuntimeProvider implements RuntimeProvider {
|
||||
|
||||
@Override
|
||||
public void run(String[] args) {
|
||||
ArrayList<String> newArgs = new ArrayList<>(Arrays.asList(args));
|
||||
try {
|
||||
String username = System.getProperty("launcher.runtime.username", null);
|
||||
String uuid = System.getProperty("launcher.runtime.uuid", null);
|
||||
String login = System.getProperty("launcher.runtime.login", username);
|
||||
String password = System.getProperty("launcher.runtime.password", "Player");
|
||||
String authId = System.getProperty("launcher.runtime.auth.authid", "std");
|
||||
String accessToken = System.getProperty("launcher.runtime.auth.accesstoken", null);
|
||||
String refreshToken = System.getProperty("launcher.runtime.auth.refreshtoken", null);
|
||||
String minecraftAccessToken = System.getProperty("launcher.runtime.auth.minecraftaccesstoken", "DEBUG");
|
||||
long expire = Long.parseLong(System.getProperty("launcher.runtime.auth.expire", "0"));
|
||||
String username = DebugProperties.USERNAME;
|
||||
String uuid = DebugProperties.UUID;
|
||||
String minecraftAccessToken = DebugProperties.MINECRAFT_ACCESS_TOKEN;
|
||||
String profileUUID = System.getProperty("launcher.runtime.profileuuid", null);
|
||||
String mainClass = System.getProperty("launcher.runtime.mainclass", null);
|
||||
String mainModule = System.getProperty("launcher.runtime.mainmodule", null);
|
||||
|
@ -55,28 +50,14 @@ public void run(String[] args) {
|
|||
throw new NullPointerException("Add `-Dlauncher.runtime.mainclass=YOUR_MAIN_CLASS` to jvmArgs");
|
||||
}
|
||||
if(uuid == null) {
|
||||
if(accessToken != null) {
|
||||
Request.setOAuth(authId, new AuthRequestEvent.OAuthRequestEvent(accessToken, refreshToken, expire));
|
||||
Request.RequestRestoreReport report = Request.restore(true, false, true);
|
||||
permissions = report.userInfo.permissions;
|
||||
username = report.userInfo.playerProfile.username;
|
||||
uuid = report.userInfo.playerProfile.uuid.toString();
|
||||
if(report.userInfo.accessToken != null) {
|
||||
minecraftAccessToken = report.userInfo.accessToken;
|
||||
}
|
||||
} else {
|
||||
AuthRequest request = new AuthRequest(login, password, authId, AuthRequest.ConnectTypes.API);
|
||||
AuthRequestEvent event = request.request();
|
||||
Request.setOAuth(authId, event.oauth);
|
||||
if(event.accessToken != null) {
|
||||
minecraftAccessToken = event.accessToken;
|
||||
}
|
||||
username = event.playerProfile.username;
|
||||
uuid = event.playerProfile.uuid.toString();
|
||||
}
|
||||
var data = DebugMain.authorize();
|
||||
minecraftAccessToken = data.userInfo().accessToken;
|
||||
permissions = data.userInfo().permissions;
|
||||
username = data.userInfo().playerProfile.username;
|
||||
uuid = data.userInfo().playerProfile.uuid.toString();
|
||||
}
|
||||
if(profileUUID != null) {
|
||||
UUID profileUuid = UUID.fromString(profileUUID);
|
||||
UUID profileUuid = java.util.UUID.fromString(profileUUID);
|
||||
ProfilesRequest profiles = new ProfilesRequest();
|
||||
ProfilesRequestEvent event = profiles.request();
|
||||
for(ClientProfile profile : event.profiles) {
|
||||
|
@ -94,7 +75,7 @@ public void run(String[] args) {
|
|||
replaceOrCreateArgument(newArgs, "--username", username);
|
||||
replaceOrCreateArgument(newArgs, "--uuid", uuid);
|
||||
replaceOrCreateArgument(newArgs, "--accessToken", minecraftAccessToken);
|
||||
AuthService.uuid = UUID.fromString(uuid);
|
||||
AuthService.uuid = java.util.UUID.fromString(uuid);
|
||||
AuthService.username = username;
|
||||
AuthService.permissions = permissions;
|
||||
Launch launch;
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
package pro.gravit.launcher.runtime.debug;
|
||||
|
||||
import pro.gravit.launcher.base.ClientPermissions;
|
||||
import pro.gravit.launcher.base.Launcher;
|
||||
import pro.gravit.launcher.base.LauncherConfig;
|
||||
import pro.gravit.launcher.base.events.request.AuthRequestEvent;
|
||||
import pro.gravit.launcher.base.events.request.CurrentUserRequestEvent;
|
||||
import pro.gravit.launcher.base.profiles.PlayerProfile;
|
||||
import pro.gravit.launcher.base.request.auth.AuthRequest;
|
||||
import pro.gravit.launcher.client.ClientLauncherMethods;
|
||||
import pro.gravit.launcher.runtime.LauncherEngine;
|
||||
import pro.gravit.launcher.client.RuntimeLauncherCoreModule;
|
||||
|
@ -21,19 +26,11 @@
|
|||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class DebugMain {
|
||||
public static final AtomicBoolean IS_DEBUG = new AtomicBoolean(false);
|
||||
public static String webSocketURL = System.getProperty("launcherdebug.websocket", "ws://localhost:9274/api");
|
||||
public static String projectName = System.getProperty("launcherdebug.projectname", "Minecraft");
|
||||
public static String unlockSecret = System.getProperty("launcherdebug.unlocksecret", "");
|
||||
public static boolean disableConsole = Boolean.getBoolean("launcherdebug.disableConsole");
|
||||
public static boolean offlineMode = Boolean.getBoolean("launcherdebug.offlinemode");
|
||||
public static boolean disableAutoRefresh = Boolean.getBoolean("launcherdebug.disableautorefresh");
|
||||
public static String[] moduleClasses = System.getProperty("launcherdebug.modules", "").split(",");
|
||||
public static String[] moduleFiles = System.getProperty("launcherdebug.modulefiles", "").split(",");
|
||||
public static LauncherConfig.LauncherEnvironment environment = LauncherConfig.LauncherEnvironment.valueOf(System.getProperty("launcherdebug.env", "STD"));
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
LogHelper.printVersion("Launcher");
|
||||
|
@ -49,42 +46,63 @@ public static void initialize() throws Exception {
|
|||
IS_DEBUG.set(true);
|
||||
LogHelper.info("Launcher start in DEBUG mode (Only for developers)");
|
||||
LogHelper.debug("Initialization LauncherConfig");
|
||||
LauncherConfig config = new LauncherConfig(webSocketURL, new HashMap<>(), projectName, environment, new DebugLauncherTrustManager(DebugLauncherTrustManager.TrustDebugMode.TRUST_ALL));
|
||||
config.unlockSecret = unlockSecret;
|
||||
LauncherConfig config = new LauncherConfig(DebugProperties.WEBSOCKET_URL, new HashMap<>(), DebugProperties.PROJECT_NAME, DebugProperties.ENV, new DebugLauncherTrustManager(DebugLauncherTrustManager.TrustDebugMode.TRUST_ALL));
|
||||
config.unlockSecret = DebugProperties.UNLOCK_SECRET;
|
||||
Launcher.setConfig(config);
|
||||
Launcher.applyLauncherEnv(environment);
|
||||
Launcher.applyLauncherEnv(DebugProperties.ENV);
|
||||
LauncherEngine.modulesManager = new RuntimeModuleManager();
|
||||
LauncherEngine.modulesManager.loadModule(new RuntimeLauncherCoreModule());
|
||||
for (String moduleClassName : moduleClasses) {
|
||||
for (String moduleClassName : DebugProperties.MODULE_CLASSES) {
|
||||
if (moduleClassName.isEmpty()) continue;
|
||||
LauncherEngine.modulesManager.loadModule(newModule(moduleClassName));
|
||||
}
|
||||
for (String moduleFileName : moduleFiles) {
|
||||
for (String moduleFileName : DebugProperties.MODULE_FILES) {
|
||||
if (moduleFileName.isEmpty()) continue;
|
||||
LauncherEngine.modulesManager.loadModule(Paths.get(moduleFileName));
|
||||
}
|
||||
LauncherEngine.modulesManager.initModules(null);
|
||||
LauncherEngine.initGson(LauncherEngine.modulesManager);
|
||||
if(!disableConsole) {
|
||||
if(!DebugProperties.DISABLE_CONSOLE) {
|
||||
ConsoleManager.initConsole();
|
||||
}
|
||||
LauncherEngine.modulesManager.invokeEvent(new PreConfigPhase());
|
||||
RequestService service;
|
||||
if (offlineMode) {
|
||||
if (DebugProperties.OFFLINE_MODE) {
|
||||
OfflineRequestService offlineRequestService = new OfflineRequestService();
|
||||
ClientLauncherMethods.applyBasicOfflineProcessors(offlineRequestService);
|
||||
OfflineModeEvent event = new OfflineModeEvent(offlineRequestService);
|
||||
LauncherEngine.modulesManager.invokeEvent(event);
|
||||
service = event.service;
|
||||
} else {
|
||||
service = StdWebSocketService.initWebSockets(webSocketURL).get();
|
||||
service = StdWebSocketService.initWebSockets(DebugProperties.WEBSOCKET_URL).get();
|
||||
}
|
||||
Request.setRequestService(service);
|
||||
if(!disableAutoRefresh) {
|
||||
if(!DebugProperties.DISABLE_AUTO_REFRESH) {
|
||||
Request.startAutoRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
public static AuthorizationData authorize() throws Exception {
|
||||
if(DebugProperties.ACCESS_TOKEN != null) {
|
||||
Request.setOAuth(DebugProperties.AUTH_ID, new AuthRequestEvent.OAuthRequestEvent(DebugProperties.ACCESS_TOKEN, DebugProperties.REFRESH_TOKEN, DebugProperties.EXPIRE));
|
||||
Request.RequestRestoreReport report = Request.restore(true, false, true);
|
||||
return new AuthorizationData(new AuthRequestEvent.OAuthRequestEvent(DebugProperties.ACCESS_TOKEN, DebugProperties.REFRESH_TOKEN, DebugProperties.EXPIRE), report.userInfo);
|
||||
} else if(DebugProperties.LOGIN != null) {
|
||||
AuthRequest request = new AuthRequest(DebugProperties.LOGIN, DebugProperties.PASSWORD, DebugProperties.AUTH_ID, AuthRequest.ConnectTypes.API);
|
||||
AuthRequestEvent event = request.request();
|
||||
Request.setOAuth(DebugProperties.AUTH_ID, event.oauth);
|
||||
return new AuthorizationData(event.oauth, new CurrentUserRequestEvent.UserInfo(event.permissions, event.accessToken, event.playerProfile));
|
||||
} else {
|
||||
return new AuthorizationData(new AuthRequestEvent.OAuthRequestEvent("ACCESS_TOKEN", "REFRESH_TOKEN", 0),
|
||||
new CurrentUserRequestEvent.UserInfo(new ClientPermissions(), "ACCESS_TOKEN", new PlayerProfile(UUID.fromString(DebugProperties.UUID),
|
||||
DebugProperties.USERNAME, new HashMap<>(), new HashMap<>())));
|
||||
}
|
||||
}
|
||||
|
||||
public record AuthorizationData(AuthRequestEvent.OAuthRequestEvent event, CurrentUserRequestEvent.UserInfo userInfo) {
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static LauncherModule newModule(String className) throws ClassNotFoundException, InvocationTargetException {
|
||||
Class<? extends LauncherModule> clazz = (Class<? extends LauncherModule>) Class.forName(className);
|
||||
|
|
|
@ -3,5 +3,6 @@
|
|||
public class DebugMainInlineInitializer {
|
||||
public static void run() throws Exception {
|
||||
DebugMain.initialize();
|
||||
DebugMain.authorize();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package pro.gravit.launcher.runtime.debug;
|
||||
|
||||
import pro.gravit.launcher.base.LauncherConfig;
|
||||
|
||||
public class DebugProperties {
|
||||
public static final String ACCESS_TOKEN = System.getProperty("launcher.runtime.auth.accesstoken", null);
|
||||
public static final String AUTH_ID = System.getProperty("launcher.runtime.auth.authid", "std");
|
||||
public static final String REFRESH_TOKEN = System.getProperty("launcher.runtime.auth.refreshtoken", null);
|
||||
public static final String MINECRAFT_ACCESS_TOKEN = System.getProperty("launcher.runtime.auth.minecraftaccesstoken", "DEBUG");
|
||||
public static final long EXPIRE = Long.parseLong(System.getProperty("launcher.runtime.auth.expire", "0"));
|
||||
public static final String USERNAME = System.getProperty("launcher.runtime.username", null);
|
||||
public static final String LOGIN = System.getProperty("launcher.runtime.login", USERNAME);
|
||||
public static final String UUID = System.getProperty("launcher.runtime.uuid", null);
|
||||
public static final String PASSWORD = System.getProperty("launcher.runtime.password", null);
|
||||
public static String WEBSOCKET_URL = System.getProperty("launcherdebug.websocket", "ws://localhost:9274/api");
|
||||
public static String PROJECT_NAME = System.getProperty("launcherdebug.projectname", "Minecraft");
|
||||
public static String UNLOCK_SECRET = System.getProperty("launcherdebug.unlocksecret", "");
|
||||
public static boolean DISABLE_CONSOLE = Boolean.getBoolean("launcherdebug.disableConsole");
|
||||
public static boolean OFFLINE_MODE = Boolean.getBoolean("launcherdebug.offlinemode");
|
||||
public static boolean DISABLE_AUTO_REFRESH = Boolean.getBoolean("launcherdebug.disableautorefresh");
|
||||
public static String[] MODULE_CLASSES = System.getProperty("launcherdebug.modules", "").split(",");
|
||||
public static String[] MODULE_FILES = System.getProperty("launcherdebug.modulefiles", "").split(",");
|
||||
public static LauncherConfig.LauncherEnvironment ENV = LauncherConfig.LauncherEnvironment.valueOf(System.getProperty("launcherdebug.env", "STD"));
|
||||
}
|
|
@ -20,5 +20,14 @@ public static class UserInfo {
|
|||
public ClientPermissions permissions;
|
||||
public String accessToken;
|
||||
public PlayerProfile playerProfile;
|
||||
|
||||
public UserInfo() {
|
||||
}
|
||||
|
||||
public UserInfo(ClientPermissions permissions, String accessToken, PlayerProfile playerProfile) {
|
||||
this.permissions = permissions;
|
||||
this.accessToken = accessToken;
|
||||
this.playerProfile = playerProfile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@ public final class Version implements Comparable<Version> {
|
|||
|
||||
public static final int MAJOR = 5;
|
||||
public static final int MINOR = 6;
|
||||
public static final int PATCH = 14;
|
||||
public static final int PATCH = 16;
|
||||
public static final int BUILD = 1;
|
||||
public static final Version.Type RELEASE = Type.STABLE;
|
||||
public static final Version.Type RELEASE = Type.DEV;
|
||||
public final int major;
|
||||
public final int minor;
|
||||
public final int patch;
|
||||
|
|
|
@ -282,12 +282,12 @@ public void setConfig(Config config) {
|
|||
@Override
|
||||
public Config getDefaultConfig() {
|
||||
Config newConfig = new Config();
|
||||
newConfig.serverName = "your server name";
|
||||
newConfig.serverName = "";
|
||||
newConfig.mainclass = "";
|
||||
newConfig.extendedTokens = new HashMap<>();
|
||||
newConfig.args = new ArrayList<>();
|
||||
newConfig.classpath = new ArrayList<>();
|
||||
newConfig.address = "ws://localhost:9274/api";
|
||||
newConfig.address = "";
|
||||
newConfig.classLoaderConfig = ClientProfile.ClassLoaderConfig.SYSTEM_ARGS;
|
||||
newConfig.env = LauncherConfig.LauncherEnvironment.STD;
|
||||
newConfig.properties = new HashMap<>();
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
id 'org.openjfx.javafxplugin' version '0.1.0' apply false
|
||||
}
|
||||
group = 'pro.gravit.launcher'
|
||||
version = '5.6.14'
|
||||
version = '5.6.16-SNAPSHOT'
|
||||
|
||||
apply from: 'props.gradle'
|
||||
|
||||
|
|
2
modules
2
modules
|
@ -1 +1 @@
|
|||
Subproject commit a2c3ccecadb7f864039b88e6269583c4b77fba13
|
||||
Subproject commit a18e0b7d7b6aff2b46c13d0290826cdb8e815dbe
|
Loading…
Reference in a new issue