From ff5ed0eb27d0f6394ec8e6946f8e6b4bd9a83064 Mon Sep 17 00:00:00 2001 From: Zaxar163 Date: Sat, 1 Feb 2020 06:30:04 +0100 Subject: [PATCH] =?UTF-8?q?[ANY]=20=D0=9D=D0=B5=D0=BC=D0=BD=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80=D0=B8?= =?UTF-8?q?=D0=BD=D0=B3=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binary/tasks/MainBuildTask.java | 81 ++++++++++--------- 1 file changed, 45 insertions(+), 36 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index 14c71088..f54d5f57 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -134,43 +134,10 @@ public Path process(Path inputJar) throws IOException { Path outputJar = server.launcherBinary.nextPath("main"); try (ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(outputJar))) { BuildContext context = new BuildContext(output, reader.getCp(), this); + initProps(); preBuildHook.hook(context); - properties.clear(); - properties.put("launcher.address", server.config.netty.address); - properties.put("launcher.projectName", server.config.projectName); - properties.put("runtimeconfig.secretKeyClient", SecurityHelper.randomStringAESKey()); - properties.put("launcher.port", 32148 + SecurityHelper.newRandom().nextInt(512)); - properties.put("launcher.guardType", server.config.launcher.guardType); - properties.put("launcher.isWarningMissArchJava", server.config.launcher.warningMissArchJava); - properties.put("launchercore.env" ,server.config.env); - properties.put("runtimeconfig.passwordEncryptKey", server.runtime.passwordEncryptKey); - List certificates = Arrays.stream(server.certificateManager.trustManager.getTrusted()).map(e -> { - try { - return e.getEncoded(); - } catch (CertificateEncodingException e2) { - LogHelper.error(e2); - return new byte[0]; - } - }).collect(Collectors.toList()); - if(!server.config.sign.enabled) - { - CertificateAutogenTask task = server.launcherBinary.getTaskByClass(CertificateAutogenTask.class).get(); - try { - certificates.add(task.certificate.getEncoded()); - } catch (CertificateEncodingException e) { - throw new InternalError(e); - } - } - properties.put("launchercore.certificates", certificates); - String launcherSalt = SecurityHelper.randomStringToken(); - byte[] launcherSecureHash = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, - server.runtime.clientCheckSecret.concat(".").concat(launcherSalt)); - properties.put("runtimeconfig.secureCheckHash", Base64.getEncoder().encodeToString(launcherSecureHash)); - properties.put("runtimeconfig.secureCheckSalt", launcherSalt); - //LogHelper.debug("[checkSecure] %s: %s", launcherSalt, Arrays.toString(launcherSecureHash)); - if (server.runtime.oemUnlockKey == null) server.runtime.oemUnlockKey = SecurityHelper.randomStringToken(); - properties.put("runtimeconfig.oemUnlockKey", server.runtime.oemUnlockKey); properties.put("launcher.modules", context.clientModules.stream().map(e -> Type.getObjectType(e.replace('.', '/'))).collect(Collectors.toList())); + postInitProps(); reader.getCp().add(new JarFile(inputJar.toFile())); server.launcherBinary.coreLibs.forEach(e -> { try { @@ -195,7 +162,49 @@ public Path process(Path inputJar) throws IOException { return outputJar; } - public byte[] transformClass(byte[] bytes, String classname, BuildContext context) + protected void postInitProps() { + List certificates = Arrays.stream(server.certificateManager.trustManager.getTrusted()).map(e -> { + try { + return e.getEncoded(); + } catch (CertificateEncodingException e2) { + LogHelper.error(e2); + return new byte[0]; + } + }).collect(Collectors.toList()); + if(!server.config.sign.enabled) + { + CertificateAutogenTask task = server.launcherBinary.getTaskByClass(CertificateAutogenTask.class).get(); + try { + certificates.add(task.certificate.getEncoded()); + } catch (CertificateEncodingException e) { + throw new InternalError(e); + } + } + properties.put("launchercore.certificates", certificates); + } + + protected void initProps() { + properties.clear(); + properties.put("launcher.address", server.config.netty.address); + properties.put("launcher.projectName", server.config.projectName); + properties.put("runtimeconfig.secretKeyClient", SecurityHelper.randomStringAESKey()); + properties.put("launcher.port", 32148 + SecurityHelper.newRandom().nextInt(512)); + properties.put("launcher.guardType", server.config.launcher.guardType); + properties.put("launcher.isWarningMissArchJava", server.config.launcher.warningMissArchJava); + properties.put("launchercore.env" ,server.config.env); + properties.put("runtimeconfig.passwordEncryptKey", server.runtime.passwordEncryptKey); + String launcherSalt = SecurityHelper.randomStringToken(); + byte[] launcherSecureHash = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, + server.runtime.clientCheckSecret.concat(".").concat(launcherSalt)); + properties.put("runtimeconfig.secureCheckHash", Base64.getEncoder().encodeToString(launcherSecureHash)); + properties.put("runtimeconfig.secureCheckSalt", launcherSalt); + //LogHelper.debug("[checkSecure] %s: %s", launcherSalt, Arrays.toString(launcherSecureHash)); + if (server.runtime.oemUnlockKey == null) server.runtime.oemUnlockKey = SecurityHelper.randomStringToken(); + properties.put("runtimeconfig.oemUnlockKey", server.runtime.oemUnlockKey); + + } + + public byte[] transformClass(byte[] bytes, String classname, BuildContext context) { byte[] result = bytes; ClassReader cr = null;