mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
Merge branch 'release/5.2.13'
This commit is contained in:
commit
b7a6cfda6d
17 changed files with 407 additions and 32 deletions
|
@ -29,6 +29,9 @@ public HttpHelper.HttpOptional<T, SimpleError> applyJson(JsonElement response, i
|
||||||
if(statusCode < 200 || statusCode >= 300) {
|
if(statusCode < 200 || statusCode >= 300) {
|
||||||
return new HttpHelper.HttpOptional<>(null, Launcher.gsonManager.gson.fromJson(response, SimpleError.class), statusCode);
|
return new HttpHelper.HttpOptional<>(null, Launcher.gsonManager.gson.fromJson(response, SimpleError.class), statusCode);
|
||||||
}
|
}
|
||||||
|
if(type == Void.class) {
|
||||||
|
return new HttpHelper.HttpOptional<>(null, null, statusCode);
|
||||||
|
}
|
||||||
return new HttpHelper.HttpOptional<>(Launcher.gsonManager.gson.fromJson(response, type), null, statusCode);
|
return new HttpHelper.HttpOptional<>(Launcher.gsonManager.gson.fromJson(response, type), null, statusCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,12 +150,12 @@ protected boolean updateServerID(User user, String serverID) throws IOException
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User checkServer(Client client, String username, String serverID) throws IOException {
|
public User checkServer(Client client, String username, String serverID) throws IOException {
|
||||||
return requester.send(requester.post(checkServerUrl, new CheckServerRequest(username, serverID), null), HttpUser.class).getOrThrow();
|
return requester.send(requester.post(checkServerUrl, new CheckServerRequest(username, serverID), bearerToken), HttpUser.class).getOrThrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean joinServer(Client client, String username, String accessToken, String serverID) throws IOException {
|
public boolean joinServer(Client client, String username, String accessToken, String serverID) throws IOException {
|
||||||
var result = requester.send(requester.post(joinServerUrl, new JoinServerRequest(username, accessToken, serverID), null), Void.class);
|
var result = requester.send(requester.post(joinServerUrl, new JoinServerRequest(username, accessToken, serverID), bearerToken), Void.class);
|
||||||
return result.isSuccessful();
|
return result.isSuccessful();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
import pro.gravit.launcher.events.request.AuthRequestEvent;
|
import pro.gravit.launcher.events.request.AuthRequestEvent;
|
||||||
import pro.gravit.launcher.profiles.ClientProfile;
|
import pro.gravit.launcher.profiles.ClientProfile;
|
||||||
import pro.gravit.launcher.profiles.PlayerProfile;
|
import pro.gravit.launcher.profiles.PlayerProfile;
|
||||||
import pro.gravit.launcher.profiles.Texture;
|
|
||||||
import pro.gravit.launcher.request.auth.AuthRequest;
|
import pro.gravit.launcher.request.auth.AuthRequest;
|
||||||
import pro.gravit.launcher.request.auth.password.*;
|
import pro.gravit.launcher.request.auth.password.*;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
@ -84,7 +83,7 @@ public boolean accept(Client client, AuthProviderPair pair, String extendedToken
|
||||||
if(client.permissions == null) client.permissions = new ClientPermissions();
|
if(client.permissions == null) client.permissions = new ClientPermissions();
|
||||||
client.permissions.addPerm("launchserver.checkserver");
|
client.permissions.addPerm("launchserver.checkserver");
|
||||||
client.permissions.addPerm(String.format("launchserver.profile.%s.show", info.serverName));
|
client.permissions.addPerm(String.format("launchserver.profile.%s.show", info.serverName));
|
||||||
client.setSerializableProperty("launchserver.serverName", info.serverName);
|
client.setProperty("launchserver.serverName", info.serverName);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
public class Client {
|
public class Client {
|
||||||
public String auth_id;
|
public String auth_id;
|
||||||
|
@ -32,7 +31,7 @@ public class Client {
|
||||||
|
|
||||||
public transient Map<String, Object> properties;
|
public transient Map<String, Object> properties;
|
||||||
|
|
||||||
public Map<String, String> serializableProperties;
|
public Map<String, Object> staticProperties;
|
||||||
|
|
||||||
public Client() {
|
public Client() {
|
||||||
timestamp = System.currentTimeMillis();
|
timestamp = System.currentTimeMillis();
|
||||||
|
@ -65,14 +64,15 @@ public <T> void setProperty(String name, T object) {
|
||||||
properties.put(name, object);
|
properties.put(name, object);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSerializableProperty(String name) {
|
@SuppressWarnings("unchecked")
|
||||||
if (serializableProperties == null) serializableProperties = new HashMap<>();
|
public<T> T getStaticProperty(String name) {
|
||||||
return serializableProperties.get(name);
|
if (staticProperties == null) staticProperties = new HashMap<>();
|
||||||
|
return (T) staticProperties.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSerializableProperty(String name, String value) {
|
public<T> void setStaticProperty(String name, T value) {
|
||||||
if (serializableProperties == null) serializableProperties = new HashMap<>();
|
if (staticProperties == null) staticProperties = new HashMap<>();
|
||||||
serializableProperties.put(name, value);
|
staticProperties.put(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public pro.gravit.launchserver.auth.core.User getUser() {
|
public pro.gravit.launchserver.auth.core.User getUser() {
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
import pro.gravit.launchserver.socket.handlers.WebSocketFrameHandler;
|
import pro.gravit.launchserver.socket.handlers.WebSocketFrameHandler;
|
||||||
import pro.gravit.launchserver.socket.response.SimpleResponse;
|
import pro.gravit.launchserver.socket.response.SimpleResponse;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class ExitResponse extends SimpleResponse {
|
public class ExitResponse extends SimpleResponse {
|
||||||
public boolean exitAll;
|
public boolean exitAll;
|
||||||
public String username;
|
public String username;
|
||||||
|
@ -20,6 +22,9 @@ public static void exit(LaunchServer server, WebSocketFrameHandler wsHandler, Ch
|
||||||
Client chClient = wsHandler.getClient();
|
Client chClient = wsHandler.getClient();
|
||||||
Client newCusClient = new Client();
|
Client newCusClient = new Client();
|
||||||
newCusClient.checkSign = chClient.checkSign;
|
newCusClient.checkSign = chClient.checkSign;
|
||||||
|
if(chClient.staticProperties != null) {
|
||||||
|
newCusClient.staticProperties = new HashMap<>(chClient.staticProperties);
|
||||||
|
}
|
||||||
wsHandler.setClient(newCusClient);
|
wsHandler.setClient(newCusClient);
|
||||||
ExitRequestEvent event = new ExitRequestEvent(reason);
|
ExitRequestEvent event = new ExitRequestEvent(reason);
|
||||||
event.requestUUID = RequestEvent.eventUUID;
|
event.requestUUID = RequestEvent.eventUUID;
|
||||||
|
|
|
@ -200,7 +200,7 @@ public static void main(String[] args) throws Throwable {
|
||||||
CommonHelper.newThread("Asset Directory Watcher", true, assetWatcher).start();
|
CommonHelper.newThread("Asset Directory Watcher", true, assetWatcher).start();
|
||||||
CommonHelper.newThread("Client Directory Watcher", true, clientWatcher).start();
|
CommonHelper.newThread("Client Directory Watcher", true, clientWatcher).start();
|
||||||
if (javaWatcher != null)
|
if (javaWatcher != null)
|
||||||
CommonHelper.newThread("Java Directory Watcher", true, clientWatcher).start();
|
CommonHelper.newThread("Java Directory Watcher", true, javaWatcher).start();
|
||||||
verifyHDir(assetDir, params.assetHDir, assetMatcher, digest);
|
verifyHDir(assetDir, params.assetHDir, assetMatcher, digest);
|
||||||
verifyHDir(clientDir, params.clientHDir, clientMatcher, digest);
|
verifyHDir(clientDir, params.clientHDir, clientMatcher, digest);
|
||||||
if (javaWatcher != null)
|
if (javaWatcher != null)
|
||||||
|
|
|
@ -483,7 +483,8 @@ public enum Version {
|
||||||
MC1171("1.17.1", 756),
|
MC1171("1.17.1", 756),
|
||||||
MC118("1.18", 757),
|
MC118("1.18", 757),
|
||||||
MC1181("1.18.1", 757),
|
MC1181("1.18.1", 757),
|
||||||
MC1182("1.18.2", 758);
|
MC1182("1.18.2", 758),
|
||||||
|
MC119("1.19", 759);
|
||||||
private static final Map<String, Version> VERSIONS;
|
private static final Map<String, Version> VERSIONS;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
|
@ -6,7 +6,7 @@ public final class Version implements Comparable<Version> {
|
||||||
|
|
||||||
public static final int MAJOR = 5;
|
public static final int MAJOR = 5;
|
||||||
public static final int MINOR = 2;
|
public static final int MINOR = 2;
|
||||||
public static final int PATCH = 12;
|
public static final int PATCH = 13;
|
||||||
public static final int BUILD = 1;
|
public static final int BUILD = 1;
|
||||||
public static final Version.Type RELEASE = Type.STABLE;
|
public static final Version.Type RELEASE = Type.STABLE;
|
||||||
public final int major;
|
public final int major;
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
import pro.gravit.launcher.config.JsonConfigurable;
|
import pro.gravit.launcher.config.JsonConfigurable;
|
||||||
import pro.gravit.launcher.events.request.AuthRequestEvent;
|
import pro.gravit.launcher.events.request.AuthRequestEvent;
|
||||||
import pro.gravit.launcher.events.request.ProfilesRequestEvent;
|
import pro.gravit.launcher.events.request.ProfilesRequestEvent;
|
||||||
import pro.gravit.launcher.modules.events.PostInitPhase;
|
|
||||||
import pro.gravit.launcher.modules.events.PreConfigPhase;
|
|
||||||
import pro.gravit.launcher.profiles.ClientProfile;
|
import pro.gravit.launcher.profiles.ClientProfile;
|
||||||
import pro.gravit.launcher.profiles.PlayerProfile;
|
import pro.gravit.launcher.profiles.PlayerProfile;
|
||||||
import pro.gravit.launcher.profiles.optional.actions.OptionalAction;
|
import pro.gravit.launcher.profiles.optional.actions.OptionalAction;
|
||||||
|
@ -15,9 +13,9 @@
|
||||||
import pro.gravit.launcher.request.Request;
|
import pro.gravit.launcher.request.Request;
|
||||||
import pro.gravit.launcher.request.auth.AuthRequest;
|
import pro.gravit.launcher.request.auth.AuthRequest;
|
||||||
import pro.gravit.launcher.request.auth.GetAvailabilityAuthRequest;
|
import pro.gravit.launcher.request.auth.GetAvailabilityAuthRequest;
|
||||||
import pro.gravit.launcher.request.auth.RestoreRequest;
|
|
||||||
import pro.gravit.launcher.request.update.ProfilesRequest;
|
import pro.gravit.launcher.request.update.ProfilesRequest;
|
||||||
import pro.gravit.launcher.request.websockets.StdWebSocketService;
|
import pro.gravit.launcher.request.websockets.StdWebSocketService;
|
||||||
|
import pro.gravit.launcher.server.authlib.InstallAuthlib;
|
||||||
import pro.gravit.launcher.server.launch.ClasspathLaunch;
|
import pro.gravit.launcher.server.launch.ClasspathLaunch;
|
||||||
import pro.gravit.launcher.server.launch.Launch;
|
import pro.gravit.launcher.server.launch.Launch;
|
||||||
import pro.gravit.launcher.server.launch.ModuleLaunch;
|
import pro.gravit.launcher.server.launch.ModuleLaunch;
|
||||||
|
@ -27,12 +25,7 @@
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.invoke.MethodHandle;
|
|
||||||
import java.lang.invoke.MethodHandles;
|
|
||||||
import java.lang.invoke.MethodType;
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -112,6 +105,13 @@ public void run(String... args) throws Throwable {
|
||||||
setup.run();
|
setup.run();
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
if (args.length > 1 && args[0].equals("installAuthlib") && !disableSetup) {
|
||||||
|
LogHelper.debug("Read ServerWrapperConfig.json");
|
||||||
|
loadConfig();
|
||||||
|
InstallAuthlib command = new InstallAuthlib();
|
||||||
|
command. run(args[1]);
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
LogHelper.debug("Read ServerWrapperConfig.json");
|
LogHelper.debug("Read ServerWrapperConfig.json");
|
||||||
loadConfig();
|
loadConfig();
|
||||||
updateLauncherConfig();
|
updateLauncherConfig();
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package pro.gravit.launcher.server.authlib;
|
||||||
|
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
public class DownloadContextModifier implements LibrariesHashFileModifier {
|
||||||
|
@Override
|
||||||
|
public byte[] apply(byte[] data, InstallAuthlib.InstallAuthlibContext context) throws IOException {
|
||||||
|
String[] lines = new String(data).split("\n");
|
||||||
|
for(int i=0;i<lines.length;++i) {
|
||||||
|
if(lines[i].contains("mojang_")) {
|
||||||
|
String[] separated = lines[i].split("\t");
|
||||||
|
Path path = context.workdir.resolve("cache").resolve(separated[2]);
|
||||||
|
if(Files.notExists(path)) {
|
||||||
|
LogHelper.warning("Unable to find %s. Maybe you should start the server at least once?", path);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
separated[0] = SecurityHelper.toHex(SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, path));
|
||||||
|
lines[i] = String.join("\t", separated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return String.join("\n", lines).getBytes(StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,252 @@
|
||||||
|
package pro.gravit.launcher.server.authlib;
|
||||||
|
|
||||||
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.file.*;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipInputStream;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
public class InstallAuthlib {
|
||||||
|
private static Map<String, LibrariesHashFileModifier> modifierMap;
|
||||||
|
static {
|
||||||
|
modifierMap = new HashMap<>();
|
||||||
|
modifierMap.put("META-INF/libraries.list", new LibrariesLstModifier());
|
||||||
|
modifierMap.put("patch.properties", new PatchPropertiesModifier());
|
||||||
|
modifierMap.put("META-INF/download-context", new DownloadContextModifier());
|
||||||
|
}
|
||||||
|
public void run(String... args) throws Exception {
|
||||||
|
boolean deleteAuthlibAfterInstall = false;
|
||||||
|
InstallAuthlibContext context = new InstallAuthlibContext();
|
||||||
|
if(args[0].startsWith("http://") || args[0].startsWith("https://")) {
|
||||||
|
Path tempAuthlib = Paths.get("authlib.jar");
|
||||||
|
LogHelper.info("Download %s to %s", args[0], tempAuthlib);
|
||||||
|
try(InputStream input = IOHelper.newInput(new URL(args[0]))) {
|
||||||
|
IOHelper.transfer(input, tempAuthlib);
|
||||||
|
}
|
||||||
|
context.pathToAuthlib = tempAuthlib;
|
||||||
|
deleteAuthlibAfterInstall = true;
|
||||||
|
} else {
|
||||||
|
context.pathToAuthlib = Paths.get(args[0]);
|
||||||
|
}
|
||||||
|
if(Files.notExists(context.pathToAuthlib)) {
|
||||||
|
throw new FileNotFoundException(context.pathToAuthlib.toString());
|
||||||
|
}
|
||||||
|
context.workdir = IOHelper.WORKING_DIR;
|
||||||
|
LogHelper.info("Search .jar files in %s", context.workdir.toAbsolutePath());
|
||||||
|
IOHelper.walk(context.workdir, new SimpleFileVisitor<Path>() {
|
||||||
|
@Override
|
||||||
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||||
|
if(file.getFileName().toString().endsWith(".jar")) {
|
||||||
|
context.files.add(file);
|
||||||
|
}
|
||||||
|
return FileVisitResult.CONTINUE;
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
LogHelper.info("Search authlib in %d files", context.files.size());
|
||||||
|
for(Path path : context.files) {
|
||||||
|
boolean foundAuthlib = false;
|
||||||
|
try(ZipInputStream input = IOHelper.newZipInput(path)) {
|
||||||
|
ZipEntry e = input.getNextEntry();
|
||||||
|
while(e != null) {
|
||||||
|
String name = e.getName();
|
||||||
|
if(!e.isDirectory() && name.contains("com/mojang/authlib") && !foundAuthlib) {
|
||||||
|
boolean isJarFile = name.endsWith(".jar");
|
||||||
|
String prefix = isJarFile ? name : name.substring(0, name.indexOf("com/mojang/authlib"));
|
||||||
|
context.repack.add(new RepackInfo(path, prefix, isJarFile));
|
||||||
|
foundAuthlib = true;
|
||||||
|
}
|
||||||
|
if(!e.isDirectory() && modifierMap.containsKey(name)) {
|
||||||
|
context.hashes.add(new HashFile(path, name, modifierMap.get(name)));
|
||||||
|
}
|
||||||
|
e = input.getNextEntry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Path tmpFile = Paths.get("repack.tmp");
|
||||||
|
for(RepackInfo ri : context.repack) {
|
||||||
|
LogHelper.info("Found authlib in %s (prefix '%s' jar %s)", ri.path, ri.prefix, ri.isJarFile ? "true" : "false");
|
||||||
|
try(ZipInputStream input = IOHelper.newZipInput(ri.path)) {
|
||||||
|
try(ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(tmpFile))) {
|
||||||
|
ZipEntry e;
|
||||||
|
e = input.getNextEntry();
|
||||||
|
while(e != null) {
|
||||||
|
if(!e.getName().equals("META-INF") && !e.getName().equals("META-INF/") && !e.getName().equals("META-INF/MANIFEST.MF")) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ZipEntry newEntry = IOHelper.newZipEntry(e);
|
||||||
|
output.putNextEntry(newEntry);
|
||||||
|
IOHelper.transfer(input, output);
|
||||||
|
e = input.getNextEntry();
|
||||||
|
}
|
||||||
|
if(!ri.isJarFile) {
|
||||||
|
try(ZipInputStream input2 = new ZipInputStream(IOHelper.newInput(context.pathToAuthlib))) {
|
||||||
|
ZipEntry e2 = input2.getNextEntry();
|
||||||
|
while(e2 != null) {
|
||||||
|
if(e2.getName().startsWith("META-INF")) {
|
||||||
|
e2 = input2.getNextEntry();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String newName = !ri.prefix.endsWith("/") && !e2.getName().startsWith("/") && !ri.prefix.isEmpty() ?
|
||||||
|
ri.prefix.concat("/").concat(e2.getName()) : ri.prefix.concat(e2.getName());
|
||||||
|
ZipEntry newEntry = IOHelper.newZipEntry(newName);
|
||||||
|
output.putNextEntry(newEntry);
|
||||||
|
IOHelper.transfer(input2, output);
|
||||||
|
e2 = input2.getNextEntry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while(e != null) {
|
||||||
|
if(e.getName().startsWith(ri.prefix)) {
|
||||||
|
if(ri.isJarFile) {
|
||||||
|
if(context.repackedAuthlibBytes == null) {
|
||||||
|
byte[] orig = IOHelper.read(input);
|
||||||
|
context.repackedAuthlibBytes = repackAuthlibJar(orig, context.pathToAuthlib);
|
||||||
|
}
|
||||||
|
ZipEntry newEntry = IOHelper.newZipEntry(e);
|
||||||
|
output.putNextEntry(newEntry);
|
||||||
|
output.write(context.repackedAuthlibBytes);
|
||||||
|
e = input.getNextEntry();
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
if(context.repackedAuthlibFiles == null) {
|
||||||
|
context.repackedAuthlibFiles = getNames(context.pathToAuthlib);
|
||||||
|
}
|
||||||
|
if(context.repackedAuthlibFiles.contains(e.getName().substring(ri.prefix.length()))) {
|
||||||
|
e = input.getNextEntry();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ZipEntry newEntry = IOHelper.newZipEntry(e);
|
||||||
|
output.putNextEntry(newEntry);
|
||||||
|
IOHelper.transfer(input, output);
|
||||||
|
e = input.getNextEntry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Files.delete(ri.path);
|
||||||
|
Files.move(tmpFile, ri.path);
|
||||||
|
}
|
||||||
|
LogHelper.info("%d authlib files repacked", context.repack.size());
|
||||||
|
for(HashFile hf : context.hashes) {
|
||||||
|
LogHelper.info("Found hash file %s in %s", hf.prefix, hf.path);
|
||||||
|
try(ZipInputStream input = IOHelper.newZipInput(hf.path)) {
|
||||||
|
try (ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(tmpFile))) {
|
||||||
|
ZipEntry e = input.getNextEntry();
|
||||||
|
while(e != null) {
|
||||||
|
ZipEntry newEntry = IOHelper.newZipEntry(e);
|
||||||
|
output.putNextEntry(newEntry);
|
||||||
|
if(e.getName().equals(hf.prefix)) {
|
||||||
|
byte[] orig = IOHelper.read(input);
|
||||||
|
byte[] bytes = hf.modifier.apply(orig, context);
|
||||||
|
output.write(bytes);
|
||||||
|
} else {
|
||||||
|
IOHelper.transfer(input, output);
|
||||||
|
}
|
||||||
|
e = input.getNextEntry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Files.delete(hf.path);
|
||||||
|
Files.move(tmpFile, hf.path);
|
||||||
|
}
|
||||||
|
LogHelper.info("%d hash files repacked", context.hashes.size());
|
||||||
|
if(deleteAuthlibAfterInstall) {
|
||||||
|
LogHelper.info("Delete %s", context.pathToAuthlib);
|
||||||
|
Files.delete(context.pathToAuthlib);
|
||||||
|
}
|
||||||
|
LogHelper.info("Completed");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set<String> getNames(Path path) throws IOException {
|
||||||
|
Set<String> set = new HashSet<>();
|
||||||
|
try(ZipInputStream input = IOHelper.newZipInput(path)) {
|
||||||
|
ZipEntry e = input.getNextEntry();
|
||||||
|
while(e != null) {
|
||||||
|
if(!e.getName().startsWith("META-INF")) {
|
||||||
|
set.add(e.getName());
|
||||||
|
}
|
||||||
|
e = input.getNextEntry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] repackAuthlibJar(byte[] data, Path path) throws IOException {
|
||||||
|
try(ZipInputStream input = new ZipInputStream(new ByteArrayInputStream(data))) {
|
||||||
|
ByteArrayOutputStream result = new ByteArrayOutputStream();
|
||||||
|
try(ZipOutputStream output = new ZipOutputStream(result)) {
|
||||||
|
Set<String> blacklist = new HashSet<>();
|
||||||
|
try(ZipInputStream input2 = IOHelper.newZipInput(path)) {
|
||||||
|
ZipEntry e = input2.getNextEntry();
|
||||||
|
while(e != null) {
|
||||||
|
if(e.getName().startsWith("META-INF")) {
|
||||||
|
e = input2.getNextEntry();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ZipEntry newEntry = IOHelper.newZipEntry(e);
|
||||||
|
output.putNextEntry(newEntry);
|
||||||
|
IOHelper.transfer(input2, output);
|
||||||
|
blacklist.add(e.getName());
|
||||||
|
e = input2.getNextEntry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ZipEntry e = input.getNextEntry();
|
||||||
|
while(e != null) {
|
||||||
|
if(blacklist.contains(e.getName())) {
|
||||||
|
e = input.getNextEntry();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ZipEntry newEntry = IOHelper.newZipEntry(e);
|
||||||
|
output.putNextEntry(newEntry);
|
||||||
|
IOHelper.transfer(input, output);
|
||||||
|
e = input.getNextEntry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.toByteArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class RepackInfo {
|
||||||
|
public Path path;
|
||||||
|
public String prefix;
|
||||||
|
public boolean isJarFile;
|
||||||
|
|
||||||
|
public RepackInfo(Path path, String prefix, boolean isJarFile) {
|
||||||
|
this.path = path;
|
||||||
|
this.prefix = prefix;
|
||||||
|
this.isJarFile = isJarFile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class HashFile {
|
||||||
|
public Path path;
|
||||||
|
public String prefix;
|
||||||
|
public LibrariesHashFileModifier modifier;
|
||||||
|
|
||||||
|
public HashFile(Path path, String prefix, LibrariesHashFileModifier modifier) {
|
||||||
|
this.path = path;
|
||||||
|
this.prefix = prefix;
|
||||||
|
this.modifier = modifier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class InstallAuthlibContext {
|
||||||
|
public Path pathToAuthlib;
|
||||||
|
public Path workdir = IOHelper.WORKING_DIR;
|
||||||
|
public List<Path> files = new ArrayList<>();
|
||||||
|
public List<RepackInfo> repack = new ArrayList<>();
|
||||||
|
public List<HashFile> hashes = new ArrayList<>();
|
||||||
|
public byte[] repackedAuthlibBytes = null;
|
||||||
|
public Set<String> repackedAuthlibFiles = null;
|
||||||
|
|
||||||
|
public LocalDateTime timestamp = LocalDateTime.now();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package pro.gravit.launcher.server.authlib;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface LibrariesHashFileModifier {
|
||||||
|
byte[] apply(byte[] data, InstallAuthlib.InstallAuthlibContext context) throws IOException;
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package pro.gravit.launcher.server.authlib;
|
||||||
|
|
||||||
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
public class LibrariesLstModifier implements LibrariesHashFileModifier {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] apply(byte[] data, InstallAuthlib.InstallAuthlibContext context) throws IOException {
|
||||||
|
String[] lines = new String(data).split("\n");
|
||||||
|
for(int i=0;i<lines.length;++i) {
|
||||||
|
if(lines[i].contains("com.mojang:authlib")) {
|
||||||
|
String[] separated = lines[i].split("\t");
|
||||||
|
separated[0] = SecurityHelper.toHex(SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, context.repackedAuthlibBytes));
|
||||||
|
lines[i] = String.join("\t", separated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return String.join("\n", lines).getBytes(StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
package pro.gravit.launcher.server.authlib;
|
||||||
|
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public class PatchPropertiesModifier implements LibrariesHashFileModifier {
|
||||||
|
@Override
|
||||||
|
public byte[] apply(byte[] data, InstallAuthlib.InstallAuthlibContext context) throws IOException {
|
||||||
|
String[] lines = new String(data).split("\n");
|
||||||
|
String version = null;
|
||||||
|
int linePatchedHashIndex = -1;
|
||||||
|
int lineOriginalHashIndex = -1;
|
||||||
|
for(int i=0;i<lines.length;++i) {
|
||||||
|
if(lines[i].startsWith("version=")) {
|
||||||
|
version = lines[i].split("=")[1];
|
||||||
|
} else if(lines[i].startsWith("patchedHash=")) {
|
||||||
|
linePatchedHashIndex = i;
|
||||||
|
} else if(lines[i].startsWith("originalHash=")) {
|
||||||
|
lineOriginalHashIndex = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(version == null) {
|
||||||
|
LogHelper.warning("Unable to parse version from patch.properties");
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
if(linePatchedHashIndex < 0) {
|
||||||
|
LogHelper.warning("Unable to parse patchedHash from patch.properties");
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
if(lineOriginalHashIndex < 0) {
|
||||||
|
LogHelper.warning("Unable to parse originalHash from patch.properties");
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
Path patchedFile = context.workdir.resolve("cache").resolve("patched_".concat(version).concat(".jar"));
|
||||||
|
Path originalFile = context.workdir.resolve("cache").resolve("mojang_".concat(version).concat(".jar"));
|
||||||
|
if(Files.notExists(patchedFile)) {
|
||||||
|
LogHelper.warning("Unable to find %s. Maybe you should start the server at least once?", patchedFile);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
if(Files.notExists(originalFile)) {
|
||||||
|
LogHelper.warning("Unable to find %s. Maybe you should start the server at least once?", originalFile);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
String newPatchedHash = SecurityHelper.toHex(SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, patchedFile)).toUpperCase();
|
||||||
|
String newOriginalHash = SecurityHelper.toHex(SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, originalFile)).toUpperCase();
|
||||||
|
lines[linePatchedHashIndex] = "patchedHash=".concat(newPatchedHash);
|
||||||
|
lines[lineOriginalHashIndex] = "originalHash=".concat(newOriginalHash);
|
||||||
|
return String.join("\n", lines).getBytes(StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,7 +5,7 @@
|
||||||
id 'org.openjfx.javafxplugin' version '0.0.10' apply false
|
id 'org.openjfx.javafxplugin' version '0.0.10' apply false
|
||||||
}
|
}
|
||||||
group = 'pro.gravit.launcher'
|
group = 'pro.gravit.launcher'
|
||||||
version = '5.2.12'
|
version = '5.2.13'
|
||||||
|
|
||||||
apply from: 'props.gradle'
|
apply from: 'props.gradle'
|
||||||
|
|
||||||
|
|
2
modules
2
modules
|
@ -1 +1 @@
|
||||||
Subproject commit 48dad65be0f613fa1a6ae544ec892592d537bcc1
|
Subproject commit d3722bf136b8c8c8da3dea879d5d2015e84b0f8c
|
14
props.gradle
14
props.gradle
|
@ -1,20 +1,20 @@
|
||||||
project.ext {
|
project.ext {
|
||||||
verAsm = '9.2'
|
verAsm = '9.3'
|
||||||
verNetty = '4.1.75.Final'
|
verNetty = '4.1.78.Final'
|
||||||
verOshiCore = '6.1.5'
|
verOshiCore = '6.2.1'
|
||||||
verJunit = '5.8.2'
|
verJunit = '5.8.2'
|
||||||
verGuavaC = '30.1.1-jre'
|
verGuavaC = '30.1.1-jre'
|
||||||
verJansi = '2.4.0'
|
verJansi = '2.4.0'
|
||||||
verJline = '3.21.0'
|
verJline = '3.21.0'
|
||||||
verJwt = '0.11.2'
|
verJwt = '0.11.5'
|
||||||
verBcprov = '1.70'
|
verBcprov = '1.70'
|
||||||
verGson = '2.9.0'
|
verGson = '2.9.0'
|
||||||
verBcpkix = '1.70'
|
verBcpkix = '1.70'
|
||||||
verSlf4j = '1.7.36'
|
verSlf4j = '1.7.36'
|
||||||
verLog4j = '2.17.2'
|
verLog4j = '2.17.2'
|
||||||
verMySQLConn = '8.0.28'
|
verMySQLConn = '8.0.29'
|
||||||
verPostgreSQLConn = '42.3.3'
|
verPostgreSQLConn = '42.4.0'
|
||||||
verProguard = '7.2.1'
|
verProguard = '7.2.2'
|
||||||
verLaunch4j = '3.14'
|
verLaunch4j = '3.14'
|
||||||
verHibernate = '5.5.6.Final'
|
verHibernate = '5.5.6.Final'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue