mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-01-03 22:30:31 +03:00
Merge branch 'dev' of github.com:GravitLauncher/Launcher into
dev
This commit is contained in:
commit
e6333e057f
19 changed files with 198 additions and 75 deletions
|
@ -405,6 +405,10 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La
|
||||||
Files.createDirectory(profilesDir);
|
Files.createDirectory(profilesDir);
|
||||||
syncProfilesDir();
|
syncProfilesDir();
|
||||||
|
|
||||||
|
if (config.netty != null)
|
||||||
|
nettyServerSocketHandler = new NettyServerSocketHandler(this);
|
||||||
|
else
|
||||||
|
nettyServerSocketHandler = null;
|
||||||
// post init modules
|
// post init modules
|
||||||
modulesManager.invokeEvent(new LaunchServerPostInitPhase(this));
|
modulesManager.invokeEvent(new LaunchServerPostInitPhase(this));
|
||||||
if (config.components != null) {
|
if (config.components != null) {
|
||||||
|
@ -415,11 +419,6 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La
|
||||||
});
|
});
|
||||||
LogHelper.debug("PostInit components successful");
|
LogHelper.debug("PostInit components successful");
|
||||||
}
|
}
|
||||||
// start updater
|
|
||||||
if (config.netty != null)
|
|
||||||
nettyServerSocketHandler = new NettyServerSocketHandler(this);
|
|
||||||
else
|
|
||||||
nettyServerSocketHandler = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private LauncherBinary binary() {
|
private LauncherBinary binary() {
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
import pro.gravit.utils.helper.SecurityHelper;
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
public class StdProtectHandler extends ProtectHandler {
|
public class StdProtectHandler extends ProtectHandler {
|
||||||
|
public boolean checkSecure = true;
|
||||||
@Override
|
@Override
|
||||||
public String generateSecureToken(AuthResponse.AuthContext context) {
|
public String generateSecureToken(AuthResponse.AuthContext context) {
|
||||||
return SecurityHelper.randomStringToken();
|
return SecurityHelper.randomStringToken();
|
||||||
|
@ -21,7 +22,7 @@ public boolean verifyClientSecureToken(String token, String secureKey) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean allowGetAccessToken(AuthResponse.AuthContext context) {
|
public boolean allowGetAccessToken(AuthResponse.AuthContext context) {
|
||||||
return (context.authType == AuthResponse.ConnectTypes.CLIENT);
|
return (context.authType == AuthResponse.ConnectTypes.CLIENT) && (!checkSecure || context.client.isSecure);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -49,7 +49,7 @@ public void pushJarFile(ZipInputStream input) throws IOException {
|
||||||
public void pushJarFile(ZipInputStream input, Set<String> blacklist) throws IOException {
|
public void pushJarFile(ZipInputStream input, Set<String> blacklist) throws IOException {
|
||||||
ZipEntry e = input.getNextEntry();
|
ZipEntry e = input.getNextEntry();
|
||||||
while (e != null) {
|
while (e != null) {
|
||||||
if (blacklist.contains(e.getName())) {
|
if (fileList.contains(e.getName()) || blacklist.contains(e.getName())) {
|
||||||
e = input.getNextEntry();
|
e = input.getNextEntry();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,6 +87,10 @@ private void setStringField(String name, String value)
|
||||||
public void setGuardType(String key) {
|
public void setGuardType(String key) {
|
||||||
setStringField("guardType", key);
|
setStringField("guardType", key);
|
||||||
}
|
}
|
||||||
|
public void setSecureCheck(String hash, String salt) {
|
||||||
|
setStringField("secureCheckHash", hash);
|
||||||
|
setStringField("secureCheckSalt", salt);
|
||||||
|
}
|
||||||
|
|
||||||
private void push(final int value) {
|
private void push(final int value) {
|
||||||
if (value >= -1 && value <= 5)
|
if (value >= -1 && value <= 5)
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.SimpleFileVisitor;
|
import java.nio.file.SimpleFileVisitor;
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
|
@ -133,6 +135,11 @@ public Path process(Path inputJar) throws IOException {
|
||||||
launcherConfigurator.setGuardType(server.config.launcher.guardType);
|
launcherConfigurator.setGuardType(server.config.launcher.guardType);
|
||||||
launcherConfigurator.setWarningMissArchJava(server.config.launcher.warningMissArchJava);
|
launcherConfigurator.setWarningMissArchJava(server.config.launcher.warningMissArchJava);
|
||||||
launcherConfigurator.setEnv(server.config.env);
|
launcherConfigurator.setEnv(server.config.env);
|
||||||
|
String launcherSalt = SecurityHelper.randomStringToken();
|
||||||
|
byte[] launcherSecureHash = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256,
|
||||||
|
server.runtime.clientCheckSecret.concat(".").concat(launcherSalt));
|
||||||
|
launcherConfigurator.setSecureCheck(Base64.getEncoder().encodeToString(launcherSecureHash), launcherSalt);
|
||||||
|
//LogHelper.debug("[checkSecure] %s: %s", launcherSalt, Arrays.toString(launcherSecureHash));
|
||||||
if (server.runtime.oemUnlockKey == null) server.runtime.oemUnlockKey = SecurityHelper.randomStringToken();
|
if (server.runtime.oemUnlockKey == null) server.runtime.oemUnlockKey = SecurityHelper.randomStringToken();
|
||||||
launcherConfigurator.setOemUnlockKey(server.runtime.oemUnlockKey);
|
launcherConfigurator.setOemUnlockKey(server.runtime.oemUnlockKey);
|
||||||
server.buildHookManager.registerAllClientModuleClass(launcherConfigurator);
|
server.buildHookManager.registerAllClientModuleClass(launcherConfigurator);
|
||||||
|
|
|
@ -30,7 +30,8 @@ public String getUsageDescription() {
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) throws Exception {
|
public void invoke(String... args) throws Exception {
|
||||||
verifyArgs(args, 2);
|
verifyArgs(args, 2);
|
||||||
Version version = Version.byName(args[0]);
|
//Version version = Version.byName(args[0]);
|
||||||
|
String versionName = args[0];
|
||||||
String dirName = IOHelper.verifyFileName(args[1]);
|
String dirName = IOHelper.verifyFileName(args[1]);
|
||||||
Path assetDir = server.updatesDir.resolve(dirName);
|
Path assetDir = server.updatesDir.resolve(dirName);
|
||||||
|
|
||||||
|
@ -40,7 +41,8 @@ public void invoke(String... args) throws Exception {
|
||||||
|
|
||||||
// Download required asset
|
// Download required asset
|
||||||
LogHelper.subInfo("Downloading asset, it may take some time");
|
LogHelper.subInfo("Downloading asset, it may take some time");
|
||||||
HttpDownloader.downloadZip(server.mirrorManager.getDefaultMirror().getAssetsURL(version.name), assetDir);
|
//HttpDownloader.downloadZip(server.mirrorManager.getDefaultMirror().getAssetsURL(version.name), assetDir);
|
||||||
|
server.mirrorManager.downloadZip(assetDir,"assets/%s.zip", versionName);
|
||||||
|
|
||||||
// Finished
|
// Finished
|
||||||
server.syncUpdatesDir(Collections.singleton(dirName));
|
server.syncUpdatesDir(Collections.singleton(dirName));
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
import pro.gravit.launcher.Launcher;
|
import pro.gravit.launcher.Launcher;
|
||||||
import pro.gravit.launcher.profiles.ClientProfile;
|
import pro.gravit.launcher.profiles.ClientProfile;
|
||||||
import pro.gravit.launcher.profiles.ClientProfile.Version;
|
import pro.gravit.launcher.profiles.ClientProfile.Version;
|
||||||
|
@ -36,7 +37,8 @@ public String getUsageDescription() {
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) throws IOException, CommandException {
|
public void invoke(String... args) throws IOException, CommandException {
|
||||||
verifyArgs(args, 2);
|
verifyArgs(args, 2);
|
||||||
Version version = Version.byName(args[0]);
|
//Version version = Version.byName(args[0]);
|
||||||
|
String versionName = args[0];
|
||||||
String dirName = IOHelper.verifyFileName(args[1]);
|
String dirName = IOHelper.verifyFileName(args[1]);
|
||||||
Path clientDir = server.updatesDir.resolve(args[1]);
|
Path clientDir = server.updatesDir.resolve(args[1]);
|
||||||
|
|
||||||
|
@ -46,14 +48,19 @@ public void invoke(String... args) throws IOException, CommandException {
|
||||||
|
|
||||||
// Download required client
|
// Download required client
|
||||||
LogHelper.subInfo("Downloading client, it may take some time");
|
LogHelper.subInfo("Downloading client, it may take some time");
|
||||||
HttpDownloader.downloadZip(server.mirrorManager.getDefaultMirror().getClientsURL(version.name), clientDir);
|
//HttpDownloader.downloadZip(server.mirrorManager.getDefaultMirror().getClientsURL(version.name), clientDir);
|
||||||
|
server.mirrorManager.downloadZip(clientDir,"clients/%s.zip", versionName);
|
||||||
|
|
||||||
// Create profile file
|
// Create profile file
|
||||||
LogHelper.subInfo("Creaing profile file: '%s'", dirName);
|
LogHelper.subInfo("Creaing profile file: '%s'", dirName);
|
||||||
ClientProfile client;
|
ClientProfile client;
|
||||||
String profilePath = String.format("pro/gravit/launchserver/defaults/profile%s.cfg", version.name);
|
String profilePath = String.format("pro/gravit/launchserver/defaults/profile%s.cfg", versionName);
|
||||||
try (BufferedReader reader = IOHelper.newReader(IOHelper.getResourceURL(profilePath))) {
|
try (BufferedReader reader = IOHelper.newReader(IOHelper.getResourceURL(profilePath))) {
|
||||||
client = Launcher.gsonManager.configGson.fromJson(reader, ClientProfile.class);
|
client = Launcher.gsonManager.configGson.fromJson(reader, ClientProfile.class);
|
||||||
|
} catch (IOException e)
|
||||||
|
{
|
||||||
|
JsonElement clientJson = server.mirrorManager.jsonRequest(null, "GET", "clients/%s.json", versionName);
|
||||||
|
client = Launcher.gsonManager.configGson.fromJson(clientJson, ClientProfile.class);
|
||||||
}
|
}
|
||||||
client.setTitle(dirName);
|
client.setTitle(dirName);
|
||||||
client.setDir(dirName);
|
client.setDir(dirName);
|
||||||
|
|
|
@ -7,13 +7,16 @@ public class LaunchServerRuntimeConfig {
|
||||||
public String clientToken;
|
public String clientToken;
|
||||||
public String oemUnlockKey;
|
public String oemUnlockKey;
|
||||||
public String registerApiKey;
|
public String registerApiKey;
|
||||||
|
public String clientCheckSecret;
|
||||||
|
|
||||||
public void verify() {
|
public void verify() {
|
||||||
if (clientToken == null) LogHelper.error("[RuntimeConfig] clientToken must not be null");
|
if (clientToken == null) LogHelper.error("[RuntimeConfig] clientToken must not be null");
|
||||||
|
if (clientCheckSecret == null) { LogHelper.warning("[RuntimeConfig] clientCheckSecret must not be null"); clientCheckSecret = SecurityHelper.randomStringToken(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
clientToken = SecurityHelper.randomStringToken();
|
clientToken = SecurityHelper.randomStringToken();
|
||||||
registerApiKey = SecurityHelper.randomStringToken();
|
registerApiKey = SecurityHelper.randomStringToken();
|
||||||
|
clientCheckSecret = SecurityHelper.randomStringToken();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,33 +1,36 @@
|
||||||
package pro.gravit.launchserver.manangers;
|
package pro.gravit.launchserver.manangers;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import pro.gravit.utils.HTTPRequest;
|
||||||
|
import pro.gravit.utils.HttpDownloader;
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
public class MirrorManager {
|
public class MirrorManager {
|
||||||
public class Mirror {
|
public static class Mirror {
|
||||||
URL url;
|
String baseUrl;
|
||||||
String assetsURLMask;
|
|
||||||
String clientsURLMask;
|
|
||||||
boolean enabled;
|
boolean enabled;
|
||||||
|
|
||||||
Mirror(String url) {
|
Mirror(String url) {
|
||||||
assetsURLMask = url.concat("assets/%s.zip");
|
//assetsURLMask = url.concat("assets/%s.zip");
|
||||||
clientsURLMask = url.concat("clients/%s.zip");
|
//clientsURLMask = url.concat("clients/%s.zip");
|
||||||
|
baseUrl = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
private URL formatArg(String mask, String arg) throws MalformedURLException {
|
private URL formatArgs(String mask, Object... args) throws MalformedURLException {
|
||||||
return new URL(String.format(mask, IOHelper.urlEncode(arg)));
|
Object[] data = Arrays.stream(args).map(e -> IOHelper.urlEncode(e.toString())).toArray();
|
||||||
|
return new URL(baseUrl.concat(String.format(mask, data)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public URL getAssetsURL(String assets) throws MalformedURLException {
|
public URL getURL(String mask, Object... args) throws MalformedURLException {
|
||||||
return formatArg(assetsURLMask, assets);
|
return formatArgs(mask, args);
|
||||||
}
|
|
||||||
|
|
||||||
public URL getClientsURL(String client) throws MalformedURLException {
|
|
||||||
return formatArg(clientsURLMask, client);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,13 +41,14 @@ public void addMirror(String mirror) {
|
||||||
Mirror m = new Mirror(mirror);
|
Mirror m = new Mirror(mirror);
|
||||||
m.enabled = true;
|
m.enabled = true;
|
||||||
if (defaultMirror == null) defaultMirror = m;
|
if (defaultMirror == null) defaultMirror = m;
|
||||||
|
list.add(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMirror(String mirror, boolean enabled) throws MalformedURLException {
|
public void addMirror(String mirror, boolean enabled) throws MalformedURLException {
|
||||||
Mirror m = new Mirror(mirror);
|
Mirror m = new Mirror(mirror);
|
||||||
m.url = new URL(mirror);
|
|
||||||
m.enabled = enabled;
|
m.enabled = enabled;
|
||||||
if (defaultMirror == null && enabled) defaultMirror = m;
|
if (defaultMirror == null && enabled) defaultMirror = m;
|
||||||
|
list.add(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mirror getDefaultMirror() {
|
public Mirror getDefaultMirror() {
|
||||||
|
@ -66,4 +70,61 @@ public void enableMirror(int index) {
|
||||||
public int size() {
|
public int size() {
|
||||||
return list.size();
|
return list.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean downloadZip(Mirror mirror, Path path, String mask, Object... args) throws IOException
|
||||||
|
{
|
||||||
|
if(!mirror.enabled) return false;
|
||||||
|
URL url = mirror.getURL(mask, args);
|
||||||
|
LogHelper.debug("Try download %s", url.toString());
|
||||||
|
try {
|
||||||
|
HttpDownloader.downloadZip(url, path);
|
||||||
|
} catch (IOException e)
|
||||||
|
{
|
||||||
|
LogHelper.error("Download %s failed(%s: %s)", url.toString(), e.getClass().getName(), e.getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void downloadZip(Path path, String mask, Object... args) throws IOException
|
||||||
|
{
|
||||||
|
if(downloadZip(defaultMirror, path, mask, args))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for(Mirror mirror : list)
|
||||||
|
{
|
||||||
|
if(mirror != defaultMirror)
|
||||||
|
{
|
||||||
|
if(downloadZip(mirror, path, mask, args)) return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IOException(String.format("Error download %s. All mirrors return error", path.toString()));
|
||||||
|
}
|
||||||
|
public JsonElement jsonRequest(Mirror mirror, JsonElement request, String method, String mask, Object... args) throws IOException
|
||||||
|
{
|
||||||
|
if(!mirror.enabled) return null;
|
||||||
|
URL url = mirror.getURL(mask, args);
|
||||||
|
try {
|
||||||
|
return HTTPRequest.jsonRequest(request, method, url);
|
||||||
|
} catch (IOException e)
|
||||||
|
{
|
||||||
|
LogHelper.error("JsonRequest %s failed(%s: %s)", url.toString(), e.getClass().getName(), e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public JsonElement jsonRequest(JsonElement request, String method, String mask, Object... args) throws IOException
|
||||||
|
{
|
||||||
|
JsonElement result = jsonRequest(defaultMirror, request, method, mask, args);
|
||||||
|
if(result != null) return result;
|
||||||
|
for(Mirror mirror : list)
|
||||||
|
{
|
||||||
|
if(mirror != defaultMirror)
|
||||||
|
{
|
||||||
|
result = jsonRequest(mirror, request, method, mask, args);
|
||||||
|
if(result != null) return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IOException("Error jsonRequest. All mirrors return error");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,15 +56,15 @@ public void initChannel(SocketChannel ch) {
|
||||||
ChannelPipeline pipeline = ch.pipeline();
|
ChannelPipeline pipeline = ch.pipeline();
|
||||||
NettyConnectContext context = new NettyConnectContext();
|
NettyConnectContext context = new NettyConnectContext();
|
||||||
//p.addLast(new LoggingHandler(LogLevel.INFO));
|
//p.addLast(new LoggingHandler(LogLevel.INFO));
|
||||||
pipeline.addLast(new HttpServerCodec());
|
pipeline.addLast("http-codec", new HttpServerCodec());
|
||||||
pipeline.addLast(new HttpObjectAggregator(65536));
|
pipeline.addLast("http-codec-compressor",new HttpObjectAggregator(65536));
|
||||||
if (server.config.netty.ipForwarding)
|
if (server.config.netty.ipForwarding)
|
||||||
pipeline.addLast(new NettyIpForwardHandler(context));
|
pipeline.addLast("forward-http", new NettyIpForwardHandler(context));
|
||||||
pipeline.addLast(new WebSocketServerCompressionHandler());
|
pipeline.addLast("websock-comp", new WebSocketServerCompressionHandler());
|
||||||
pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
|
pipeline.addLast("websock-codec", new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
|
||||||
if (server.config.netty.fileServerEnabled)
|
if (server.config.netty.fileServerEnabled)
|
||||||
pipeline.addLast(new FileServerHandler(server.updatesDir, true, config.showHiddenFiles));
|
pipeline.addLast("fileserver", new FileServerHandler(server.updatesDir, true, config.showHiddenFiles));
|
||||||
pipeline.addLast(new WebSocketFrameHandler(context, server, service));
|
pipeline.addLast("launchserver", new WebSocketFrameHandler(context, server, service));
|
||||||
pipelineHook.hook(context, ch);
|
pipelineHook.hook(context, ch);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -37,7 +37,6 @@
|
||||||
public class WebSocketService {
|
public class WebSocketService {
|
||||||
public final ChannelGroup channels;
|
public final ChannelGroup channels;
|
||||||
public static ProviderMap<WebSocketServerResponse> providers = new ProviderMap<>();
|
public static ProviderMap<WebSocketServerResponse> providers = new ProviderMap<>();
|
||||||
public final BiHookSet<TextWebSocketFrame, ChannelHandlerContext> packetHook = new BiHookSet<>();
|
|
||||||
public static class WebSocketRequestContext
|
public static class WebSocketRequestContext
|
||||||
{
|
{
|
||||||
public WebSocketServerResponse response;
|
public WebSocketServerResponse response;
|
||||||
|
@ -65,7 +64,6 @@ public WebSocketService(ChannelGroup channels, LaunchServer server) {
|
||||||
private final Gson gson;
|
private final Gson gson;
|
||||||
|
|
||||||
public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client, String ip) {
|
public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client, String ip) {
|
||||||
if (packetHook.hook(frame, ctx)) return;
|
|
||||||
String request = frame.text();
|
String request = frame.text();
|
||||||
WebSocketServerResponse response = gson.fromJson(request, WebSocketServerResponse.class);
|
WebSocketServerResponse response = gson.fromJson(request, WebSocketServerResponse.class);
|
||||||
process(ctx, response, client, ip);
|
process(ctx, response, client, ip);
|
||||||
|
|
|
@ -71,7 +71,7 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti
|
||||||
AuthProviderPair pair;
|
AuthProviderPair pair;
|
||||||
if (auth_id.isEmpty()) pair = server.config.getAuthProviderPair();
|
if (auth_id.isEmpty()) pair = server.config.getAuthProviderPair();
|
||||||
else pair = server.config.getAuthProviderPair(auth_id);
|
else pair = server.config.getAuthProviderPair(auth_id);
|
||||||
AuthContext context = new AuthContext(0, login, customText, client, null, ip, authType);
|
AuthContext context = new AuthContext(clientData, login, customText, client, hwid, ip, authType);
|
||||||
AuthProvider provider = pair.provider;
|
AuthProvider provider = pair.provider;
|
||||||
server.authHookManager.preHook.hook(context, clientData);
|
server.authHookManager.preHook.hook(context, clientData);
|
||||||
provider.preAuth(login, password, customText, ip);
|
provider.preAuth(login, password, customText, ip);
|
||||||
|
@ -130,24 +130,23 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class AuthContext {
|
public static class AuthContext {
|
||||||
public AuthContext(long session, String login, String customText, String client, String hwid, String ip, ConnectTypes authType) {
|
public AuthContext(Client client, String login, String customText, String profileName, HWID hwid, String ip, ConnectTypes authType) {
|
||||||
this.session = session;
|
this.client = client;
|
||||||
this.login = login;
|
this.login = login;
|
||||||
this.customText = customText;
|
this.customText = customText;
|
||||||
this.client = client;
|
this.profileName = profileName;
|
||||||
this.hwid = hwid;
|
this.hwid = hwid;
|
||||||
this.ip = ip;
|
this.ip = ip;
|
||||||
this.authType = authType;
|
this.authType = authType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long session;
|
|
||||||
public String login;
|
public String login;
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public int password_length; //Use AuthProvider for get password
|
public int password_length; //Use AuthProvider for get password
|
||||||
public String client;
|
public String profileName;
|
||||||
public String hwid;
|
public HWID hwid;
|
||||||
public String customText;
|
public String customText;
|
||||||
public String ip;
|
public String ip;
|
||||||
public ConnectTypes authType;
|
public ConnectTypes authType;
|
||||||
|
public Client client;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
import pro.gravit.launchserver.socket.Client;
|
import pro.gravit.launchserver.socket.Client;
|
||||||
import pro.gravit.launchserver.socket.response.SimpleResponse;
|
import pro.gravit.launchserver.socket.response.SimpleResponse;
|
||||||
import pro.gravit.utils.Version;
|
import pro.gravit.utils.Version;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
public class LauncherResponse extends SimpleResponse {
|
public class LauncherResponse extends SimpleResponse {
|
||||||
public Version version;
|
public Version version;
|
||||||
|
@ -15,6 +17,9 @@ public class LauncherResponse extends SimpleResponse {
|
||||||
public byte[] digest;
|
public byte[] digest;
|
||||||
public int launcher_type;
|
public int launcher_type;
|
||||||
|
|
||||||
|
public String secureHash;
|
||||||
|
public String secureSalt;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return "launcher";
|
return "launcher";
|
||||||
|
@ -33,6 +38,7 @@ public void execute(ChannelHandlerContext ctx, Client client) {
|
||||||
if (hash == null) service.sendObjectAndClose(ctx, new LauncherRequestEvent(true, server.config.netty.launcherURL));
|
if (hash == null) service.sendObjectAndClose(ctx, new LauncherRequestEvent(true, server.config.netty.launcherURL));
|
||||||
if (Arrays.equals(bytes, hash)) {
|
if (Arrays.equals(bytes, hash)) {
|
||||||
client.checkSign = true;
|
client.checkSign = true;
|
||||||
|
client.isSecure = checkSecure(secureHash, secureSalt);
|
||||||
sendResult(new LauncherRequestEvent(false, server.config.netty.launcherURL));
|
sendResult(new LauncherRequestEvent(false, server.config.netty.launcherURL));
|
||||||
} else {
|
} else {
|
||||||
sendResultAndClose(new LauncherRequestEvent(true, server.config.netty.launcherURL));
|
sendResultAndClose(new LauncherRequestEvent(true, server.config.netty.launcherURL));
|
||||||
|
@ -43,12 +49,21 @@ public void execute(ChannelHandlerContext ctx, Client client) {
|
||||||
if (hash == null) sendResultAndClose(new LauncherRequestEvent(true, server.config.netty.launcherEXEURL));
|
if (hash == null) sendResultAndClose(new LauncherRequestEvent(true, server.config.netty.launcherEXEURL));
|
||||||
if (Arrays.equals(bytes, hash)) {
|
if (Arrays.equals(bytes, hash)) {
|
||||||
client.checkSign = true;
|
client.checkSign = true;
|
||||||
|
client.isSecure = checkSecure(secureHash, secureSalt);
|
||||||
sendResult(new LauncherRequestEvent(false, server.config.netty.launcherEXEURL));
|
sendResult(new LauncherRequestEvent(false, server.config.netty.launcherEXEURL));
|
||||||
} else {
|
} else {
|
||||||
sendResultAndClose(new LauncherRequestEvent(true, server.config.netty.launcherEXEURL));
|
sendResultAndClose(new LauncherRequestEvent(true, server.config.netty.launcherEXEURL));
|
||||||
}
|
}
|
||||||
} else sendError("Request launcher type error");
|
} else sendError("Request launcher type error");
|
||||||
|
}
|
||||||
|
private boolean checkSecure(String hash, String salt)
|
||||||
|
{
|
||||||
|
if(hash == null || salt == null) return false;
|
||||||
|
byte[] normal_hash = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256,
|
||||||
|
server.runtime.clientCheckSecret.concat(".").concat(salt));
|
||||||
|
byte[] launcher_hash = Base64.getDecoder().decode(hash);
|
||||||
|
//LogHelper.debug("[checkSecure] %s vs %s", Arrays.toString(normal_hash), Arrays.toString(launcher_hash));
|
||||||
|
return Arrays.equals(normal_hash, launcher_hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,18 +32,33 @@ public boolean isAgentStarted() {
|
||||||
|
|
||||||
public static void premain(String agentArgument, Instrumentation instrumentation) {
|
public static void premain(String agentArgument, Instrumentation instrumentation) {
|
||||||
System.out.println("Launcher Agent");
|
System.out.println("Launcher Agent");
|
||||||
|
checkAgentStacktrace();
|
||||||
inst = instrumentation;
|
inst = instrumentation;
|
||||||
SafeExitJVMLegacy.class.getName();
|
//SafeExitJVMLegacy.class.getName();
|
||||||
SafeExitJVM.class.getName();
|
//SafeExitJVM.class.getName();
|
||||||
NativeJVMHalt.class.getName();
|
//NativeJVMHalt.class.getName();
|
||||||
NativeJVMHalt.initFunc();
|
//NativeJVMHalt.initFunc();
|
||||||
boolean bad = false;
|
isAgentStarted = true;
|
||||||
try {
|
}
|
||||||
for (StackTraceElement e : new Throwable().getStackTrace())
|
public static void checkAgentStacktrace()
|
||||||
if (Class.forName(e.getClassName()).getClassLoader() != Runtime.class.getClassLoader() && Class.forName(e.getClassName()) != LauncherAgent.class) bad = true;
|
{
|
||||||
} catch(Throwable e) { bad = true; }
|
RuntimeException ex = new SecurityException("Error check agent stacktrace");
|
||||||
if (bad) NativeJVMHalt.haltA(-17);
|
boolean isFoundNative = false;
|
||||||
else isAgentStarted = true;
|
boolean foundPreMain = false;
|
||||||
|
for(StackTraceElement e : ex.getStackTrace())
|
||||||
|
{
|
||||||
|
if(e.isNativeMethod())
|
||||||
|
{
|
||||||
|
if(!isFoundNative) isFoundNative = true;
|
||||||
|
else throw ex;
|
||||||
|
}
|
||||||
|
if(e.getMethodName().equals("premain"))
|
||||||
|
{
|
||||||
|
if(!foundPreMain) foundPreMain = true;
|
||||||
|
else throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!isFoundNative || !foundPreMain) throw ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isStarted() {
|
public static boolean isStarted() {
|
||||||
|
|
|
@ -595,15 +595,11 @@ public static interface ParamsAPI {
|
||||||
public static ParamsAPI container = new ParamsAPI() {
|
public static ParamsAPI container = new ParamsAPI() {
|
||||||
@Override
|
@Override
|
||||||
public ParamContainer read() throws Exception {
|
public ParamContainer read() throws Exception {
|
||||||
ParamContainer p = new ParamContainer();
|
ParamContainer p;
|
||||||
try (Socket socket = IOHelper.newSocket()) {
|
try (Socket socket = IOHelper.newSocket()) {
|
||||||
socket.connect(new InetSocketAddress(SOCKET_HOST, SOCKET_PORT));
|
socket.connect(new InetSocketAddress(SOCKET_HOST, SOCKET_PORT));
|
||||||
try (HInput input = new HInput(socket.getInputStream())) {
|
try (HInput input = new HInput(socket.getInputStream())) {
|
||||||
p.params = new Params(input);
|
p = new ParamContainer(input);
|
||||||
p.profile = Launcher.gsonManager.gson.fromJson(input.readString(0), ClientProfile.class);
|
|
||||||
p.assetHDir = new HashedDir(input);
|
|
||||||
p.clientHDir = new HashedDir(input);
|
|
||||||
ClientHookManager.paramsInputHook.hook(input);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
|
@ -630,11 +626,7 @@ public void write(ParamContainer p) throws Exception {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try (HOutput output = new HOutput(client.getOutputStream())) {
|
try (HOutput output = new HOutput(client.getOutputStream())) {
|
||||||
p.params.write(output);
|
p.write(output);
|
||||||
output.writeString(Launcher.gsonManager.gson.toJson(p.profile), 0);
|
|
||||||
p.assetHDir.write(output);
|
|
||||||
p.clientHDir.write(output);
|
|
||||||
ClientHookManager.paramsOutputHook.hook(output);
|
|
||||||
}
|
}
|
||||||
clientStarted = true;
|
clientStarted = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@ public class AutogenConfig {
|
||||||
public String guardLicenseName;
|
public String guardLicenseName;
|
||||||
public String guardLicenseKey;
|
public String guardLicenseKey;
|
||||||
public String guardLicenseEncryptKey;
|
public String guardLicenseEncryptKey;
|
||||||
|
public String secureCheckHash;
|
||||||
|
public String secureCheckSalt;
|
||||||
public int env;
|
public int env;
|
||||||
public boolean isWarningMissArchJava;
|
public boolean isWarningMissArchJava;
|
||||||
// 0 - Dev (дебаг включен по умолчанию, все сообщения)
|
// 0 - Dev (дебаг включен по умолчанию, все сообщения)
|
||||||
|
|
|
@ -43,10 +43,15 @@ public static AutogenConfig getAutogenConfig() {
|
||||||
public final String guardLicenseKey;
|
public final String guardLicenseKey;
|
||||||
public final String guardLicenseEncryptKey;
|
public final String guardLicenseEncryptKey;
|
||||||
public final String guardType;
|
public final String guardType;
|
||||||
|
|
||||||
|
public final String secureCheckHash;
|
||||||
|
public final String secureCheckSalt;
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException {
|
public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException {
|
||||||
publicKey = SecurityHelper.toPublicRSAKey(input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH));
|
publicKey = SecurityHelper.toPublicRSAKey(input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH));
|
||||||
|
secureCheckHash = config.secureCheckHash;
|
||||||
|
secureCheckSalt = config.secureCheckSalt;
|
||||||
projectname = config.projectname;
|
projectname = config.projectname;
|
||||||
clientPort = config.clientPort;
|
clientPort = config.clientPort;
|
||||||
secretKeyClient = config.secretKeyClient;
|
secretKeyClient = config.secretKeyClient;
|
||||||
|
@ -92,6 +97,8 @@ public LauncherConfig(String address, RSAPublicKey publicKey, Map<String, byte[]
|
||||||
isWarningMissArchJava = true;
|
isWarningMissArchJava = true;
|
||||||
isNettyEnabled = false;
|
isNettyEnabled = false;
|
||||||
environment = LauncherEnvironment.STD;
|
environment = LauncherEnvironment.STD;
|
||||||
|
secureCheckSalt = null;
|
||||||
|
secureCheckHash = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
@ -108,6 +115,8 @@ public LauncherConfig(String address, RSAPublicKey publicKey, Map<String, byte[]
|
||||||
isWarningMissArchJava = true;
|
isWarningMissArchJava = true;
|
||||||
isNettyEnabled = false;
|
isNettyEnabled = false;
|
||||||
environment = LauncherEnvironment.STD;
|
environment = LauncherEnvironment.STD;
|
||||||
|
secureCheckSalt = null;
|
||||||
|
secureCheckHash = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,6 +24,10 @@ public final class LauncherRequest extends Request<LauncherRequestEvent> impleme
|
||||||
@LauncherNetworkAPI
|
@LauncherNetworkAPI
|
||||||
public byte[] digest;
|
public byte[] digest;
|
||||||
@LauncherNetworkAPI
|
@LauncherNetworkAPI
|
||||||
|
public String secureHash;
|
||||||
|
@LauncherNetworkAPI
|
||||||
|
public String secureSalt;
|
||||||
|
@LauncherNetworkAPI
|
||||||
public int launcher_type = EXE_BINARY ? 2 : 1;
|
public int launcher_type = EXE_BINARY ? 2 : 1;
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static final Path BINARY_PATH = IOHelper.getCodeSource(Launcher.class);
|
public static final Path BINARY_PATH = IOHelper.getCodeSource(Launcher.class);
|
||||||
|
@ -89,6 +93,8 @@ public LauncherRequest() {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogHelper.error(e);
|
LogHelper.error(e);
|
||||||
}
|
}
|
||||||
|
secureHash = Launcher.getConfig().secureCheckHash;
|
||||||
|
secureSalt = Launcher.getConfig().secureCheckSalt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -39,19 +39,22 @@ public static int sendCrashreport(String strurl, String data) throws IOException
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonElement jsonRequest(JsonElement request, URL url) throws IOException {
|
public static JsonElement jsonRequest(JsonElement request, URL url) throws IOException {
|
||||||
|
return jsonRequest(request, "POST", url);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JsonElement jsonRequest(JsonElement request, String method, URL url) throws IOException {
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
connection.setDoInput(true);
|
connection.setDoInput(true);
|
||||||
connection.setDoOutput(true);
|
if(request != null) connection.setDoOutput(true);
|
||||||
connection.setRequestMethod("POST");
|
connection.setRequestMethod(method);
|
||||||
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
|
if(request != null) connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
|
||||||
connection.setRequestProperty("Accept", "application/json");
|
connection.setRequestProperty("Accept", "application/json");
|
||||||
if (TIMEOUT > 0)
|
if (TIMEOUT > 0)
|
||||||
connection.setConnectTimeout(TIMEOUT);
|
connection.setConnectTimeout(TIMEOUT);
|
||||||
|
if(request != null) try (OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), StandardCharsets.UTF_8)) {
|
||||||
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), Charset.forName("UTF-8"));
|
writer.write(request.toString());
|
||||||
writer.write(request.toString());
|
writer.flush();
|
||||||
writer.flush();
|
}
|
||||||
writer.close();
|
|
||||||
|
|
||||||
InputStreamReader reader;
|
InputStreamReader reader;
|
||||||
int statusCode = connection.getResponseCode();
|
int statusCode = connection.getResponseCode();
|
||||||
|
|
Loading…
Reference in a new issue