package pro.gravit.launcher; import pro.gravit.launcher.serialize.HInput; import pro.gravit.launcher.serialize.HOutput; import pro.gravit.launcher.serialize.stream.StreamObject; import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.VerifyHelper; import java.io.IOException; import java.security.cert.CertificateException; import java.security.interfaces.ECPublicKey; import java.security.spec.InvalidKeySpecException; import java.util.*; public final class LauncherConfig extends StreamObject { @LauncherInject("launchercore.env") private static final int cenv = -1; @LauncherInject("launchercore.certificates") private static final List secureConfigCertificates = null; @LauncherInject("launcher.address") public String address; @LauncherInject("launcher.projectName") public final String projectName; @LauncherInject("launcher.port") public final int clientPort; @LauncherInject("runtimeconfig.secretKeyClient") public String secretKeyClient; @LauncherInject("runtimeconfig.oemUnlockKey") public String oemUnlockKey; public final LauncherTrustManager trustManager; public final ECPublicKey publicKey; public final Map runtime; @LauncherInject("launcher.isWarningMissArchJava") public final boolean isWarningMissArchJava; public LauncherEnvironment environment; @LauncherInject("launcher.guardType") public final String guardType; @LauncherInject("runtimeconfig.secureCheckHash") public final String secureCheckHash; @LauncherInject("runtimeconfig.secureCheckSalt") public final String secureCheckSalt; @LauncherInject("runtimeconfig.passwordEncryptKey") public final String passwordEncryptKey; @SuppressWarnings("unused") @LauncherInjectionConstructor public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException { publicKey = SecurityHelper.toPublicECKey(input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH)); secureCheckHash = null; secureCheckSalt = null; passwordEncryptKey = null; projectName = null; clientPort = -1; secretKeyClient = null; oemUnlockKey = null; try { trustManager = new LauncherTrustManager(secureConfigCertificates); } catch (CertificateException e) { throw new IOException(e); } isWarningMissArchJava = false; guardType = null; address = null; LauncherEnvironment env; if (cenv == 0) env = LauncherEnvironment.DEV; else if (cenv == 1) env = LauncherEnvironment.DEBUG; else if (cenv == 2) env = LauncherEnvironment.STD; else if (cenv == 3) env = LauncherEnvironment.PROD; else env = LauncherEnvironment.STD; Launcher.applyLauncherEnv(env); environment = env; // Read signed runtime int count = input.readLength(0); Map localResources = new HashMap<>(count); for (int i = 0; i < count; i++) { String name = input.readString(255); VerifyHelper.putIfAbsent(localResources, name, input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH), String.format("Duplicate runtime resource: '%s'", name)); } runtime = Collections.unmodifiableMap(localResources); } public LauncherConfig(String address, ECPublicKey publicKey, Map runtime, String projectName) { this.address = address; this.publicKey = publicKey; this.runtime = Collections.unmodifiableMap(new HashMap<>(runtime)); this.projectName = projectName; this.clientPort = 32148; guardType = "no"; isWarningMissArchJava = true; environment = LauncherEnvironment.STD; secureCheckSalt = null; secureCheckHash = null; passwordEncryptKey = null; trustManager = null; } @Override public void write(HOutput output) throws IOException { output.writeByteArray(publicKey.getEncoded(), SecurityHelper.CRYPTO_MAX_LENGTH); // Write signed runtime Set> entrySet = runtime.entrySet(); output.writeLength(entrySet.size(), 0); for (Map.Entry entry : runtime.entrySet()) { output.writeString(entry.getKey(), 255); output.writeByteArray(entry.getValue(), SecurityHelper.CRYPTO_MAX_LENGTH); } } public enum LauncherEnvironment { DEV, DEBUG, STD, PROD } public static void initModules() { // TODO Fill /* * Old filler public void addModuleClass(String fullName) { initModuleMethod.instructions.add(new FieldInsnNode(Opcodes.GETSTATIC, launcherName, "modulesManager", modulesManagerDesc)); initModuleMethod.instructions.add(new TypeInsnNode(Opcodes.NEW, fullName.replace('.', '/'))); initModuleMethod.instructions.add(new InsnNode(Opcodes.DUP)); initModuleMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, fullName.replace('.', '/'), "", "()V")); initModuleMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, modulesManagerName, "loadModule", registerModDesc)); } */ } }