2018-09-17 10:07:32 +03:00
|
|
|
package ru.gravit.launcher;
|
|
|
|
|
|
|
|
import ru.gravit.launcher.serialize.HInput;
|
|
|
|
import ru.gravit.launcher.serialize.HOutput;
|
|
|
|
import ru.gravit.launcher.serialize.stream.StreamObject;
|
2018-12-06 05:29:34 +03:00
|
|
|
import ru.gravit.utils.helper.SecurityHelper;
|
|
|
|
import ru.gravit.utils.helper.VerifyHelper;
|
2018-09-17 10:07:32 +03:00
|
|
|
|
2018-12-20 18:45:01 +03:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.security.interfaces.RSAPublicKey;
|
|
|
|
import java.security.spec.InvalidKeySpecException;
|
|
|
|
import java.util.*;
|
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
public final class LauncherConfig extends StreamObject {
|
|
|
|
private static final AutogenConfig config = new AutogenConfig();
|
2018-09-22 17:33:00 +03:00
|
|
|
|
2018-10-13 11:01:10 +03:00
|
|
|
|
2018-09-22 17:33:00 +03:00
|
|
|
public static AutogenConfig getAutogenConfig() {
|
2018-09-17 10:07:32 +03:00
|
|
|
return config;
|
|
|
|
}
|
2018-09-22 17:33:00 +03:00
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
// Instance
|
2019-04-04 15:02:12 +03:00
|
|
|
public String address;
|
2018-09-17 10:07:32 +03:00
|
|
|
@LauncherAPI
|
2018-09-20 14:47:40 +03:00
|
|
|
public final String projectname;
|
2018-10-13 11:20:23 +03:00
|
|
|
public final int clientPort;
|
2018-10-08 16:57:29 +03:00
|
|
|
public String secretKeyClient;
|
2018-09-20 14:47:40 +03:00
|
|
|
@LauncherAPI
|
2018-09-17 10:07:32 +03:00
|
|
|
public final RSAPublicKey publicKey;
|
|
|
|
|
|
|
|
@LauncherAPI
|
|
|
|
public final Map<String, byte[]> runtime;
|
2018-12-20 18:43:01 +03:00
|
|
|
public final boolean isWarningMissArchJava;
|
2019-04-04 11:16:23 +03:00
|
|
|
public boolean isNettyEnabled;
|
2019-04-24 11:49:01 +03:00
|
|
|
public LauncherEnvironment environment;
|
2018-10-20 12:33:02 +03:00
|
|
|
|
2019-02-06 12:00:18 +03:00
|
|
|
public final String guardLicenseName;
|
|
|
|
public final String guardLicenseKey;
|
|
|
|
public final String guardLicenseEncryptKey;
|
2019-04-12 01:15:05 +03:00
|
|
|
public final String guardType;
|
2019-02-06 12:00:18 +03:00
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
@LauncherAPI
|
|
|
|
public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException {
|
|
|
|
publicKey = SecurityHelper.toPublicRSAKey(input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH));
|
2018-09-20 14:47:40 +03:00
|
|
|
projectname = config.projectname;
|
2018-10-13 11:20:23 +03:00
|
|
|
clientPort = config.clientPort;
|
2018-10-08 16:57:29 +03:00
|
|
|
secretKeyClient = config.secretKeyClient;
|
2019-04-12 01:15:05 +03:00
|
|
|
|
2018-12-20 18:43:01 +03:00
|
|
|
isWarningMissArchJava = config.isWarningMissArchJava;
|
2019-02-06 12:00:18 +03:00
|
|
|
guardLicenseEncryptKey = config.guardLicenseEncryptKey;
|
|
|
|
guardLicenseKey = config.guardLicenseKey;
|
2019-04-12 01:15:05 +03:00
|
|
|
guardType = config.guardType;
|
2019-02-06 12:00:18 +03:00
|
|
|
guardLicenseName = config.guardLicenseName;
|
2019-04-04 15:22:06 +03:00
|
|
|
address = config.address;
|
2018-12-19 14:24:50 +03:00
|
|
|
LauncherEnvironment env;
|
2018-12-20 18:45:01 +03:00
|
|
|
if (config.env == 0) env = LauncherEnvironment.DEV;
|
|
|
|
else if (config.env == 1) env = LauncherEnvironment.DEBUG;
|
|
|
|
else if (config.env == 2) env = LauncherEnvironment.STD;
|
|
|
|
else if (config.env == 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
|
|
|
|
2018-09-17 10:07:32 +03:00
|
|
|
@LauncherAPI
|
2019-04-04 14:40:24 +03:00
|
|
|
public LauncherConfig(String address, RSAPublicKey publicKey, Map<String, byte[]> runtime, String projectname) {
|
2019-04-04 15:02:12 +03:00
|
|
|
this.address = address;
|
2018-09-20 14:47:40 +03:00
|
|
|
this.publicKey = Objects.requireNonNull(publicKey, "publicKey");
|
|
|
|
this.runtime = Collections.unmodifiableMap(new HashMap<>(runtime));
|
|
|
|
this.projectname = projectname;
|
2018-10-13 11:20:23 +03:00
|
|
|
this.clientPort = 32148;
|
2019-02-06 12:00:18 +03:00
|
|
|
this.guardLicenseName = "FREE";
|
|
|
|
this.guardLicenseKey = "AAAA-BBBB-CCCC-DDDD";
|
|
|
|
this.guardLicenseEncryptKey = "12345";
|
2019-04-12 01:15:05 +03:00
|
|
|
guardType = "no";
|
2018-12-20 18:43:01 +03:00
|
|
|
isWarningMissArchJava = true;
|
2019-02-20 13:23:24 +03:00
|
|
|
isNettyEnabled = false;
|
2019-04-24 11:49:01 +03:00
|
|
|
environment = LauncherEnvironment.STD;
|
2018-09-20 14:47:40 +03:00
|
|
|
}
|
2018-09-22 17:33:00 +03:00
|
|
|
|
2018-09-20 14:47:40 +03:00
|
|
|
@LauncherAPI
|
2019-04-04 14:40:24 +03:00
|
|
|
public LauncherConfig(String address, RSAPublicKey publicKey, Map<String, byte[]> runtime) {
|
2019-04-04 15:02:12 +03:00
|
|
|
this.address = address;
|
2018-09-17 10:07:32 +03:00
|
|
|
this.publicKey = Objects.requireNonNull(publicKey, "publicKey");
|
|
|
|
this.runtime = Collections.unmodifiableMap(new HashMap<>(runtime));
|
2018-09-20 14:47:40 +03:00
|
|
|
this.projectname = "Minecraft";
|
2019-02-06 12:00:18 +03:00
|
|
|
this.guardLicenseName = "FREE";
|
|
|
|
this.guardLicenseKey = "AAAA-BBBB-CCCC-DDDD";
|
|
|
|
this.guardLicenseEncryptKey = "12345";
|
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-02-20 13:23:24 +03:00
|
|
|
isNettyEnabled = false;
|
2019-04-24 11:49:01 +03:00
|
|
|
environment = LauncherEnvironment.STD;
|
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
|
|
|
}
|
2018-09-17 10:07:32 +03:00
|
|
|
}
|