From 4a0485d1de96d84e38cd97f87ad52e8598b88223 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 16 Oct 2019 17:48:36 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=9A=D0=BB=D1=8E=D1=87=D0=B8=20?= =?UTF-8?q?=D1=83=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=B0,=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=B0=D0=BF?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BB=D0=B0=D1=83=D0=BD=D1=87=D0=B5=D1=80=D0=B0?= =?UTF-8?q?=20=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=B0=D0=B8=D0=B2=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=D1=81=D1=8F=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20projectNa?= =?UTF-8?q?me?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Launcher/runtime/config.js | 8 +---- .../pro/gravit/launcher/LauncherEngine.java | 30 +++++++++++++++++++ .../launcher/client/ClientLauncher.java | 1 + .../pro/gravit/launcher/client/DirBridge.java | 16 ++++++++++ 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/Launcher/runtime/config.js b/Launcher/runtime/config.js index 1f1f81b4..c63a5dc4 100644 --- a/Launcher/runtime/config.js +++ b/Launcher/runtime/config.js @@ -1,6 +1,6 @@ var config = { //*** Настройки лаунчера ***// - dir: "GravitLauncher", // Название папки лаунчера + // Название папки лаунчера настраивается в LaunchServer.conf(строка projectName) title: "GravitLauncher", // Заголовок окна icons: ["favicon.png"], // Путь/Пути до иконки окна @@ -36,12 +36,6 @@ var config = { 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"); if (!IOHelper.isDir(DirBridge.defaultUpdatesDir)) { java.nio.file.Files.createDirectory(DirBridge.defaultUpdatesDir); diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java index a5f425a4..8b538ea2 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java @@ -1,6 +1,11 @@ package pro.gravit.launcher; +import java.io.IOException; +import java.nio.file.Path; 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.concurrent.atomic.AtomicBoolean; @@ -72,9 +77,33 @@ public static void initGson(ClientModuleManager modulesManager) { 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 private final AtomicBoolean started = new AtomicBoolean(false); public RuntimeProvider runtimeProvider; + public ECPublicKey publicKey; + public ECPrivateKey privateKey; public static ClientModuleManager modulesManager; @@ -119,6 +148,7 @@ public void start(String... args) throws Throwable { Objects.requireNonNull(args, "args"); if (started.getAndSet(true)) throw new IllegalStateException("Launcher has been already started"); + readKeys(); LauncherEngine.modulesManager.invokeEvent(new ClientEngineInitPhase(this)); runtimeProvider.preLoad(); LauncherGuardManager.initGuard(false); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java index ff1db902..b81d0bd3 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncher.java @@ -461,6 +461,7 @@ public static void main(String... args) throws Throwable { if (engine.runtimeProvider == null) engine.runtimeProvider = new JSRuntimeProvider(); engine.runtimeProvider.init(true); engine.runtimeProvider.preLoad(); + engine.readKeys(); HWIDProvider.registerHWIDs(); LauncherGuardManager.initGuard(true); LogHelper.debug("Reading ClientLauncher params"); diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java b/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java index 194ea88e..3175bc43 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/DirBridge.java @@ -5,9 +5,11 @@ import java.nio.file.Path; import java.nio.file.Paths; +import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherAPI; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; +import pro.gravit.utils.helper.LogHelper; public class DirBridge { @@ -98,4 +100,18 @@ public static Path getLegacyLauncherDir(String projectname) { public static void setUseLegacyDir(boolean 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); + } + } }