2019-06-02 05:03:08 +03:00
|
|
|
package pro.gravit.launcher;
|
2018-09-17 10:07:32 +03:00
|
|
|
|
2019-06-02 05:03:08 +03:00
|
|
|
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;
|
2018-09-17 10:07:32 +03:00
|
|
|
|
2019-10-19 19:46:04 +03:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.security.cert.CertificateException;
|
|
|
|
import java.security.interfaces.ECPublicKey;
|
|
|
|
import java.security.spec.InvalidKeySpecException;
|
|
|
|
import java.util.*;
|
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
public final class LauncherConfig extends StreamObject {
|
2020-01-31 21:07:33 +03:00
|
|
|
@LauncherInject("launchercore.env")
|
|
|
|
private static final int cenv = -1;
|
|
|
|
@LauncherInject("launchercore.certificates")
|
|
|
|
private static final List<byte[]> secureConfigCertificates = null;
|
|
|
|
@LauncherInject("launcher.address")
|
|
|
|
public String address;
|
|
|
|
@LauncherInject("launcher.projectName")
|
2019-10-19 19:52:57 +03:00
|
|
|
public final String projectName;
|
2020-01-31 21:07:33 +03:00
|
|
|
@LauncherInject("launcher.port")
|
2018-10-13 11:20:23 +03:00
|
|
|
public final int clientPort;
|
2020-01-31 21:07:33 +03:00
|
|
|
@LauncherInject("runtimeconfig.secretKeyClient")
|
2018-10-08 16:57:29 +03:00
|
|
|
public String secretKeyClient;
|
2020-01-31 21:07:33 +03:00
|
|
|
@LauncherInject("runtimeconfig.oemUnlockKey")
|
2019-05-22 01:32:40 +03:00
|
|
|
public String oemUnlockKey;
|
2019-10-18 15:10:04 +03:00
|
|
|
public final LauncherTrustManager trustManager;
|
2019-12-08 22:21:05 +03:00
|
|
|
|
2019-10-16 12:38:44 +03:00
|
|
|
public final ECPublicKey publicKey;
|
2018-09-17 10:07:32 +03:00
|
|
|
|
2019-12-08 22:21:05 +03:00
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
public final Map<String, byte[]> runtime;
|
2020-01-31 21:07:33 +03:00
|
|
|
@LauncherInject("launcher.isWarningMissArchJava")
|
2018-12-20 18:43:01 +03:00
|
|
|
public final boolean isWarningMissArchJava;
|
2019-04-24 11:49:01 +03:00
|
|
|
public LauncherEnvironment environment;
|
2020-01-31 21:07:33 +03:00
|
|
|
@LauncherInject("launcher.guardType")
|
2019-04-12 01:15:05 +03:00
|
|
|
public final String guardType;
|
2020-01-31 21:07:33 +03:00
|
|
|
@LauncherInject("runtimeconfig.secureCheckHash")
|
2019-09-29 11:40:26 +03:00
|
|
|
public final String secureCheckHash;
|
2020-01-31 21:07:33 +03:00
|
|
|
@LauncherInject("runtimeconfig.secureCheckSalt")
|
2019-09-29 11:40:26 +03:00
|
|
|
public final String secureCheckSalt;
|
2020-01-31 21:07:33 +03:00
|
|
|
@LauncherInject("runtimeconfig.passwordEncryptKey")
|
2019-10-16 12:38:44 +03:00
|
|
|
public final String passwordEncryptKey;
|
2019-02-06 12:00:18 +03:00
|
|
|
|
2020-01-31 21:07:33 +03:00
|
|
|
@SuppressWarnings("unused")
|
|
|
|
@LauncherInjectionConstructor
|
2018-09-17 10:07:32 +03:00
|
|
|
public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException {
|
2019-10-16 12:38:44 +03:00
|
|
|
publicKey = SecurityHelper.toPublicECKey(input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH));
|
2020-01-31 21:07:33 +03:00
|
|
|
secureCheckHash = null;
|
|
|
|
secureCheckSalt = null;
|
|
|
|
passwordEncryptKey = null;
|
|
|
|
projectName = null;
|
|
|
|
clientPort = -1;
|
|
|
|
secretKeyClient = null;
|
|
|
|
oemUnlockKey = null;
|
2019-10-18 15:10:04 +03:00
|
|
|
try {
|
2020-01-31 21:07:33 +03:00
|
|
|
trustManager = new LauncherTrustManager(secureConfigCertificates);
|
2019-10-18 15:10:04 +03:00
|
|
|
} catch (CertificateException e) {
|
|
|
|
throw new IOException(e);
|
|
|
|
}
|
2019-04-12 01:15:05 +03:00
|
|
|
|
2020-01-31 21:07:33 +03:00
|
|
|
isWarningMissArchJava = false;
|
|
|
|
guardType = null;
|
|
|
|
address = null;
|
2018-12-19 14:24:50 +03:00
|
|
|
LauncherEnvironment env;
|
2020-01-31 21:07:33 +03:00
|
|
|
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;
|
2018-12-19 14:24:50 +03:00
|
|
|
else env = LauncherEnvironment.STD;
|
2019-01-15 06:48:20 +03:00
|
|
|
Launcher.applyLauncherEnv(env);
|
2019-04-24 11:49:01 +03:00
|
|
|
environment = env;
|
2018-09-17 10:07:32 +03:00
|
|
|
// Read signed runtime
|
|
|
|
int count = input.readLength(0);
|
|
|
|
Map<String, byte[]> 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);
|
|
|
|
}
|
2018-09-22 17:33:00 +03:00
|
|
|
|
2019-12-08 22:21:05 +03:00
|
|
|
|
2019-10-19 19:52:57 +03:00
|
|
|
public LauncherConfig(String address, ECPublicKey publicKey, Map<String, byte[]> runtime, String projectName) {
|
2019-04-04 15:02:12 +03:00
|
|
|
this.address = address;
|
2019-10-27 21:24:09 +03:00
|
|
|
this.publicKey = publicKey;
|
2018-09-20 14:47:40 +03:00
|
|
|
this.runtime = Collections.unmodifiableMap(new HashMap<>(runtime));
|
2019-10-19 19:52:57 +03:00
|
|
|
this.projectName = projectName;
|
2018-10-13 11:20:23 +03:00
|
|
|
this.clientPort = 32148;
|
2019-04-12 01:15:05 +03:00
|
|
|
guardType = "no";
|
2018-12-20 18:43:01 +03:00
|
|
|
isWarningMissArchJava = true;
|
2019-04-24 11:49:01 +03:00
|
|
|
environment = LauncherEnvironment.STD;
|
2019-09-29 11:40:26 +03:00
|
|
|
secureCheckSalt = null;
|
|
|
|
secureCheckHash = null;
|
2019-10-16 12:38:44 +03:00
|
|
|
passwordEncryptKey = null;
|
2019-10-18 15:10:04 +03:00
|
|
|
trustManager = null;
|
2018-09-17 10:07:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void write(HOutput output) throws IOException {
|
|
|
|
output.writeByteArray(publicKey.getEncoded(), SecurityHelper.CRYPTO_MAX_LENGTH);
|
|
|
|
|
|
|
|
// Write signed runtime
|
|
|
|
Set<Map.Entry<String, byte[]>> entrySet = runtime.entrySet();
|
|
|
|
output.writeLength(entrySet.size(), 0);
|
|
|
|
for (Map.Entry<String, byte[]> entry : runtime.entrySet()) {
|
|
|
|
output.writeString(entry.getKey(), 255);
|
|
|
|
output.writeByteArray(entry.getValue(), SecurityHelper.CRYPTO_MAX_LENGTH);
|
|
|
|
}
|
|
|
|
}
|
2018-12-19 14:24:50 +03:00
|
|
|
|
2018-12-20 18:45:01 +03:00
|
|
|
public enum LauncherEnvironment {
|
|
|
|
DEV, DEBUG, STD, PROD
|
2018-12-19 14:24:50 +03:00
|
|
|
}
|
2020-01-31 21:07:33 +03:00
|
|
|
|
|
|
|
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('.', '/'), "<init>", "()V"));
|
|
|
|
initModuleMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, modulesManagerName, "loadModule", registerModDesc));
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
2018-09-17 10:07:32 +03:00
|
|
|
}
|