[FEATURE] Ключи у клиента, название папки лаунчера настраивается через projectName

This commit is contained in:
Gravit 2019-10-16 17:48:36 +07:00
parent 35a94ae59f
commit 4a0485d1de
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
4 changed files with 48 additions and 7 deletions

View file

@ -1,6 +1,6 @@
var config = { var config = {
//*** Настройки лаунчера ***// //*** Настройки лаунчера ***//
dir: "GravitLauncher", // Название папки лаунчера // Название папки лаунчера настраивается в LaunchServer.conf(строка projectName)
title: "GravitLauncher", // Заголовок окна title: "GravitLauncher", // Заголовок окна
icons: ["favicon.png"], // Путь/Пути до иконки окна icons: ["favicon.png"], // Путь/Пути до иконки окна
@ -36,12 +36,6 @@ var config = {
settingsMagic: 0xC0DE5, // Магия вне хогвартса settingsMagic: 0xC0DE5, // Магия вне хогвартса
}; };
DirBridge.dir = DirBridge.getLauncherDir(config.dir);
DirBridge.dirStore = DirBridge.getStoreDir(config.dir);
DirBridge.dirProjectStore = DirBridge.getProjectStoreDir(config.dir);
if (!IOHelper.isDir(DirBridge.dir)) {
java.nio.file.Files.createDirectory(DirBridge.dir);
}
DirBridge.defaultUpdatesDir = DirBridge.dir.resolve("updates"); DirBridge.defaultUpdatesDir = DirBridge.dir.resolve("updates");
if (!IOHelper.isDir(DirBridge.defaultUpdatesDir)) { if (!IOHelper.isDir(DirBridge.defaultUpdatesDir)) {
java.nio.file.Files.createDirectory(DirBridge.defaultUpdatesDir); java.nio.file.Files.createDirectory(DirBridge.defaultUpdatesDir);

View file

@ -1,6 +1,11 @@
package pro.gravit.launcher; package pro.gravit.launcher;
import java.io.IOException;
import java.nio.file.Path;
import java.security.*; import java.security.*;
import java.security.interfaces.ECPrivateKey;
import java.security.interfaces.ECPublicKey;
import java.security.spec.InvalidKeySpecException;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@ -72,9 +77,33 @@ public static void initGson(ClientModuleManager modulesManager) {
Launcher.gsonManager.initGson(); Launcher.gsonManager.initGson();
} }
public void readKeys() throws IOException, InvalidKeySpecException {
if(privateKey != null || publicKey != null) return;
Path dir = DirBridge.dir;
Path publicKeyFile =dir.resolve("public.key");
Path privateKeyFile = dir.resolve("private.key");
if (IOHelper.isFile(publicKeyFile) && IOHelper.isFile(privateKeyFile)) {
LogHelper.info("Reading EC keypair");
publicKey = SecurityHelper.toPublicECKey(IOHelper.read(publicKeyFile));
privateKey = SecurityHelper.toPrivateECKey(IOHelper.read(privateKeyFile));
} else {
LogHelper.info("Generating EC keypair");
KeyPair pair = SecurityHelper.genECKeyPair(new SecureRandom());
publicKey = (ECPublicKey) pair.getPublic();
privateKey = (ECPrivateKey) pair.getPrivate();
// Write key pair list
LogHelper.info("Writing EC keypair list");
IOHelper.write(publicKeyFile, publicKey.getEncoded());
IOHelper.write(privateKeyFile, privateKey.getEncoded());
}
}
// Instance // Instance
private final AtomicBoolean started = new AtomicBoolean(false); private final AtomicBoolean started = new AtomicBoolean(false);
public RuntimeProvider runtimeProvider; public RuntimeProvider runtimeProvider;
public ECPublicKey publicKey;
public ECPrivateKey privateKey;
public static ClientModuleManager modulesManager; public static ClientModuleManager modulesManager;
@ -119,6 +148,7 @@ public void start(String... args) throws Throwable {
Objects.requireNonNull(args, "args"); Objects.requireNonNull(args, "args");
if (started.getAndSet(true)) if (started.getAndSet(true))
throw new IllegalStateException("Launcher has been already started"); throw new IllegalStateException("Launcher has been already started");
readKeys();
LauncherEngine.modulesManager.invokeEvent(new ClientEngineInitPhase(this)); LauncherEngine.modulesManager.invokeEvent(new ClientEngineInitPhase(this));
runtimeProvider.preLoad(); runtimeProvider.preLoad();
LauncherGuardManager.initGuard(false); LauncherGuardManager.initGuard(false);

View file

@ -461,6 +461,7 @@ public static void main(String... args) throws Throwable {
if (engine.runtimeProvider == null) engine.runtimeProvider = new JSRuntimeProvider(); if (engine.runtimeProvider == null) engine.runtimeProvider = new JSRuntimeProvider();
engine.runtimeProvider.init(true); engine.runtimeProvider.init(true);
engine.runtimeProvider.preLoad(); engine.runtimeProvider.preLoad();
engine.readKeys();
HWIDProvider.registerHWIDs(); HWIDProvider.registerHWIDs();
LauncherGuardManager.initGuard(true); LauncherGuardManager.initGuard(true);
LogHelper.debug("Reading ClientLauncher params"); LogHelper.debug("Reading ClientLauncher params");

View file

@ -5,9 +5,11 @@
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import pro.gravit.launcher.Launcher;
import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherAPI;
import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.IOHelper;
import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.JVMHelper;
import pro.gravit.utils.helper.LogHelper;
public class DirBridge { public class DirBridge {
@ -98,4 +100,18 @@ public static Path getLegacyLauncherDir(String projectname) {
public static void setUseLegacyDir(boolean b) { public static void setUseLegacyDir(boolean b) {
useLegacyDir = b; useLegacyDir = b;
} }
static {
String projectName = Launcher.getConfig().projectname;
try {
DirBridge.dir = getLauncherDir(projectName);
if(!IOHelper.exists(DirBridge.dir)) Files.createDirectories(DirBridge.dir);
DirBridge.dirStore = getStoreDir(projectName);
if(!IOHelper.exists(DirBridge.dirStore)) Files.createDirectories(DirBridge.dirStore);
DirBridge.dirProjectStore = getProjectStoreDir(projectName);
if(!IOHelper.exists(DirBridge.dirProjectStore)) Files.createDirectories(DirBridge.dirProjectStore);
} catch (IOException e) {
LogHelper.error(e);
}
}
} }