mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[ANY] IDEA Reformat Code
This commit is contained in:
parent
9a4b813bb7
commit
176430e442
276 changed files with 2320 additions and 2699 deletions
|
@ -1,46 +1,46 @@
|
||||||
image: docker:latest
|
image: docker:latest
|
||||||
services:
|
services:
|
||||||
- docker:dind
|
- docker:dind
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
DOCKER_DRIVER: overlay2
|
DOCKER_DRIVER: overlay2
|
||||||
CI_VERSION: '6.6.$CI_PIPELINE_IID'
|
CI_VERSION: '6.6.$CI_PIPELINE_IID'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- build
|
- build
|
||||||
- test
|
- test
|
||||||
|
|
||||||
build:
|
build:
|
||||||
image: frekele/java
|
image: frekele/java
|
||||||
stage: build
|
stage: build
|
||||||
before_script:
|
before_script:
|
||||||
- apt-get -y update
|
- apt-get -y update
|
||||||
- apt-get -y install zip git
|
- apt-get -y install zip git
|
||||||
- export GRADLE_USER_HOME=`pwd`/.gradle
|
- export GRADLE_USER_HOME=`pwd`/.gradle
|
||||||
- chmod +x gradlew
|
- chmod +x gradlew
|
||||||
- sed -i 's/git@github.com:/https:\/\/github.com\//' .gitmodules
|
- sed -i 's/git@github.com:/https:\/\/github.com\//' .gitmodules
|
||||||
- git submodule sync
|
- git submodule sync
|
||||||
- git submodule update --init --recursive
|
- git submodule update --init --recursive
|
||||||
script:
|
script:
|
||||||
- ./gradlew assemble
|
- ./gradlew assemble
|
||||||
after_script:
|
after_script:
|
||||||
- mkdir -p artifacts/modules
|
- mkdir -p artifacts/modules
|
||||||
- cd LaunchServer/build/libs/
|
- cd LaunchServer/build/libs/
|
||||||
- zip -r -9 ../../../artifacts/libraries.zip * -x "LaunchServer.jar" -x "LaunchServer-clean.jar"
|
- zip -r -9 ../../../artifacts/libraries.zip * -x "LaunchServer.jar" -x "LaunchServer-clean.jar"
|
||||||
- mv LaunchServer.jar ../../../artifacts/LaunchServer.jar
|
- mv LaunchServer.jar ../../../artifacts/LaunchServer.jar
|
||||||
- cd ../../../ServerWrapper/build/libs
|
- cd ../../../ServerWrapper/build/libs
|
||||||
- mv ServerWrapper.jar ../../../artifacts/ServerWrapper.jar
|
- mv ServerWrapper.jar ../../../artifacts/ServerWrapper.jar
|
||||||
- cd ../../../
|
- cd ../../../
|
||||||
- mv modules/*_module/build/libs/*.jar artifacts/modules
|
- mv modules/*_module/build/libs/*.jar artifacts/modules
|
||||||
- mv modules/*_swmodule/build/libs/*.jar artifacts/modules
|
- mv modules/*_swmodule/build/libs/*.jar artifacts/modules
|
||||||
- mv modules/*_lmodule/build/libs/*.jar artifacts/modules
|
- mv modules/*_lmodule/build/libs/*.jar artifacts/modules
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .gradle
|
- .gradle
|
||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 6 week
|
expire_in: 6 week
|
||||||
paths:
|
paths:
|
||||||
- artifacts
|
- artifacts
|
||||||
|
|
||||||
test:
|
test:
|
||||||
image: frekele/java
|
image: frekele/java
|
||||||
|
|
|
@ -73,7 +73,7 @@ task cleanjar(type: Jar, dependsOn: jar) {
|
||||||
pack project(':LauncherAPI')
|
pack project(':LauncherAPI')
|
||||||
bundle 'org.ow2.asm:asm-commons:7.1'
|
bundle 'org.ow2.asm:asm-commons:7.1'
|
||||||
bundle 'mysql:mysql-connector-java:8.0.16'
|
bundle 'mysql:mysql-connector-java:8.0.16'
|
||||||
bundle 'org.postgresql:postgresql:42.2.6'
|
bundle 'org.postgresql:postgresql:42.2.6'
|
||||||
bundle 'org.jline:jline:3.11.0'
|
bundle 'org.jline:jline:3.11.0'
|
||||||
bundle 'org.jline:jline-reader:3.11.0'
|
bundle 'org.jline:jline-reader:3.11.0'
|
||||||
bundle 'org.jline:jline-terminal:3.11.0'
|
bundle 'org.jline:jline-terminal:3.11.0'
|
||||||
|
|
|
@ -1,37 +1,7 @@
|
||||||
package pro.gravit.launchserver;
|
package pro.gravit.launchserver;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.ProcessBuilder.Redirect;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.nio.file.DirectoryStream;
|
|
||||||
import java.nio.file.FileVisitResult;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.SimpleFileVisitor;
|
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
|
||||||
import java.security.KeyPair;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.security.interfaces.ECPrivateKey;
|
|
||||||
import java.security.interfaces.ECPublicKey;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.Timer;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import org.bouncycastle.crypto.util.PrivateKeyFactory;
|
import org.bouncycastle.crypto.util.PrivateKeyFactory;
|
||||||
import org.bouncycastle.operator.OperatorCreationException;
|
import org.bouncycastle.operator.OperatorCreationException;
|
||||||
|
|
||||||
import pro.gravit.launcher.Launcher;
|
import pro.gravit.launcher.Launcher;
|
||||||
import pro.gravit.launcher.NeedGarbageCollection;
|
import pro.gravit.launcher.NeedGarbageCollection;
|
||||||
import pro.gravit.launcher.hasher.HashedDir;
|
import pro.gravit.launcher.hasher.HashedDir;
|
||||||
|
@ -40,12 +10,7 @@
|
||||||
import pro.gravit.launcher.modules.events.ClosePhase;
|
import pro.gravit.launcher.modules.events.ClosePhase;
|
||||||
import pro.gravit.launcher.profiles.ClientProfile;
|
import pro.gravit.launcher.profiles.ClientProfile;
|
||||||
import pro.gravit.launchserver.auth.AuthProviderPair;
|
import pro.gravit.launchserver.auth.AuthProviderPair;
|
||||||
import pro.gravit.launchserver.binary.EXEL4JLauncherBinary;
|
import pro.gravit.launchserver.binary.*;
|
||||||
import pro.gravit.launchserver.binary.EXELauncherBinary;
|
|
||||||
import pro.gravit.launchserver.binary.JARLauncherBinary;
|
|
||||||
import pro.gravit.launchserver.binary.LauncherBinary;
|
|
||||||
import pro.gravit.launchserver.binary.ProguardConf;
|
|
||||||
import pro.gravit.launchserver.binary.SimpleEXELauncherBinary;
|
|
||||||
import pro.gravit.launchserver.config.LaunchServerConfig;
|
import pro.gravit.launchserver.config.LaunchServerConfig;
|
||||||
import pro.gravit.launchserver.config.LaunchServerRuntimeConfig;
|
import pro.gravit.launchserver.config.LaunchServerRuntimeConfig;
|
||||||
import pro.gravit.launchserver.manangers.CertificateManager;
|
import pro.gravit.launchserver.manangers.CertificateManager;
|
||||||
|
@ -68,41 +33,57 @@
|
||||||
import pro.gravit.utils.helper.JVMHelper;
|
import pro.gravit.utils.helper.JVMHelper;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.ProcessBuilder.Redirect;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.nio.file.*;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.security.InvalidAlgorithmParameterException;
|
||||||
|
import java.security.KeyPair;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.interfaces.ECPrivateKey;
|
||||||
|
import java.security.interfaces.ECPublicKey;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurable {
|
public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurable {
|
||||||
|
|
||||||
public enum ReloadType
|
public enum ReloadType {
|
||||||
{
|
|
||||||
NO_AUTH,
|
NO_AUTH,
|
||||||
NO_COMPONENTS,
|
NO_COMPONENTS,
|
||||||
FULL
|
FULL
|
||||||
}
|
}
|
||||||
public enum LaunchServerEnv
|
|
||||||
{
|
public enum LaunchServerEnv {
|
||||||
TEST,
|
TEST,
|
||||||
DEV,
|
DEV,
|
||||||
DEBUG,
|
DEBUG,
|
||||||
PRODUCTION
|
PRODUCTION
|
||||||
}
|
}
|
||||||
public interface LaunchServerConfigManager
|
|
||||||
{
|
public interface LaunchServerConfigManager {
|
||||||
LaunchServerConfig readConfig() throws IOException;
|
LaunchServerConfig readConfig() throws IOException;
|
||||||
|
|
||||||
LaunchServerRuntimeConfig readRuntimeConfig() throws IOException;
|
LaunchServerRuntimeConfig readRuntimeConfig() throws IOException;
|
||||||
|
|
||||||
void writeConfig(LaunchServerConfig config) throws IOException;
|
void writeConfig(LaunchServerConfig config) throws IOException;
|
||||||
|
|
||||||
void writeRuntimeConfig(LaunchServerRuntimeConfig config) throws IOException;
|
void writeRuntimeConfig(LaunchServerRuntimeConfig config) throws IOException;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reload(ReloadType type) throws Exception {
|
public void reload(ReloadType type) throws Exception {
|
||||||
config.close(type);
|
config.close(type);
|
||||||
AuthProviderPair[] pairs = null;
|
AuthProviderPair[] pairs = null;
|
||||||
if(type.equals(ReloadType.NO_AUTH))
|
if (type.equals(ReloadType.NO_AUTH)) {
|
||||||
{
|
|
||||||
pairs = config.auth;
|
pairs = config.auth;
|
||||||
}
|
}
|
||||||
LogHelper.info("Reading LaunchServer config file");
|
LogHelper.info("Reading LaunchServer config file");
|
||||||
config = launchServerConfigManager.readConfig();
|
config = launchServerConfigManager.readConfig();
|
||||||
config.setLaunchServer(this);
|
config.setLaunchServer(this);
|
||||||
if(type.equals(ReloadType.NO_AUTH))
|
if (type.equals(ReloadType.NO_AUTH)) {
|
||||||
{
|
|
||||||
config.auth = pairs;
|
config.auth = pairs;
|
||||||
}
|
}
|
||||||
config.verify();
|
config.verify();
|
||||||
|
@ -137,13 +118,11 @@ public Map<String, Command> getCommands() {
|
||||||
SubCommand reload = new SubCommand() {
|
SubCommand reload = new SubCommand() {
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) throws Exception {
|
public void invoke(String... args) throws Exception {
|
||||||
if(args.length == 0)
|
if (args.length == 0) {
|
||||||
{
|
|
||||||
reload(ReloadType.FULL);
|
reload(ReloadType.FULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (args[0])
|
switch (args[0]) {
|
||||||
{
|
|
||||||
case "full":
|
case "full":
|
||||||
reload(ReloadType.FULL);
|
reload(ReloadType.FULL);
|
||||||
break;
|
break;
|
||||||
|
@ -266,17 +245,16 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
||||||
|
|
||||||
public static final Class<? extends LauncherBinary> defaultLauncherEXEBinaryClass = null;
|
public static final Class<? extends LauncherBinary> defaultLauncherEXEBinaryClass = null;
|
||||||
|
|
||||||
public static class LaunchServerDirectories
|
public static class LaunchServerDirectories {
|
||||||
{
|
|
||||||
public Path updatesDir;
|
public Path updatesDir;
|
||||||
public Path profilesDir;
|
public Path profilesDir;
|
||||||
public Path dir;
|
public Path dir;
|
||||||
public Path trustStore;
|
public Path trustStore;
|
||||||
public void collect()
|
|
||||||
{
|
public void collect() {
|
||||||
if(updatesDir == null) updatesDir = dir.resolve("updates");
|
if (updatesDir == null) updatesDir = dir.resolve("updates");
|
||||||
if(profilesDir == null) profilesDir = dir.resolve("profiles");
|
if (profilesDir == null) profilesDir = dir.resolve("profiles");
|
||||||
if(trustStore == null) trustStore = dir.resolve("truststore");
|
if (trustStore == null) trustStore = dir.resolve("truststore");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,15 +311,11 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La
|
||||||
configManager = new ConfigManager();
|
configManager = new ConfigManager();
|
||||||
//Generate or set new Certificate API
|
//Generate or set new Certificate API
|
||||||
certificateManager.orgName = config.projectName;
|
certificateManager.orgName = config.projectName;
|
||||||
if(config.certificate != null && config.certificate.enabled)
|
if (config.certificate != null && config.certificate.enabled) {
|
||||||
{
|
if (IOHelper.isFile(caCertFile) && IOHelper.isFile(caKeyFile)) {
|
||||||
if(IOHelper.isFile(caCertFile) && IOHelper.isFile(caKeyFile))
|
|
||||||
{
|
|
||||||
certificateManager.ca = certificateManager.readCertificate(caCertFile);
|
certificateManager.ca = certificateManager.readCertificate(caCertFile);
|
||||||
certificateManager.caKey = certificateManager.readPrivateKey(caKeyFile);
|
certificateManager.caKey = certificateManager.readPrivateKey(caKeyFile);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
certificateManager.generateCA();
|
certificateManager.generateCA();
|
||||||
certificateManager.writeCertificate(caCertFile, certificateManager.ca);
|
certificateManager.writeCertificate(caCertFile, certificateManager.ca);
|
||||||
|
@ -350,13 +324,10 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La
|
||||||
LogHelper.error(e);
|
LogHelper.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(IOHelper.isFile(serverCertFile) && IOHelper.isFile(serverKeyFile))
|
if (IOHelper.isFile(serverCertFile) && IOHelper.isFile(serverKeyFile)) {
|
||||||
{
|
|
||||||
certificateManager.server = certificateManager.readCertificate(serverCertFile);
|
certificateManager.server = certificateManager.readCertificate(serverCertFile);
|
||||||
certificateManager.serverKey = certificateManager.readPrivateKey(serverKeyFile);
|
certificateManager.serverKey = certificateManager.readPrivateKey(serverKeyFile);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
KeyPair pair = certificateManager.generateKeyPair();
|
KeyPair pair = certificateManager.generateKeyPair();
|
||||||
certificateManager.server = certificateManager.generateCertificate(config.projectName.concat(" Server"), pair.getPublic());
|
certificateManager.server = certificateManager.generateCertificate(config.projectName.concat(" Server"), pair.getPublic());
|
||||||
|
@ -425,8 +396,7 @@ private LauncherBinary binary() {
|
||||||
LogHelper.error(e);
|
LogHelper.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(config.launch4j.alternative != null)
|
if (config.launch4j.alternative != null) {
|
||||||
{
|
|
||||||
switch (config.launch4j.alternative) {
|
switch (config.launch4j.alternative) {
|
||||||
case "simple":
|
case "simple":
|
||||||
return new SimpleEXELauncherBinary(this);
|
return new SimpleEXELauncherBinary(this);
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package pro.gravit.launchserver;
|
package pro.gravit.launchserver;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.security.interfaces.ECPrivateKey;
|
|
||||||
import java.security.interfaces.ECPublicKey;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.config.LaunchServerConfig;
|
import pro.gravit.launchserver.config.LaunchServerConfig;
|
||||||
import pro.gravit.launchserver.config.LaunchServerRuntimeConfig;
|
import pro.gravit.launchserver.config.LaunchServerRuntimeConfig;
|
||||||
import pro.gravit.launchserver.manangers.CertificateManager;
|
import pro.gravit.launchserver.manangers.CertificateManager;
|
||||||
import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager;
|
import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager;
|
||||||
import pro.gravit.utils.command.CommandHandler;
|
import pro.gravit.utils.command.CommandHandler;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.security.interfaces.ECPrivateKey;
|
||||||
|
import java.security.interfaces.ECPublicKey;
|
||||||
|
|
||||||
public class LaunchServerBuilder {
|
public class LaunchServerBuilder {
|
||||||
private LaunchServerConfig config;
|
private LaunchServerConfig config;
|
||||||
private LaunchServerRuntimeConfig runtimeConfig;
|
private LaunchServerRuntimeConfig runtimeConfig;
|
||||||
|
@ -72,13 +72,11 @@ public LaunchServerBuilder setLaunchServerConfigManager(LaunchServer.LaunchServe
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LaunchServer build() throws Exception
|
public LaunchServer build() throws Exception {
|
||||||
{
|
|
||||||
//if(updatesDir == null) updatesDir = dir.resolve("updates");
|
//if(updatesDir == null) updatesDir = dir.resolve("updates");
|
||||||
//if(profilesDir == null) profilesDir = dir.resolve("profiles");
|
//if(profilesDir == null) profilesDir = dir.resolve("profiles");
|
||||||
directories.collect();
|
directories.collect();
|
||||||
if(launchServerConfigManager == null)
|
if (launchServerConfigManager == null) {
|
||||||
{
|
|
||||||
launchServerConfigManager = new LaunchServer.LaunchServerConfigManager() {
|
launchServerConfigManager = new LaunchServer.LaunchServerConfigManager() {
|
||||||
@Override
|
@Override
|
||||||
public LaunchServerConfig readConfig() {
|
public LaunchServerConfig readConfig() {
|
||||||
|
|
|
@ -1,18 +1,5 @@
|
||||||
package pro.gravit.launchserver;
|
package pro.gravit.launchserver;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Writer;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.security.KeyPair;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.security.Security;
|
|
||||||
import java.security.cert.CertificateException;
|
|
||||||
import java.security.interfaces.ECPrivateKey;
|
|
||||||
import java.security.interfaces.ECPublicKey;
|
|
||||||
|
|
||||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||||
import pro.gravit.launcher.Launcher;
|
import pro.gravit.launcher.Launcher;
|
||||||
import pro.gravit.launcher.hwid.HWIDProvider;
|
import pro.gravit.launcher.hwid.HWIDProvider;
|
||||||
|
@ -42,8 +29,22 @@
|
||||||
import pro.gravit.utils.helper.SecurityHelper;
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
import pro.gravit.utils.verify.LauncherTrustManager;
|
import pro.gravit.utils.verify.LauncherTrustManager;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.security.KeyPair;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.security.Security;
|
||||||
|
import java.security.cert.CertificateException;
|
||||||
|
import java.security.interfaces.ECPrivateKey;
|
||||||
|
import java.security.interfaces.ECPublicKey;
|
||||||
|
|
||||||
public class LaunchServerStarter {
|
public class LaunchServerStarter {
|
||||||
public static final boolean allowUnsigned = Boolean.getBoolean("launchserver.allowUnsigned");
|
public static final boolean allowUnsigned = Boolean.getBoolean("launchserver.allowUnsigned");
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
JVMHelper.checkStackTrace(LaunchServerStarter.class);
|
JVMHelper.checkStackTrace(LaunchServerStarter.class);
|
||||||
JVMHelper.verifySystemProperties(LaunchServer.class, true);
|
JVMHelper.verifySystemProperties(LaunchServer.class, true);
|
||||||
|
@ -56,7 +57,7 @@ public static void main(String[] args) throws Exception {
|
||||||
}
|
}
|
||||||
Path dir = IOHelper.WORKING_DIR;
|
Path dir = IOHelper.WORKING_DIR;
|
||||||
Path configFile, runtimeConfigFile;
|
Path configFile, runtimeConfigFile;
|
||||||
Path publicKeyFile =dir.resolve("public.key");
|
Path publicKeyFile = dir.resolve("public.key");
|
||||||
Path privateKeyFile = dir.resolve("private.key");
|
Path privateKeyFile = dir.resolve("private.key");
|
||||||
ECPublicKey publicKey;
|
ECPublicKey publicKey;
|
||||||
ECPrivateKey privateKey;
|
ECPrivateKey privateKey;
|
||||||
|
@ -197,8 +198,7 @@ public static void initGson(LaunchServerModulesManager modulesManager) {
|
||||||
Launcher.gsonManager.initGson();
|
Launcher.gsonManager.initGson();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerAll()
|
public static void registerAll() {
|
||||||
{
|
|
||||||
|
|
||||||
AuthHandler.registerHandlers();
|
AuthHandler.registerHandlers();
|
||||||
AuthProvider.registerProviders();
|
AuthProvider.registerProviders();
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
package pro.gravit.launchserver;
|
package pro.gravit.launchserver;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import pro.gravit.utils.command.Command;
|
import pro.gravit.utils.command.Command;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows calling commands using the config command
|
* Allows calling commands using the config command
|
||||||
*/
|
*/
|
||||||
public interface Reconfigurable {
|
public interface Reconfigurable {
|
||||||
/**
|
/**
|
||||||
* Gets a list of commands available for this object.
|
* Gets a list of commands available for this object.
|
||||||
|
*
|
||||||
* @return Key - Command Name
|
* @return Key - Command Name
|
||||||
* Value is a command object
|
* Value is a command object
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,12 +2,7 @@
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.instrument.Instrumentation;
|
import java.lang.instrument.Instrumentation;
|
||||||
import java.nio.file.FileVisitOption;
|
import java.nio.file.*;
|
||||||
import java.nio.file.FileVisitResult;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.nio.file.SimpleFileVisitor;
|
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.nio.file.attribute.PosixFileAttributeView;
|
import java.nio.file.attribute.PosixFileAttributeView;
|
||||||
import java.nio.file.attribute.PosixFilePermission;
|
import java.nio.file.attribute.PosixFilePermission;
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
package pro.gravit.launchserver.asm;
|
package pro.gravit.launchserver.asm;
|
||||||
|
|
||||||
|
import org.objectweb.asm.ClassReader;
|
||||||
|
import org.objectweb.asm.ClassVisitor;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -8,12 +13,6 @@
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
import org.objectweb.asm.ClassReader;
|
|
||||||
import org.objectweb.asm.ClassVisitor;
|
|
||||||
import org.objectweb.asm.Opcodes;
|
|
||||||
|
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Позволяет искать методы внутри незагруженных классов и общие суперклассы для
|
* Позволяет искать методы внутри незагруженных классов и общие суперклассы для
|
||||||
* чего угодно. Работает через поиск class-файлов в classpath.
|
* чего угодно. Работает через поиск class-файлов в classpath.
|
||||||
|
|
|
@ -1,25 +1,17 @@
|
||||||
package pro.gravit.launchserver.asm;
|
package pro.gravit.launchserver.asm;
|
||||||
|
|
||||||
import java.util.Base64;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.objectweb.asm.ClassWriter;
|
import org.objectweb.asm.ClassWriter;
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.Type;
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
import org.objectweb.asm.tree.*;
|
||||||
import org.objectweb.asm.tree.FieldInsnNode;
|
|
||||||
import org.objectweb.asm.tree.InsnList;
|
import java.util.Base64;
|
||||||
import org.objectweb.asm.tree.InsnNode;
|
import java.util.List;
|
||||||
import org.objectweb.asm.tree.LdcInsnNode;
|
|
||||||
import org.objectweb.asm.tree.MethodInsnNode;
|
|
||||||
import org.objectweb.asm.tree.MethodNode;
|
|
||||||
import org.objectweb.asm.tree.TypeInsnNode;
|
|
||||||
import org.objectweb.asm.tree.VarInsnNode;
|
|
||||||
|
|
||||||
public class ConfigGenerator {
|
public class ConfigGenerator {
|
||||||
protected static final String stringDesc = Type.getDescriptor(String.class);
|
protected static final String stringDesc = Type.getDescriptor(String.class);
|
||||||
protected static final String byteArrDesc = Type.getDescriptor(byte[].class);
|
protected static final String byteArrDesc = Type.getDescriptor(byte[].class);
|
||||||
protected static final String base64DecDesc = "(" + stringDesc + ")" + byteArrDesc;
|
protected static final String base64DecDesc = "(" + stringDesc + ")" + byteArrDesc;
|
||||||
protected final ClassNode configclass;
|
protected final ClassNode configclass;
|
||||||
protected final MethodNode constructor;
|
protected final MethodNode constructor;
|
||||||
|
|
||||||
|
@ -42,15 +34,13 @@ public String getZipEntryPath() {
|
||||||
return configclass.name.concat(".class");
|
return configclass.name.concat(".class");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStringField(String name, String value)
|
public void setStringField(String name, String value) {
|
||||||
{
|
|
||||||
constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
constructor.instructions.add(NodeUtils.getSafeStringInsnList(value));
|
constructor.instructions.add(NodeUtils.getSafeStringInsnList(value));
|
||||||
constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, stringDesc));
|
constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, stringDesc));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setByteArrayField(String name, byte[] value)
|
public void setByteArrayField(String name, byte[] value) {
|
||||||
{
|
|
||||||
constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64", "getDecoder", "()Ljava/util/Base64$Decoder;", false));
|
constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64", "getDecoder", "()Ljava/util/Base64$Decoder;", false));
|
||||||
constructor.instructions.add(NodeUtils.getSafeStringInsnList(Base64.getEncoder().encodeToString(value)));
|
constructor.instructions.add(NodeUtils.getSafeStringInsnList(Base64.getEncoder().encodeToString(value)));
|
||||||
|
@ -58,39 +48,35 @@ public void setByteArrayField(String name, byte[] value)
|
||||||
constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, stringDesc));
|
constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, stringDesc));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setByteArrayListField(String name, List<byte[]> b)
|
public void setByteArrayListField(String name, List<byte[]> b) {
|
||||||
{
|
|
||||||
constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
constructor.instructions.add(new TypeInsnNode(Opcodes.NEW, "java/util/ArrayList"));
|
constructor.instructions.add(new TypeInsnNode(Opcodes.NEW, "java/util/ArrayList"));
|
||||||
constructor.instructions.add(new InsnNode(Opcodes.DUP));
|
constructor.instructions.add(new InsnNode(Opcodes.DUP));
|
||||||
constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V"));
|
constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/util/ArrayList", "<init>", "()V"));
|
||||||
for (byte[] value : b) {
|
for (byte[] value : b) {
|
||||||
constructor.instructions.add(new InsnNode(Opcodes.DUP));
|
constructor.instructions.add(new InsnNode(Opcodes.DUP));
|
||||||
constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64", "getDecoder", "()Ljava/util/Base64$Decoder;", false));
|
constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64", "getDecoder", "()Ljava/util/Base64$Decoder;", false));
|
||||||
constructor.instructions.add(NodeUtils.getSafeStringInsnList(Base64.getEncoder().encodeToString(value)));
|
constructor.instructions.add(NodeUtils.getSafeStringInsnList(Base64.getEncoder().encodeToString(value)));
|
||||||
constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64$Decoder", "decode", base64DecDesc, false));
|
constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/util/Base64$Decoder", "decode", base64DecDesc, false));
|
||||||
constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", false));
|
constructor.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/util/List", "add", "(Ljava/lang/Object;)Z", false));
|
||||||
constructor.instructions.add(new InsnNode(Opcodes.POP));
|
constructor.instructions.add(new InsnNode(Opcodes.POP));
|
||||||
}
|
}
|
||||||
constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, "Ljava/util/List;"));
|
constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, "Ljava/util/List;"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIntegerField(String name, int value)
|
public void setIntegerField(String name, int value) {
|
||||||
{
|
|
||||||
constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
constructor.instructions.add(NodeUtils.push(value));
|
constructor.instructions.add(NodeUtils.push(value));
|
||||||
constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, Type.INT_TYPE.getInternalName()));
|
constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, Type.INT_TYPE.getInternalName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLongField(String name, long value)
|
public void setLongField(String name, long value) {
|
||||||
{
|
|
||||||
constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
constructor.instructions.add(new LdcInsnNode(value));
|
constructor.instructions.add(new LdcInsnNode(value));
|
||||||
constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, Type.INT_TYPE.getInternalName()));
|
constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, Type.INT_TYPE.getInternalName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBooleanField(String name, boolean b)
|
public void setBooleanField(String name, boolean b) {
|
||||||
{
|
|
||||||
constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
constructor.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
|
||||||
constructor.instructions.add(new InsnNode(b ? Opcodes.ICONST_1 : Opcodes.ICONST_0));
|
constructor.instructions.add(new InsnNode(b ? Opcodes.ICONST_1 : Opcodes.ICONST_0));
|
||||||
constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, Type.BOOLEAN_TYPE.getInternalName()));
|
constructor.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, configclass.name, name, Type.BOOLEAN_TYPE.getInternalName()));
|
||||||
|
|
|
@ -1,57 +1,60 @@
|
||||||
package pro.gravit.launchserver.asm;
|
package pro.gravit.launchserver.asm;
|
||||||
|
|
||||||
|
import org.objectweb.asm.ClassReader;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
import org.objectweb.asm.Type;
|
||||||
|
import org.objectweb.asm.tree.*;
|
||||||
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.objectweb.asm.*;
|
|
||||||
import org.objectweb.asm.tree.*;
|
|
||||||
|
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
|
||||||
|
|
||||||
import static org.objectweb.asm.Opcodes.*;
|
import static org.objectweb.asm.Opcodes.*;
|
||||||
|
|
||||||
public final class NodeUtils {
|
public final class NodeUtils {
|
||||||
private NodeUtils() { }
|
private NodeUtils() {
|
||||||
public static ClassNode forClass(Class<?> cls, int flags) {
|
}
|
||||||
try (InputStream in = cls.getClassLoader().getResourceAsStream(cls.getName().replace('.', '/') + ".class")) {
|
|
||||||
ClassNode ret = new ClassNode();
|
|
||||||
new ClassReader(IOHelper.read(in)).accept(ret, flags);
|
|
||||||
return ret;
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ClassNode forClass(String clazz, int flags, ClassMetadataReader r) {
|
public static ClassNode forClass(Class<?> cls, int flags) {
|
||||||
try {
|
try (InputStream in = cls.getClassLoader().getResourceAsStream(cls.getName().replace('.', '/') + ".class")) {
|
||||||
ClassNode ret = new ClassNode();
|
ClassNode ret = new ClassNode();
|
||||||
r.acceptVisitor(clazz, ret, flags);
|
new ClassReader(IOHelper.read(in)).accept(ret, flags);
|
||||||
return ret;
|
return ret;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<AnnotationNode> annots(String clazz, String method, ClassMetadataReader r) {
|
public static ClassNode forClass(String clazz, int flags, ClassMetadataReader r) {
|
||||||
if (clazz.startsWith("L")) clazz = Type.getType(clazz).getInternalName();
|
try {
|
||||||
try {
|
ClassNode ret = new ClassNode();
|
||||||
List<AnnotationNode> ret = new ArrayList<>();
|
r.acceptVisitor(clazz, ret, flags);
|
||||||
ClassNode n = forClass(clazz, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG, r);
|
return ret;
|
||||||
if (n.visibleAnnotations != null) ret.addAll(n.visibleAnnotations);
|
} catch (IOException e) {
|
||||||
if (n.invisibleAnnotations != null) ret.addAll(n.invisibleAnnotations);
|
throw new RuntimeException(e);
|
||||||
for (MethodNode m : n.methods)
|
}
|
||||||
if (method.equals(m.name)) {
|
}
|
||||||
if (m.visibleAnnotations != null) ret.addAll(m.visibleAnnotations);
|
|
||||||
if (m.invisibleAnnotations != null) ret.addAll(m.invisibleAnnotations);
|
public static List<AnnotationNode> annots(String clazz, String method, ClassMetadataReader r) {
|
||||||
}
|
if (clazz.startsWith("L")) clazz = Type.getType(clazz).getInternalName();
|
||||||
return ret;
|
try {
|
||||||
} catch (Throwable e) {
|
List<AnnotationNode> ret = new ArrayList<>();
|
||||||
return Collections.emptyList();
|
ClassNode n = forClass(clazz, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG, r);
|
||||||
}
|
if (n.visibleAnnotations != null) ret.addAll(n.visibleAnnotations);
|
||||||
}
|
if (n.invisibleAnnotations != null) ret.addAll(n.invisibleAnnotations);
|
||||||
|
for (MethodNode m : n.methods)
|
||||||
|
if (method.equals(m.name)) {
|
||||||
|
if (m.visibleAnnotations != null) ret.addAll(m.visibleAnnotations);
|
||||||
|
if (m.invisibleAnnotations != null) ret.addAll(m.invisibleAnnotations);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
} catch (Throwable e) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static int doMethodEmulation(String desc) {
|
private static int doMethodEmulation(String desc) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
@ -66,98 +69,98 @@ private static int doMethodEmulation(String desc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int opcodeEmulation(AbstractInsnNode e) {
|
public static int opcodeEmulation(AbstractInsnNode e) {
|
||||||
int stackSize = 0;
|
int stackSize = 0;
|
||||||
switch (e.getOpcode()) {
|
switch (e.getOpcode()) {
|
||||||
case NOP:
|
case NOP:
|
||||||
case LALOAD: // (index, arrayref) -> (long, long_top)
|
case LALOAD: // (index, arrayref) -> (long, long_top)
|
||||||
case DALOAD: // (index, arrayref) -> (double, double_top)
|
case DALOAD: // (index, arrayref) -> (double, double_top)
|
||||||
case SWAP: // (value1, value2) -> (value2, value1)
|
case SWAP: // (value1, value2) -> (value2, value1)
|
||||||
case INEG:
|
case INEG:
|
||||||
case LNEG:
|
case LNEG:
|
||||||
case FNEG:
|
case FNEG:
|
||||||
case DNEG:
|
case DNEG:
|
||||||
case IINC:
|
case IINC:
|
||||||
case I2F:
|
case I2F:
|
||||||
case L2D:
|
case L2D:
|
||||||
case F2I:
|
case F2I:
|
||||||
case D2L:
|
case D2L:
|
||||||
case I2B:
|
case I2B:
|
||||||
case I2C:
|
case I2C:
|
||||||
case I2S:
|
case I2S:
|
||||||
case GOTO:
|
case GOTO:
|
||||||
case RETURN:
|
case RETURN:
|
||||||
case NEWARRAY:
|
case NEWARRAY:
|
||||||
case ANEWARRAY:
|
case ANEWARRAY:
|
||||||
case ARRAYLENGTH:
|
case ARRAYLENGTH:
|
||||||
case CHECKCAST:
|
case CHECKCAST:
|
||||||
case INSTANCEOF:
|
case INSTANCEOF:
|
||||||
// Does nothing
|
// Does nothing
|
||||||
break;
|
break;
|
||||||
case ACONST_NULL:
|
case ACONST_NULL:
|
||||||
case ICONST_M1:
|
case ICONST_M1:
|
||||||
case ICONST_0:
|
case ICONST_0:
|
||||||
case ICONST_1:
|
case ICONST_1:
|
||||||
case ICONST_2:
|
case ICONST_2:
|
||||||
case ICONST_3:
|
case ICONST_3:
|
||||||
case ICONST_4:
|
case ICONST_4:
|
||||||
case ICONST_5:
|
case ICONST_5:
|
||||||
case FCONST_0:
|
case FCONST_0:
|
||||||
case FCONST_1:
|
case FCONST_1:
|
||||||
case FCONST_2:
|
case FCONST_2:
|
||||||
case BIPUSH:
|
case BIPUSH:
|
||||||
case SIPUSH:
|
case SIPUSH:
|
||||||
case ILOAD:
|
case ILOAD:
|
||||||
case FLOAD:
|
case FLOAD:
|
||||||
case ALOAD:
|
case ALOAD:
|
||||||
case DUP:
|
case DUP:
|
||||||
case DUP_X1:
|
case DUP_X1:
|
||||||
case DUP_X2:
|
case DUP_X2:
|
||||||
case I2L:
|
case I2L:
|
||||||
case I2D:
|
case I2D:
|
||||||
case F2L:
|
case F2L:
|
||||||
case F2D:
|
case F2D:
|
||||||
case NEW:
|
case NEW:
|
||||||
// Pushes one-word constant to stack
|
// Pushes one-word constant to stack
|
||||||
stackSize++;
|
|
||||||
break;
|
|
||||||
case LDC:
|
|
||||||
LdcInsnNode ldc = (LdcInsnNode) e;
|
|
||||||
if (ldc.cst instanceof Long || ldc.cst instanceof Double)
|
|
||||||
stackSize++;
|
stackSize++;
|
||||||
|
break;
|
||||||
|
case LDC:
|
||||||
|
LdcInsnNode ldc = (LdcInsnNode) e;
|
||||||
|
if (ldc.cst instanceof Long || ldc.cst instanceof Double)
|
||||||
|
stackSize++;
|
||||||
|
|
||||||
stackSize++;
|
stackSize++;
|
||||||
break;
|
break;
|
||||||
case LCONST_0:
|
case LCONST_0:
|
||||||
case LCONST_1:
|
case LCONST_1:
|
||||||
case DCONST_0:
|
case DCONST_0:
|
||||||
case DCONST_1:
|
case DCONST_1:
|
||||||
case LLOAD:
|
case LLOAD:
|
||||||
case DLOAD:
|
case DLOAD:
|
||||||
case DUP2:
|
case DUP2:
|
||||||
case DUP2_X1:
|
case DUP2_X1:
|
||||||
case DUP2_X2:
|
case DUP2_X2:
|
||||||
// Pushes two-word constant or two one-word constants to stack
|
// Pushes two-word constant or two one-word constants to stack
|
||||||
stackSize++;
|
stackSize++;
|
||||||
stackSize++;
|
stackSize++;
|
||||||
break;
|
break;
|
||||||
case INVOKEVIRTUAL:
|
case INVOKEVIRTUAL:
|
||||||
case INVOKESPECIAL:
|
case INVOKESPECIAL:
|
||||||
case INVOKEINTERFACE:
|
case INVOKEINTERFACE:
|
||||||
stackSize += doMethodEmulation(((MethodInsnNode) e).desc);
|
stackSize += doMethodEmulation(((MethodInsnNode) e).desc);
|
||||||
break;
|
break;
|
||||||
case INVOKESTATIC:
|
case INVOKESTATIC:
|
||||||
stackSize += doMethodEmulation(((MethodInsnNode) e).desc);
|
stackSize += doMethodEmulation(((MethodInsnNode) e).desc);
|
||||||
break;
|
break;
|
||||||
case INVOKEDYNAMIC:
|
case INVOKEDYNAMIC:
|
||||||
stackSize += doMethodEmulation(((InvokeDynamicInsnNode) e).desc);
|
stackSize += doMethodEmulation(((InvokeDynamicInsnNode) e).desc);
|
||||||
break;
|
break;
|
||||||
case JSR:
|
case JSR:
|
||||||
case RET:
|
case RET:
|
||||||
throw new RuntimeException("Did not expect JSR/RET instructions");
|
throw new RuntimeException("Did not expect JSR/RET instructions");
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return stackSize;
|
return stackSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static InsnList getSafeStringInsnList(String string) {
|
public static InsnList getSafeStringInsnList(String string) {
|
||||||
|
@ -181,7 +184,7 @@ public static InsnList getSafeStringInsnList(String string) {
|
||||||
return insnList;
|
return insnList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int MAX_SAFE_BYTE_COUNT = 65535-Byte.MAX_VALUE;
|
public static final int MAX_SAFE_BYTE_COUNT = 65535 - Byte.MAX_VALUE;
|
||||||
|
|
||||||
public static String[] splitUtf8ToChunks(String text, int maxBytes) {
|
public static String[] splitUtf8ToChunks(String text, int maxBytes) {
|
||||||
List<String> parts = new ArrayList<>();
|
List<String> parts = new ArrayList<>();
|
||||||
|
@ -220,15 +223,15 @@ public static int getUtf8CharSize(char c) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static InsnList push(final int value) {
|
public static InsnList push(final int value) {
|
||||||
InsnList ret = new InsnList();
|
InsnList ret = new InsnList();
|
||||||
if (value >= -1 && value <= 5)
|
if (value >= -1 && value <= 5)
|
||||||
ret.add(new InsnNode(Opcodes.ICONST_0 + value));
|
ret.add(new InsnNode(Opcodes.ICONST_0 + value));
|
||||||
else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE)
|
else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE)
|
||||||
ret.add(new IntInsnNode(Opcodes.BIPUSH, value));
|
ret.add(new IntInsnNode(Opcodes.BIPUSH, value));
|
||||||
else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE)
|
else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE)
|
||||||
ret.add(new IntInsnNode(Opcodes.SIPUSH, value));
|
ret.add(new IntInsnNode(Opcodes.SIPUSH, value));
|
||||||
else
|
else
|
||||||
ret.add(new LdcInsnNode(value));
|
ret.add(new LdcInsnNode(value));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package pro.gravit.launchserver.asm;
|
package pro.gravit.launchserver.asm;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import org.objectweb.asm.ClassReader;
|
import org.objectweb.asm.ClassReader;
|
||||||
import org.objectweb.asm.ClassWriter;
|
import org.objectweb.asm.ClassWriter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ClassWriter с другой реализацией метода getCommonSuperClass: при его
|
* ClassWriter с другой реализацией метода getCommonSuperClass: при его
|
||||||
* использовании не происходит загрузки классов.
|
* использовании не происходит загрузки классов.
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package pro.gravit.launchserver.auth;
|
package pro.gravit.launchserver.auth;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.auth.handler.AuthHandler;
|
import pro.gravit.launchserver.auth.handler.AuthHandler;
|
||||||
import pro.gravit.launchserver.auth.provider.AuthProvider;
|
import pro.gravit.launchserver.auth.provider.AuthProvider;
|
||||||
import pro.gravit.launchserver.auth.texture.TextureProvider;
|
import pro.gravit.launchserver.auth.texture.TextureProvider;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class AuthProviderPair {
|
public class AuthProviderPair {
|
||||||
public final AuthProvider provider;
|
public final AuthProvider provider;
|
||||||
public final AuthHandler handler;
|
public final AuthHandler handler;
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
package pro.gravit.launchserver.auth;
|
package pro.gravit.launchserver.auth;
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import com.mysql.cj.jdbc.MysqlDataSource;
|
import com.mysql.cj.jdbc.MysqlDataSource;
|
||||||
import com.zaxxer.hikari.HikariConfig;
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
import pro.gravit.utils.helper.VerifyHelper;
|
import pro.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public final class MySQLSourceConfig implements AutoCloseable {
|
public final class MySQLSourceConfig implements AutoCloseable {
|
||||||
|
|
||||||
public static final int TIMEOUT = VerifyHelper.verifyInt(
|
public static final int TIMEOUT = VerifyHelper.verifyInt(
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
package pro.gravit.launchserver.auth;
|
package pro.gravit.launchserver.auth;
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.postgresql.ds.PGSimpleDataSource;
|
|
||||||
|
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
import org.postgresql.ds.PGSimpleDataSource;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
import pro.gravit.utils.helper.VerifyHelper;
|
import pro.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public final class PostgreSQLSourceConfig implements AutoCloseable {
|
public final class PostgreSQLSourceConfig implements AutoCloseable {
|
||||||
public static final int TIMEOUT = VerifyHelper.verifyInt(
|
public static final int TIMEOUT = VerifyHelper.verifyInt(
|
||||||
Integer.parseUnsignedInt(System.getProperty("launcher.postgresql.idleTimeout", Integer.toString(5000))),
|
Integer.parseUnsignedInt(System.getProperty("launcher.postgresql.idleTimeout", Integer.toString(5000))),
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package pro.gravit.launchserver.auth.handler;
|
package pro.gravit.launchserver.auth.handler;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.auth.AuthException;
|
import pro.gravit.launchserver.auth.AuthException;
|
||||||
import pro.gravit.launchserver.auth.provider.AuthProviderResult;
|
import pro.gravit.launchserver.auth.provider.AuthProviderResult;
|
||||||
import pro.gravit.utils.ProviderMap;
|
import pro.gravit.utils.ProviderMap;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
||||||
public abstract class AuthHandler implements AutoCloseable {
|
public abstract class AuthHandler implements AutoCloseable {
|
||||||
public static final ProviderMap<AuthHandler> providers = new ProviderMap<>("AuthHandler");
|
public static final ProviderMap<AuthHandler> providers = new ProviderMap<>("AuthHandler");
|
||||||
|
@ -31,24 +31,24 @@ public static void registerHandlers() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected transient LaunchServer srv;
|
protected transient LaunchServer srv;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the UUID associated with the account
|
* Returns the UUID associated with the account
|
||||||
|
*
|
||||||
* @param authResult {@link pro.gravit.launchserver.auth.provider.AuthProvider} result
|
* @param authResult {@link pro.gravit.launchserver.auth.provider.AuthProvider} result
|
||||||
* @return User UUID
|
* @return User UUID
|
||||||
* @throws IOException
|
* @throws IOException Internal Script Error
|
||||||
* Internal Script Error
|
|
||||||
*/
|
*/
|
||||||
public abstract UUID auth(AuthProviderResult authResult) throws IOException;
|
public abstract UUID auth(AuthProviderResult authResult) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates serverID
|
* Validates serverID
|
||||||
|
*
|
||||||
* @param username user name
|
* @param username user name
|
||||||
* @param serverID serverID to check
|
* @param serverID serverID to check
|
||||||
* @return user UUID
|
* @return user UUID
|
||||||
* @throws IOException
|
* @throws IOException Internal Script Error
|
||||||
* Internal Script Error
|
|
||||||
*/
|
*/
|
||||||
public abstract UUID checkServer(String username, String serverID) throws IOException;
|
public abstract UUID checkServer(String username, String serverID) throws IOException;
|
||||||
|
|
||||||
|
@ -58,12 +58,12 @@ public static void registerHandlers() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks assessToken for validity and saves serverID if successful
|
* Checks assessToken for validity and saves serverID if successful
|
||||||
* @param username user name
|
*
|
||||||
|
* @param username user name
|
||||||
* @param accessToken assessToken to check
|
* @param accessToken assessToken to check
|
||||||
* @param serverID serverID to save
|
* @param serverID serverID to save
|
||||||
* @return true - allow, false - deny
|
* @return true - allow, false - deny
|
||||||
* @throws IOException
|
* @throws IOException Internal Script Error
|
||||||
* Internal Script Error
|
|
||||||
*/
|
*/
|
||||||
public abstract boolean joinServer(String username, String accessToken, String serverID) throws IOException;
|
public abstract boolean joinServer(String username, String accessToken, String serverID) throws IOException;
|
||||||
|
|
||||||
|
@ -74,6 +74,6 @@ public static void registerHandlers() {
|
||||||
public abstract String uuidToUsername(UUID uuid) throws IOException;
|
public abstract String uuidToUsername(UUID uuid) throws IOException;
|
||||||
|
|
||||||
public void init(LaunchServer srv) {
|
public void init(LaunchServer srv) {
|
||||||
this.srv = srv;
|
this.srv = srv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
package pro.gravit.launchserver.auth.handler;
|
package pro.gravit.launchserver.auth.handler;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.Launcher;
|
||||||
|
import pro.gravit.launcher.NeedGarbageCollection;
|
||||||
|
import pro.gravit.launchserver.Reconfigurable;
|
||||||
|
import pro.gravit.launchserver.auth.provider.AuthProviderResult;
|
||||||
|
import pro.gravit.utils.command.Command;
|
||||||
|
import pro.gravit.utils.command.SubCommand;
|
||||||
|
import pro.gravit.utils.helper.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
@ -9,18 +17,6 @@
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import pro.gravit.launcher.Launcher;
|
|
||||||
import pro.gravit.launcher.NeedGarbageCollection;
|
|
||||||
import pro.gravit.launchserver.Reconfigurable;
|
|
||||||
import pro.gravit.launchserver.auth.provider.AuthProviderResult;
|
|
||||||
import pro.gravit.utils.command.Command;
|
|
||||||
import pro.gravit.utils.command.SubCommand;
|
|
||||||
import pro.gravit.utils.helper.CommonHelper;
|
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
|
||||||
import pro.gravit.utils.helper.SecurityHelper;
|
|
||||||
import pro.gravit.utils.helper.VerifyHelper;
|
|
||||||
|
|
||||||
public abstract class CachedAuthHandler extends AuthHandler implements NeedGarbageCollection, Reconfigurable {
|
public abstract class CachedAuthHandler extends AuthHandler implements NeedGarbageCollection, Reconfigurable {
|
||||||
public static final class Entry {
|
public static final class Entry {
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,21 @@
|
||||||
package pro.gravit.launchserver.auth.handler;
|
package pro.gravit.launchserver.auth.handler;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.dao.User;
|
import pro.gravit.launchserver.dao.User;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class HibernateAuthHandler extends CachedAuthHandler {
|
public class HibernateAuthHandler extends CachedAuthHandler {
|
||||||
@Override
|
@Override
|
||||||
protected Entry fetchEntry(String username) {
|
protected Entry fetchEntry(String username) {
|
||||||
User user = srv.config.dao.userService.findUserByUsername(username);
|
User user = srv.config.dao.userService.findUserByUsername(username);
|
||||||
if(user == null) return null;
|
if (user == null) return null;
|
||||||
return new Entry(user.uuid, username, user.getAccessToken(), user.serverID);
|
return new Entry(user.uuid, username, user.getAccessToken(), user.serverID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Entry fetchEntry(UUID uuid) {
|
protected Entry fetchEntry(UUID uuid) {
|
||||||
User user = srv.config.dao.userService.findUserByUUID(uuid);
|
User user = srv.config.dao.userService.findUserByUUID(uuid);
|
||||||
if(user == null) return null;
|
if (user == null) return null;
|
||||||
return new Entry(user.uuid, user.username, user.getAccessToken(), user.serverID);
|
return new Entry(user.uuid, user.username, user.getAccessToken(), user.serverID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package pro.gravit.launchserver.auth.handler;
|
package pro.gravit.launchserver.auth.handler;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.Launcher;
|
||||||
|
import pro.gravit.utils.HTTPRequest;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import pro.gravit.launcher.Launcher;
|
|
||||||
import pro.gravit.utils.HTTPRequest;
|
|
||||||
|
|
||||||
public class JsonAuthHandler extends CachedAuthHandler {
|
public class JsonAuthHandler extends CachedAuthHandler {
|
||||||
public URL getUrl;
|
public URL getUrl;
|
||||||
public URL updateAuthUrl;
|
public URL updateAuthUrl;
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package pro.gravit.launchserver.auth.handler;
|
package pro.gravit.launchserver.auth.handler;
|
||||||
|
|
||||||
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
import pro.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
|
||||||
import pro.gravit.utils.helper.VerifyHelper;
|
|
||||||
|
|
||||||
public final class MemoryAuthHandler extends CachedAuthHandler {
|
public final class MemoryAuthHandler extends CachedAuthHandler {
|
||||||
private static String toUsername(UUID uuid) {
|
private static String toUsername(UUID uuid) {
|
||||||
byte[] bytes = ByteBuffer.allocate(16).
|
byte[] bytes = ByteBuffer.allocate(16).
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package pro.gravit.launchserver.auth.handler;
|
package pro.gravit.launchserver.auth.handler;
|
||||||
|
|
||||||
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
import pro.gravit.launchserver.auth.MySQLSourceConfig;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
@ -7,10 +11,6 @@
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
|
||||||
import pro.gravit.launchserver.auth.MySQLSourceConfig;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
public final class MySQLAuthHandler extends CachedAuthHandler {
|
public final class MySQLAuthHandler extends CachedAuthHandler {
|
||||||
private MySQLSourceConfig mySQLHolder;
|
private MySQLSourceConfig mySQLHolder;
|
||||||
private String uuidColumn;
|
private String uuidColumn;
|
||||||
|
@ -27,7 +27,7 @@ public final class MySQLAuthHandler extends CachedAuthHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(LaunchServer srv) {
|
public void init(LaunchServer srv) {
|
||||||
super.init(srv);
|
super.init(srv);
|
||||||
//Verify
|
//Verify
|
||||||
if (mySQLHolder == null) LogHelper.error("[Verify][AuthHandler] mySQLHolder cannot be null");
|
if (mySQLHolder == null) LogHelper.error("[Verify][AuthHandler] mySQLHolder cannot be null");
|
||||||
if (uuidColumn == null) LogHelper.error("[Verify][AuthHandler] uuidColumn cannot be null");
|
if (uuidColumn == null) LogHelper.error("[Verify][AuthHandler] uuidColumn cannot be null");
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package pro.gravit.launchserver.auth.handler;
|
package pro.gravit.launchserver.auth.handler;
|
||||||
|
|
||||||
|
import pro.gravit.launchserver.auth.provider.AuthProviderResult;
|
||||||
|
import pro.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import pro.gravit.launchserver.auth.provider.AuthProviderResult;
|
|
||||||
import pro.gravit.utils.helper.VerifyHelper;
|
|
||||||
|
|
||||||
public final class NullAuthHandler extends AuthHandler {
|
public final class NullAuthHandler extends AuthHandler {
|
||||||
private volatile AuthHandler handler;
|
private volatile AuthHandler handler;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package pro.gravit.launchserver.auth.handler;
|
package pro.gravit.launchserver.auth.handler;
|
||||||
|
|
||||||
|
import org.postgresql.util.PGobject;
|
||||||
|
import pro.gravit.launchserver.auth.PostgreSQLSourceConfig;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
@ -7,10 +10,6 @@
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.postgresql.util.PGobject;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.auth.PostgreSQLSourceConfig;
|
|
||||||
|
|
||||||
public final class PostgreSQLAuthHandler extends CachedAuthHandler {
|
public final class PostgreSQLAuthHandler extends CachedAuthHandler {
|
||||||
private PostgreSQLSourceConfig postgreSQLHolder;
|
private PostgreSQLSourceConfig postgreSQLHolder;
|
||||||
private String uuidColumn;
|
private String uuidColumn;
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package pro.gravit.launchserver.auth.handler;
|
package pro.gravit.launchserver.auth.handler;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.utils.helper.CommonHelper;
|
import pro.gravit.utils.helper.CommonHelper;
|
||||||
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.net.URL;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public final class RequestAuthHandler extends CachedAuthHandler {
|
public final class RequestAuthHandler extends CachedAuthHandler {
|
||||||
private String usernameFetch;
|
private String usernameFetch;
|
||||||
private String uuidFetch;
|
private String uuidFetch;
|
||||||
|
@ -21,7 +21,7 @@ public final class RequestAuthHandler extends CachedAuthHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(LaunchServer srv) {
|
public void init(LaunchServer srv) {
|
||||||
super.init(srv);
|
super.init(srv);
|
||||||
if (usernameFetch == null)
|
if (usernameFetch == null)
|
||||||
LogHelper.error("[Verify][AuthHandler] usernameFetch cannot be null");
|
LogHelper.error("[Verify][AuthHandler] usernameFetch cannot be null");
|
||||||
if (uuidFetch == null)
|
if (uuidFetch == null)
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package pro.gravit.launchserver.auth.hwid;
|
package pro.gravit.launchserver.auth.hwid;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.hwid.HWID;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import pro.gravit.launcher.hwid.HWID;
|
|
||||||
|
|
||||||
public class AcceptHWIDHandler extends HWIDHandler {
|
public class AcceptHWIDHandler extends HWIDHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package pro.gravit.launchserver.auth.hwid;
|
package pro.gravit.launchserver.auth.hwid;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.hwid.HWID;
|
import pro.gravit.launcher.hwid.HWID;
|
||||||
import pro.gravit.launchserver.Reconfigurable;
|
import pro.gravit.launchserver.Reconfigurable;
|
||||||
import pro.gravit.utils.ProviderMap;
|
import pro.gravit.utils.ProviderMap;
|
||||||
|
@ -11,6 +7,10 @@
|
||||||
import pro.gravit.utils.command.SubCommand;
|
import pro.gravit.utils.command.SubCommand;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class HWIDHandler implements AutoCloseable, Reconfigurable {
|
public abstract class HWIDHandler implements AutoCloseable, Reconfigurable {
|
||||||
public static final ProviderMap<HWIDHandler> providers = new ProviderMap<>("HWIDHandler");
|
public static final ProviderMap<HWIDHandler> providers = new ProviderMap<>("HWIDHandler");
|
||||||
private static boolean registredHandl = false;
|
private static boolean registredHandl = false;
|
||||||
|
@ -48,8 +48,7 @@ public void invoke(String... args) throws Exception {
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) throws Exception {
|
public void invoke(String... args) throws Exception {
|
||||||
List<HWID> target = getHwid(args[0]);
|
List<HWID> target = getHwid(args[0]);
|
||||||
for(HWID hwid : target)
|
for (HWID hwid : target) {
|
||||||
{
|
|
||||||
if (hwid == null) {
|
if (hwid == null) {
|
||||||
LogHelper.error("[%s] HWID: null", args[0]);
|
LogHelper.error("[%s] HWID: null", args[0]);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
package pro.gravit.launchserver.auth.hwid;
|
package pro.gravit.launchserver.auth.hwid;
|
||||||
|
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import pro.gravit.launcher.Launcher;
|
||||||
|
import pro.gravit.launcher.hwid.HWID;
|
||||||
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
@ -10,13 +16,6 @@
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import com.google.gson.reflect.TypeToken;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.Launcher;
|
|
||||||
import pro.gravit.launcher.hwid.HWID;
|
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
public class JsonFileHWIDHandler extends HWIDHandler {
|
public class JsonFileHWIDHandler extends HWIDHandler {
|
||||||
public static class Entry {
|
public static class Entry {
|
||||||
public final HWID hwid;
|
public final HWID hwid;
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
package pro.gravit.launchserver.auth.hwid;
|
package pro.gravit.launchserver.auth.hwid;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import pro.gravit.launcher.hwid.HWID;
|
||||||
|
import pro.gravit.launcher.hwid.OshiHWID;
|
||||||
|
import pro.gravit.utils.HTTPRequest;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.hwid.HWID;
|
|
||||||
import pro.gravit.launcher.hwid.OshiHWID;
|
|
||||||
import pro.gravit.utils.HTTPRequest;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
public final class JsonHWIDHandler extends HWIDHandler {
|
public final class JsonHWIDHandler extends HWIDHandler {
|
||||||
private static final Gson gson = new Gson();
|
private static final Gson gson = new Gson();
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package pro.gravit.launchserver.auth.hwid;
|
package pro.gravit.launchserver.auth.hwid;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.hwid.HWID;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import pro.gravit.launcher.hwid.HWID;
|
|
||||||
|
|
||||||
public class MemoryHWIDHandler extends HWIDHandler {
|
public class MemoryHWIDHandler extends HWIDHandler {
|
||||||
public static class Entry {
|
public static class Entry {
|
||||||
public final HWID hwid;
|
public final HWID hwid;
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
package pro.gravit.launchserver.auth.hwid;
|
package pro.gravit.launchserver.auth.hwid;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.hwid.HWID;
|
||||||
|
import pro.gravit.launcher.hwid.OshiHWID;
|
||||||
|
import pro.gravit.launchserver.auth.MySQLSourceConfig;
|
||||||
|
import pro.gravit.utils.helper.CommonHelper;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
@ -7,12 +13,6 @@
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import pro.gravit.launcher.hwid.HWID;
|
|
||||||
import pro.gravit.launcher.hwid.OshiHWID;
|
|
||||||
import pro.gravit.launchserver.auth.MySQLSourceConfig;
|
|
||||||
import pro.gravit.utils.helper.CommonHelper;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
public class MysqlHWIDHandler extends HWIDHandler {
|
public class MysqlHWIDHandler extends HWIDHandler {
|
||||||
private MySQLSourceConfig mySQLHolder;
|
private MySQLSourceConfig mySQLHolder;
|
||||||
|
|
||||||
|
|
|
@ -8,14 +8,14 @@ public class HibernatePermissionsHandler extends PermissionsHandler {
|
||||||
@Override
|
@Override
|
||||||
public ClientPermissions getPermissions(String username) {
|
public ClientPermissions getPermissions(String username) {
|
||||||
User user = srv.config.dao.userService.findUserByUsername(username);
|
User user = srv.config.dao.userService.findUserByUsername(username);
|
||||||
if(user == null) return ClientPermissions.DEFAULT;
|
if (user == null) return ClientPermissions.DEFAULT;
|
||||||
return user.getPermissions();
|
return user.getPermissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPermissions(String username, ClientPermissions permissions) {
|
public void setPermissions(String username, ClientPermissions permissions) {
|
||||||
User user = srv.config.dao.userService.findUserByUsername(username);
|
User user = srv.config.dao.userService.findUserByUsername(username);
|
||||||
if(user == null) return;
|
if (user == null) return;
|
||||||
user.setPermissions(permissions);
|
user.setPermissions(permissions);
|
||||||
srv.config.dao.userService.updateUser(user);
|
srv.config.dao.userService.updateUser(user);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,15 @@
|
||||||
package pro.gravit.launchserver.auth.permissions;
|
package pro.gravit.launchserver.auth.permissions;
|
||||||
|
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import pro.gravit.launcher.ClientPermissions;
|
||||||
|
import pro.gravit.launcher.Launcher;
|
||||||
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
import pro.gravit.launchserver.Reconfigurable;
|
||||||
|
import pro.gravit.utils.command.Command;
|
||||||
|
import pro.gravit.utils.command.SubCommand;
|
||||||
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
@ -9,17 +19,6 @@
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.google.gson.reflect.TypeToken;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.ClientPermissions;
|
|
||||||
import pro.gravit.launcher.Launcher;
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
|
||||||
import pro.gravit.launchserver.Reconfigurable;
|
|
||||||
import pro.gravit.utils.command.Command;
|
|
||||||
import pro.gravit.utils.command.SubCommand;
|
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
public class JsonFilePermissionsHandler extends PermissionsHandler implements Reconfigurable {
|
public class JsonFilePermissionsHandler extends PermissionsHandler implements Reconfigurable {
|
||||||
public final String filename = "permissions.json";
|
public final String filename = "permissions.json";
|
||||||
public static Map<String, ClientPermissions> map;
|
public static Map<String, ClientPermissions> map;
|
||||||
|
|
|
@ -1,5 +1,15 @@
|
||||||
package pro.gravit.launchserver.auth.permissions;
|
package pro.gravit.launchserver.auth.permissions;
|
||||||
|
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import pro.gravit.launcher.ClientPermissions;
|
||||||
|
import pro.gravit.launcher.Launcher;
|
||||||
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
import pro.gravit.launchserver.Reconfigurable;
|
||||||
|
import pro.gravit.utils.command.Command;
|
||||||
|
import pro.gravit.utils.command.SubCommand;
|
||||||
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
@ -9,17 +19,6 @@
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.google.gson.reflect.TypeToken;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.ClientPermissions;
|
|
||||||
import pro.gravit.launcher.Launcher;
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
|
||||||
import pro.gravit.launchserver.Reconfigurable;
|
|
||||||
import pro.gravit.utils.command.Command;
|
|
||||||
import pro.gravit.utils.command.SubCommand;
|
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
public class JsonLongFilePermissionsHandler extends PermissionsHandler implements Reconfigurable {
|
public class JsonLongFilePermissionsHandler extends PermissionsHandler implements Reconfigurable {
|
||||||
public final String filename = "permissions.json";
|
public final String filename = "permissions.json";
|
||||||
public final long defaultPerms = 0L;
|
public final long defaultPerms = 0L;
|
||||||
|
|
|
@ -20,8 +20,7 @@ public static void registerHandlers() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(LaunchServer server)
|
public void init(LaunchServer server) {
|
||||||
{
|
|
||||||
this.srv = server;
|
this.srv = server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
public class StdProtectHandler extends ProtectHandler {
|
public class StdProtectHandler extends ProtectHandler {
|
||||||
public final boolean checkSecure = true;
|
public final boolean checkSecure = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String generateSecureToken(AuthResponse.AuthContext context) {
|
public String generateSecureToken(AuthResponse.AuthContext context) {
|
||||||
return SecurityHelper.randomStringToken();
|
return SecurityHelper.randomStringToken();
|
||||||
|
|
|
@ -1,16 +1,17 @@
|
||||||
package pro.gravit.launchserver.auth.provider;
|
package pro.gravit.launchserver.auth.provider;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.request.auth.AuthRequest;
|
import pro.gravit.launcher.request.auth.AuthRequest;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.auth.AuthException;
|
import pro.gravit.launchserver.auth.AuthException;
|
||||||
import pro.gravit.utils.ProviderMap;
|
import pro.gravit.utils.ProviderMap;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public abstract class AuthProvider implements AutoCloseable {
|
public abstract class AuthProvider implements AutoCloseable {
|
||||||
public static final ProviderMap<AuthProvider> providers = new ProviderMap<>("AuthProvider");
|
public static final ProviderMap<AuthProvider> providers = new ProviderMap<>("AuthProvider");
|
||||||
private static boolean registredProv = false;
|
private static boolean registredProv = false;
|
||||||
protected transient LaunchServer srv = null;
|
protected transient LaunchServer srv = null;
|
||||||
|
|
||||||
public static AuthProviderResult authError(String message) throws AuthException {
|
public static AuthProviderResult authError(String message) throws AuthException {
|
||||||
throw new AuthException(message);
|
throw new AuthException(message);
|
||||||
}
|
}
|
||||||
|
@ -32,13 +33,13 @@ public static void registerProviders() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies the username and password
|
* Verifies the username and password
|
||||||
* @param login user login
|
*
|
||||||
|
* @param login user login
|
||||||
* @param password user password
|
* @param password user password
|
||||||
* @param ip user ip
|
* @param ip user ip
|
||||||
* @return player privileges, effective username and authorization token
|
* @return player privileges, effective username and authorization token
|
||||||
* @throws Exception
|
* @throws Exception Throws an exception {@link AuthException} {@link pro.gravit.utils.HookException} if the verification script returned a meaningful error
|
||||||
* Throws an exception {@link AuthException} {@link pro.gravit.utils.HookException} if the verification script returned a meaningful error
|
* In other cases, throwing an exception indicates a serious error
|
||||||
* In other cases, throwing an exception indicates a serious error
|
|
||||||
*/
|
*/
|
||||||
public abstract AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws Exception;
|
public abstract AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws Exception;
|
||||||
|
|
||||||
|
@ -49,6 +50,6 @@ public void preAuth(String login, AuthRequest.AuthPasswordInterface password, St
|
||||||
public abstract void close() throws IOException;
|
public abstract void close() throws IOException;
|
||||||
|
|
||||||
public void init(LaunchServer srv) {
|
public void init(LaunchServer srv) {
|
||||||
this.srv = srv;
|
this.srv = srv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package pro.gravit.launchserver.auth.provider;
|
package pro.gravit.launchserver.auth.provider;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.request.auth.AuthRequest;
|
import pro.gravit.launcher.request.auth.AuthRequest;
|
||||||
import pro.gravit.launcher.request.auth.password.AuthPlainPassword;
|
import pro.gravit.launcher.request.auth.password.AuthPlainPassword;
|
||||||
import pro.gravit.launchserver.auth.AuthException;
|
import pro.gravit.launchserver.auth.AuthException;
|
||||||
|
@ -11,25 +9,21 @@
|
||||||
|
|
||||||
public class HibernateAuthProvider extends AuthProvider {
|
public class HibernateAuthProvider extends AuthProvider {
|
||||||
public boolean autoReg;
|
public boolean autoReg;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws Exception {
|
public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws Exception {
|
||||||
if(!(password instanceof AuthPlainPassword)) throw new AuthException("This password type not supported");
|
if (!(password instanceof AuthPlainPassword)) throw new AuthException("This password type not supported");
|
||||||
User user = srv.config.dao.userService.findUserByUsername(login);
|
User user = srv.config.dao.userService.findUserByUsername(login);
|
||||||
if(user == null && autoReg)
|
if (user == null && autoReg) {
|
||||||
{
|
|
||||||
AuthHookManager.RegContext context = new AuthHookManager.RegContext(login, ((AuthPlainPassword) password).password, ip, false);
|
AuthHookManager.RegContext context = new AuthHookManager.RegContext(login, ((AuthPlainPassword) password).password, ip, false);
|
||||||
if(srv.authHookManager.registraion.hook(context))
|
if (srv.authHookManager.registraion.hook(context)) {
|
||||||
{
|
|
||||||
user = srv.config.dao.userService.registerNewUser(login, ((AuthPlainPassword) password).password);
|
user = srv.config.dao.userService.registerNewUser(login, ((AuthPlainPassword) password).password);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new AuthException("Registration canceled. Try again later");
|
throw new AuthException("Registration canceled. Try again later");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(user == null || !user.verifyPassword(((AuthPlainPassword) password).password))
|
if (user == null || !user.verifyPassword(((AuthPlainPassword) password).password)) {
|
||||||
{
|
if (user == null) throw new AuthException("Username incorrect");
|
||||||
if(user ==null) throw new AuthException("Username incorrect");
|
|
||||||
else throw new AuthException("Username or password incorrect");
|
else throw new AuthException("Username or password incorrect");
|
||||||
}
|
}
|
||||||
return new AuthProviderResult(login, SecurityHelper.randomStringToken(), srv);
|
return new AuthProviderResult(login, SecurityHelper.randomStringToken(), srv);
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
package pro.gravit.launchserver.auth.provider;
|
package pro.gravit.launchserver.auth.provider;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
|
||||||
import pro.gravit.launcher.ClientPermissions;
|
import pro.gravit.launcher.ClientPermissions;
|
||||||
import pro.gravit.launcher.request.auth.AuthRequest;
|
import pro.gravit.launcher.request.auth.AuthRequest;
|
||||||
import pro.gravit.launcher.request.auth.password.AuthPlainPassword;
|
import pro.gravit.launcher.request.auth.password.AuthPlainPassword;
|
||||||
|
@ -13,6 +9,9 @@
|
||||||
import pro.gravit.utils.HTTPRequest;
|
import pro.gravit.utils.HTTPRequest;
|
||||||
import pro.gravit.utils.helper.SecurityHelper;
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
public final class JsonAuthProvider extends AuthProvider {
|
public final class JsonAuthProvider extends AuthProvider {
|
||||||
private static final Gson gson = new Gson();
|
private static final Gson gson = new Gson();
|
||||||
private URL url;
|
private URL url;
|
||||||
|
@ -46,7 +45,7 @@ public authRequest(String username, String password, String ip, String apiKey) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws IOException {
|
public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws IOException {
|
||||||
if(!(password instanceof AuthPlainPassword)) throw new AuthException("This password type not supported");
|
if (!(password instanceof AuthPlainPassword)) throw new AuthException("This password type not supported");
|
||||||
authRequest authRequest = new authRequest(login, ((AuthPlainPassword) password).password, ip, apiKey);
|
authRequest authRequest = new authRequest(login, ((AuthPlainPassword) password).password, ip, apiKey);
|
||||||
JsonElement request = gson.toJsonTree(authRequest);
|
JsonElement request = gson.toJsonTree(authRequest);
|
||||||
JsonElement content = HTTPRequest.jsonRequest(request, url);
|
JsonElement content = HTTPRequest.jsonRequest(request, url);
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
package pro.gravit.launchserver.auth.provider;
|
package pro.gravit.launchserver.auth.provider;
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.ClientPermissions;
|
import pro.gravit.launcher.ClientPermissions;
|
||||||
import pro.gravit.launcher.request.auth.AuthRequest;
|
import pro.gravit.launcher.request.auth.AuthRequest;
|
||||||
import pro.gravit.launcher.request.auth.password.AuthPlainPassword;
|
import pro.gravit.launcher.request.auth.password.AuthPlainPassword;
|
||||||
|
@ -15,6 +10,11 @@
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
import pro.gravit.utils.helper.SecurityHelper;
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public final class MySQLAuthProvider extends AuthProvider {
|
public final class MySQLAuthProvider extends AuthProvider {
|
||||||
private MySQLSourceConfig mySQLHolder;
|
private MySQLSourceConfig mySQLHolder;
|
||||||
private String query;
|
private String query;
|
||||||
|
@ -24,7 +24,7 @@ public final class MySQLAuthProvider extends AuthProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(LaunchServer srv) {
|
public void init(LaunchServer srv) {
|
||||||
super.init(srv);
|
super.init(srv);
|
||||||
if (query == null) LogHelper.error("[Verify][AuthProvider] query cannot be null");
|
if (query == null) LogHelper.error("[Verify][AuthProvider] query cannot be null");
|
||||||
if (message == null) LogHelper.error("[Verify][AuthProvider] message cannot be null");
|
if (message == null) LogHelper.error("[Verify][AuthProvider] message cannot be null");
|
||||||
if (mySQLHolder == null) LogHelper.error("[Verify][AuthProvider] mySQLHolder cannot be null");
|
if (mySQLHolder == null) LogHelper.error("[Verify][AuthProvider] mySQLHolder cannot be null");
|
||||||
|
@ -32,7 +32,7 @@ public void init(LaunchServer srv) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws SQLException, AuthException {
|
public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws SQLException, AuthException {
|
||||||
if(!(password instanceof AuthPlainPassword)) throw new AuthException("This password type not supported");
|
if (!(password instanceof AuthPlainPassword)) throw new AuthException("This password type not supported");
|
||||||
try (Connection c = mySQLHolder.getConnection()) {
|
try (Connection c = mySQLHolder.getConnection()) {
|
||||||
PreparedStatement s = c.prepareStatement(query);
|
PreparedStatement s = c.prepareStatement(query);
|
||||||
String[] replaceParams = {"login", login, "password", ((AuthPlainPassword) password).password, "ip", ip};
|
String[] replaceParams = {"login", login, "password", ((AuthPlainPassword) password).password, "ip", ip};
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package pro.gravit.launchserver.auth.provider;
|
package pro.gravit.launchserver.auth.provider;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.request.auth.AuthRequest;
|
import pro.gravit.launcher.request.auth.AuthRequest;
|
||||||
import pro.gravit.utils.helper.VerifyHelper;
|
import pro.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public final class NullAuthProvider extends AuthProvider {
|
public final class NullAuthProvider extends AuthProvider {
|
||||||
private volatile AuthProvider provider;
|
private volatile AuthProvider provider;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
package pro.gravit.launchserver.auth.provider;
|
package pro.gravit.launchserver.auth.provider;
|
||||||
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.ClientPermissions;
|
import pro.gravit.launcher.ClientPermissions;
|
||||||
import pro.gravit.launcher.request.auth.AuthRequest;
|
import pro.gravit.launcher.request.auth.AuthRequest;
|
||||||
import pro.gravit.launcher.request.auth.password.AuthPlainPassword;
|
import pro.gravit.launcher.request.auth.password.AuthPlainPassword;
|
||||||
|
@ -14,6 +9,11 @@
|
||||||
import pro.gravit.utils.helper.CommonHelper;
|
import pro.gravit.utils.helper.CommonHelper;
|
||||||
import pro.gravit.utils.helper.SecurityHelper;
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public final class PostgreSQLAuthProvider extends AuthProvider {
|
public final class PostgreSQLAuthProvider extends AuthProvider {
|
||||||
private PostgreSQLSourceConfig postgreSQLHolder;
|
private PostgreSQLSourceConfig postgreSQLHolder;
|
||||||
private String query;
|
private String query;
|
||||||
|
@ -23,7 +23,7 @@ public final class PostgreSQLAuthProvider extends AuthProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws SQLException, AuthException {
|
public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws SQLException, AuthException {
|
||||||
if(!(password instanceof AuthPlainPassword)) throw new AuthException("This password type not supported");
|
if (!(password instanceof AuthPlainPassword)) throw new AuthException("This password type not supported");
|
||||||
try (Connection c = postgreSQLHolder.getConnection(); PreparedStatement s = c.prepareStatement(query)) {
|
try (Connection c = postgreSQLHolder.getConnection(); PreparedStatement s = c.prepareStatement(query)) {
|
||||||
String[] replaceParams = {"login", login, "password", ((AuthPlainPassword) password).password, "ip", ip};
|
String[] replaceParams = {"login", login, "password", ((AuthPlainPassword) password).password, "ip", ip};
|
||||||
for (int i = 0; i < queryParams.length; i++) {
|
for (int i = 0; i < queryParams.length; i++) {
|
||||||
|
@ -40,6 +40,6 @@ public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface p
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
postgreSQLHolder.close();
|
postgreSQLHolder.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,9 +1,5 @@
|
||||||
package pro.gravit.launchserver.auth.provider;
|
package pro.gravit.launchserver.auth.provider;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.request.auth.AuthRequest;
|
import pro.gravit.launcher.request.auth.AuthRequest;
|
||||||
import pro.gravit.launchserver.Reconfigurable;
|
import pro.gravit.launchserver.Reconfigurable;
|
||||||
import pro.gravit.launchserver.auth.AuthException;
|
import pro.gravit.launchserver.auth.AuthException;
|
||||||
|
@ -12,6 +8,10 @@
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
import pro.gravit.utils.helper.SecurityHelper;
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public final class RejectAuthProvider extends AuthProvider implements Reconfigurable {
|
public final class RejectAuthProvider extends AuthProvider implements Reconfigurable {
|
||||||
public RejectAuthProvider() {
|
public RejectAuthProvider() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
package pro.gravit.launchserver.auth.provider;
|
package pro.gravit.launchserver.auth.provider;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.ClientPermissions;
|
import pro.gravit.launcher.ClientPermissions;
|
||||||
import pro.gravit.launcher.request.auth.AuthRequest;
|
import pro.gravit.launcher.request.auth.AuthRequest;
|
||||||
import pro.gravit.launcher.request.auth.password.AuthPlainPassword;
|
import pro.gravit.launcher.request.auth.password.AuthPlainPassword;
|
||||||
|
@ -15,6 +10,11 @@
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
import pro.gravit.utils.helper.SecurityHelper;
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public final class RequestAuthProvider extends AuthProvider {
|
public final class RequestAuthProvider extends AuthProvider {
|
||||||
private String url;
|
private String url;
|
||||||
private transient Pattern pattern;
|
private transient Pattern pattern;
|
||||||
|
@ -23,7 +23,7 @@ public final class RequestAuthProvider extends AuthProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(LaunchServer srv) {
|
public void init(LaunchServer srv) {
|
||||||
super.init(srv);
|
super.init(srv);
|
||||||
if (url == null) LogHelper.error("[Verify][AuthProvider] url cannot be null");
|
if (url == null) LogHelper.error("[Verify][AuthProvider] url cannot be null");
|
||||||
if (response == null) LogHelper.error("[Verify][AuthProvider] response cannot be null");
|
if (response == null) LogHelper.error("[Verify][AuthProvider] response cannot be null");
|
||||||
pattern = Pattern.compile(response);
|
pattern = Pattern.compile(response);
|
||||||
|
@ -31,7 +31,7 @@ public void init(LaunchServer srv) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws IOException {
|
public AuthProviderResult auth(String login, AuthRequest.AuthPasswordInterface password, String ip) throws IOException {
|
||||||
if(!(password instanceof AuthPlainPassword)) throw new AuthException("This password type not supported");
|
if (!(password instanceof AuthPlainPassword)) throw new AuthException("This password type not supported");
|
||||||
String currentResponse = IOHelper.request(new URL(getFormattedURL(login, ((AuthPlainPassword) password).password, ip)));
|
String currentResponse = IOHelper.request(new URL(getFormattedURL(login, ((AuthPlainPassword) password).password, ip)));
|
||||||
|
|
||||||
// Match username
|
// Match username
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package pro.gravit.launchserver.auth.texture;
|
package pro.gravit.launchserver.auth.texture;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.profiles.Texture;
|
||||||
|
import pro.gravit.utils.helper.VerifyHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import pro.gravit.launcher.profiles.Texture;
|
|
||||||
import pro.gravit.utils.helper.VerifyHelper;
|
|
||||||
|
|
||||||
public final class NullTextureProvider extends TextureProvider {
|
public final class NullTextureProvider extends TextureProvider {
|
||||||
private volatile TextureProvider provider;
|
private volatile TextureProvider provider;
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package pro.gravit.launchserver.auth.texture;
|
package pro.gravit.launchserver.auth.texture;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.Launcher;
|
import pro.gravit.launcher.Launcher;
|
||||||
import pro.gravit.launcher.profiles.Texture;
|
import pro.gravit.launcher.profiles.Texture;
|
||||||
import pro.gravit.utils.helper.CommonHelper;
|
import pro.gravit.utils.helper.CommonHelper;
|
||||||
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.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public final class RequestTextureProvider extends TextureProvider {
|
public final class RequestTextureProvider extends TextureProvider {
|
||||||
public RequestTextureProvider() {
|
public RequestTextureProvider() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package pro.gravit.launchserver.auth.texture;
|
package pro.gravit.launchserver.auth.texture;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.profiles.Texture;
|
import pro.gravit.launcher.profiles.Texture;
|
||||||
import pro.gravit.utils.ProviderMap;
|
import pro.gravit.utils.ProviderMap;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public abstract class TextureProvider implements AutoCloseable {
|
public abstract class TextureProvider implements AutoCloseable {
|
||||||
public static final ProviderMap<TextureProvider> providers = new ProviderMap<>("TextureProvider");
|
public static final ProviderMap<TextureProvider> providers = new ProviderMap<>("TextureProvider");
|
||||||
private static boolean registredProv = false;
|
private static boolean registredProv = false;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package pro.gravit.launchserver.auth.texture;
|
package pro.gravit.launchserver.auth.texture;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.profiles.Texture;
|
import pro.gravit.launcher.profiles.Texture;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public final class VoidTextureProvider extends TextureProvider {
|
public final class VoidTextureProvider extends TextureProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package pro.gravit.launchserver.binary;
|
package pro.gravit.launchserver.binary;
|
||||||
|
|
||||||
|
import pro.gravit.launchserver.binary.tasks.MainBuildTask;
|
||||||
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -8,9 +11,6 @@
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
import pro.gravit.launchserver.binary.tasks.MainBuildTask;
|
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
|
||||||
|
|
||||||
public class BuildContext {
|
public class BuildContext {
|
||||||
public final ZipOutputStream output;
|
public final ZipOutputStream output;
|
||||||
public final LauncherConfigurator config;
|
public final LauncherConfigurator config;
|
||||||
|
|
|
@ -1,20 +1,16 @@
|
||||||
package pro.gravit.launchserver.binary;
|
package pro.gravit.launchserver.binary;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
import net.sf.launch4j.Builder;
|
import net.sf.launch4j.Builder;
|
||||||
import net.sf.launch4j.Log;
|
import net.sf.launch4j.Log;
|
||||||
import net.sf.launch4j.config.Config;
|
import net.sf.launch4j.config.*;
|
||||||
import net.sf.launch4j.config.ConfigPersister;
|
|
||||||
import net.sf.launch4j.config.Jre;
|
|
||||||
import net.sf.launch4j.config.LanguageID;
|
|
||||||
import net.sf.launch4j.config.VersionInfo;
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.utils.Version;
|
import pro.gravit.utils.Version;
|
||||||
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.nio.file.Path;
|
||||||
|
|
||||||
public final class EXEL4JLauncherBinary extends LauncherBinary {
|
public final class EXEL4JLauncherBinary extends LauncherBinary {
|
||||||
private final static class Launch4JLog extends Log {
|
private final static class Launch4JLog extends Log {
|
||||||
private static final Launch4JLog INSTANCE = new Launch4JLog();
|
private static final Launch4JLog INSTANCE = new Launch4JLog();
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package pro.gravit.launchserver.binary;
|
package pro.gravit.launchserver.binary;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
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.nio.file.Files;
|
||||||
|
|
||||||
public class EXELauncherBinary extends LauncherBinary {
|
public class EXELauncherBinary extends LauncherBinary {
|
||||||
|
|
||||||
public EXELauncherBinary(LaunchServer server) {
|
public EXELauncherBinary(LaunchServer server) {
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
package pro.gravit.launchserver.binary;
|
package pro.gravit.launchserver.binary;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.Launcher;
|
||||||
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
import pro.gravit.launchserver.binary.tasks.*;
|
||||||
|
import pro.gravit.utils.helper.CommonHelper;
|
||||||
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -7,19 +14,6 @@
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import pro.gravit.launcher.Launcher;
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
|
||||||
import pro.gravit.launchserver.binary.tasks.AdditionalFixesApplyTask;
|
|
||||||
import pro.gravit.launchserver.binary.tasks.AttachJarsTask;
|
|
||||||
import pro.gravit.launchserver.binary.tasks.CompressBuildTask;
|
|
||||||
import pro.gravit.launchserver.binary.tasks.LauncherBuildTask;
|
|
||||||
import pro.gravit.launchserver.binary.tasks.MainBuildTask;
|
|
||||||
import pro.gravit.launchserver.binary.tasks.PrepareBuildTask;
|
|
||||||
import pro.gravit.launchserver.binary.tasks.ProGuardBuildTask;
|
|
||||||
import pro.gravit.utils.helper.CommonHelper;
|
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
public final class JARLauncherBinary extends LauncherBinary {
|
public final class JARLauncherBinary extends LauncherBinary {
|
||||||
public final AtomicLong count;
|
public final AtomicLong count;
|
||||||
public final Path runtimeDir;
|
public final Path runtimeDir;
|
||||||
|
@ -52,7 +46,7 @@ public void init() {
|
||||||
tasks.add(new ProGuardBuildTask(server));
|
tasks.add(new ProGuardBuildTask(server));
|
||||||
tasks.add(new AdditionalFixesApplyTask(server));
|
tasks.add(new AdditionalFixesApplyTask(server));
|
||||||
if (!server.config.launcher.attachLibraryBeforeProGuard) tasks.add(new AttachJarsTask(server));
|
if (!server.config.launcher.attachLibraryBeforeProGuard) tasks.add(new AttachJarsTask(server));
|
||||||
if(server.config.launcher.compress) tasks.add(new CompressBuildTask(server));
|
if (server.config.launcher.compress) tasks.add(new CompressBuildTask(server));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package pro.gravit.launchserver.binary;
|
package pro.gravit.launchserver.binary;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
import pro.gravit.utils.helper.SecurityHelper;
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public abstract class LauncherBinary {
|
public abstract class LauncherBinary {
|
||||||
public final LaunchServer server;
|
public final LaunchServer server;
|
||||||
public final Path syncBinaryFile;
|
public final Path syncBinaryFile;
|
||||||
|
|
|
@ -2,14 +2,7 @@
|
||||||
|
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.Type;
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
import org.objectweb.asm.tree.*;
|
||||||
import org.objectweb.asm.tree.FieldInsnNode;
|
|
||||||
import org.objectweb.asm.tree.InsnList;
|
|
||||||
import org.objectweb.asm.tree.InsnNode;
|
|
||||||
import org.objectweb.asm.tree.MethodInsnNode;
|
|
||||||
import org.objectweb.asm.tree.MethodNode;
|
|
||||||
import org.objectweb.asm.tree.TypeInsnNode;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.LauncherConfig;
|
import pro.gravit.launcher.LauncherConfig;
|
||||||
import pro.gravit.launcher.modules.LauncherModule;
|
import pro.gravit.launcher.modules.LauncherModule;
|
||||||
import pro.gravit.launchserver.asm.ClassMetadataReader;
|
import pro.gravit.launchserver.asm.ClassMetadataReader;
|
||||||
|
@ -23,7 +16,7 @@ public class LauncherConfigurator extends ConfigGenerator {
|
||||||
private final MethodNode initModuleMethod;
|
private final MethodNode initModuleMethod;
|
||||||
|
|
||||||
public LauncherConfigurator(ClassNode configclass) {
|
public LauncherConfigurator(ClassNode configclass) {
|
||||||
super(configclass);
|
super(configclass);
|
||||||
initModuleMethod = configclass.methods.stream().filter(e -> "initModules".equals(e.name)).findFirst().get();
|
initModuleMethod = configclass.methods.stream().filter(e -> "initModules".equals(e.name)).findFirst().get();
|
||||||
initModuleMethod.instructions = new InsnList();
|
initModuleMethod.instructions = new InsnList();
|
||||||
}
|
}
|
||||||
|
@ -38,7 +31,7 @@ public void addModuleClass(String fullName) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] getBytecode(ClassMetadataReader reader) {
|
public byte[] getBytecode(ClassMetadataReader reader) {
|
||||||
initModuleMethod.instructions.add(new InsnNode(Opcodes.RETURN));
|
initModuleMethod.instructions.add(new InsnNode(Opcodes.RETURN));
|
||||||
return super.getBytecode(reader);
|
return super.getBytecode(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
package pro.gravit.launchserver.binary;
|
package pro.gravit.launchserver.binary;
|
||||||
|
|
||||||
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
|
import pro.gravit.utils.helper.UnpackHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
@ -9,12 +15,6 @@
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
|
||||||
import pro.gravit.utils.helper.SecurityHelper;
|
|
||||||
import pro.gravit.utils.helper.UnpackHelper;
|
|
||||||
|
|
||||||
public class ProguardConf {
|
public class ProguardConf {
|
||||||
private static final String chars = "1aAbBcC2dDeEfF3gGhHiI4jJkKl5mMnNoO6pPqQrR7sStT8uUvV9wWxX0yYzZ";
|
private static final String chars = "1aAbBcC2dDeEfF3gGhHiI4jJkKl5mMnNoO6pPqQrR7sStT8uUvV9wWxX0yYzZ";
|
||||||
|
|
||||||
|
@ -45,7 +45,8 @@ public ProguardConf(LaunchServer srv) {
|
||||||
public String[] buildConfig(Path inputJar, Path outputJar) {
|
public String[] buildConfig(Path inputJar, Path outputJar) {
|
||||||
List<String> confStrs = new ArrayList<>();
|
List<String> confStrs = new ArrayList<>();
|
||||||
prepare(false);
|
prepare(false);
|
||||||
if (srv.config.launcher.proguardGenMappings) confStrs.add("-printmapping \'" + mappings.toFile().getName() + "\'");
|
if (srv.config.launcher.proguardGenMappings)
|
||||||
|
confStrs.add("-printmapping \'" + mappings.toFile().getName() + "\'");
|
||||||
confStrs.add("-obfuscationdictionary \'" + words.toFile().getName() + "\'");
|
confStrs.add("-obfuscationdictionary \'" + words.toFile().getName() + "\'");
|
||||||
confStrs.add("-injar \'" + inputJar.toAbsolutePath() + "\'");
|
confStrs.add("-injar \'" + inputJar.toAbsolutePath() + "\'");
|
||||||
confStrs.add("-outjar \'" + outputJar.toAbsolutePath() + "\'");
|
confStrs.add("-outjar \'" + outputJar.toAbsolutePath() + "\'");
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
package pro.gravit.launchserver.binary;
|
package pro.gravit.launchserver.binary;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
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.io.OutputStream;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public class SimpleEXELauncherBinary extends LauncherBinary {
|
public class SimpleEXELauncherBinary extends LauncherBinary {
|
||||||
public final Path exeTemplate;
|
public final Path exeTemplate;
|
||||||
|
|
||||||
public SimpleEXELauncherBinary(LaunchServer server) {
|
public SimpleEXELauncherBinary(LaunchServer server) {
|
||||||
super(server, LauncherBinary.resolve(server, ".exe"));
|
super(server, LauncherBinary.resolve(server, ".exe"));
|
||||||
exeTemplate = server.dir.resolve("SimpleTemplate.exe");
|
exeTemplate = server.dir.resolve("SimpleTemplate.exe");
|
||||||
|
@ -17,13 +18,11 @@ public SimpleEXELauncherBinary(LaunchServer server) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build() throws IOException {
|
public void build() throws IOException {
|
||||||
if(!IOHelper.isFile(exeTemplate))
|
if (!IOHelper.isFile(exeTemplate)) {
|
||||||
{
|
|
||||||
LogHelper.warning("[SimpleEXEBinary] File %s not found. %s not created", exeTemplate.toString(), syncBinaryFile.toString());
|
LogHelper.warning("[SimpleEXEBinary] File %s not found. %s not created", exeTemplate.toString(), syncBinaryFile.toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try(OutputStream output = IOHelper.newOutput(syncBinaryFile))
|
try (OutputStream output = IOHelper.newOutput(syncBinaryFile)) {
|
||||||
{
|
|
||||||
IOHelper.transfer(exeTemplate, output);
|
IOHelper.transfer(exeTemplate, output);
|
||||||
IOHelper.transfer(server.launcherBinary.syncBinaryFile, output);
|
IOHelper.transfer(server.launcherBinary.syncBinaryFile, output);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
package pro.gravit.launchserver.binary.tasks;
|
package pro.gravit.launchserver.binary.tasks;
|
||||||
|
|
||||||
|
import org.objectweb.asm.ClassReader;
|
||||||
|
import org.objectweb.asm.ClassWriter;
|
||||||
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
import pro.gravit.launchserver.asm.ClassMetadataReader;
|
||||||
|
import pro.gravit.launchserver.asm.SafeClassWriter;
|
||||||
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -11,16 +20,6 @@
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
import org.objectweb.asm.ClassReader;
|
|
||||||
import org.objectweb.asm.ClassWriter;
|
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
|
||||||
import pro.gravit.launchserver.asm.ClassMetadataReader;
|
|
||||||
import pro.gravit.launchserver.asm.SafeClassWriter;
|
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
public class AdditionalFixesApplyTask implements LauncherBuildTask {
|
public class AdditionalFixesApplyTask implements LauncherBuildTask {
|
||||||
private final LaunchServer server;
|
private final LaunchServer server;
|
||||||
|
|
||||||
|
@ -75,9 +74,9 @@ public static void apply(Path inputFile, Path addFile, ZipOutputStream output, L
|
||||||
bytes = outputStream.toByteArray();
|
bytes = outputStream.toByteArray();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
bytes = classFix(bytes, reader, srv.config.launcher.stripLineNumbers);
|
bytes = classFix(bytes, reader, srv.config.launcher.stripLineNumbers);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
LogHelper.error(t);
|
LogHelper.error(t);
|
||||||
}
|
}
|
||||||
output.write(bytes);
|
output.write(bytes);
|
||||||
} else
|
} else
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
package pro.gravit.launchserver.binary.tasks;
|
package pro.gravit.launchserver.binary.tasks;
|
||||||
|
|
||||||
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -8,10 +12,6 @@
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
public class AttachJarsTask implements LauncherBuildTask {
|
public class AttachJarsTask implements LauncherBuildTask {
|
||||||
private final LaunchServer srv;
|
private final LaunchServer srv;
|
||||||
private final List<Path> jars;
|
private final List<Path> jars;
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package pro.gravit.launchserver.binary.tasks;
|
package pro.gravit.launchserver.binary.tasks;
|
||||||
|
|
||||||
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.zip.Deflater;
|
import java.util.zip.Deflater;
|
||||||
|
@ -7,9 +10,6 @@
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
|
||||||
|
|
||||||
public class CompressBuildTask implements LauncherBuildTask {
|
public class CompressBuildTask implements LauncherBuildTask {
|
||||||
public transient final LaunchServer server;
|
public transient final LaunchServer server;
|
||||||
|
|
||||||
|
@ -25,12 +25,10 @@ public String getName() {
|
||||||
@Override
|
@Override
|
||||||
public Path process(Path inputFile) throws IOException {
|
public Path process(Path inputFile) throws IOException {
|
||||||
Path output = server.launcherBinary.nextPath(this);
|
Path output = server.launcherBinary.nextPath(this);
|
||||||
try(ZipOutputStream outputStream = new ZipOutputStream(IOHelper.newOutput(output)))
|
try (ZipOutputStream outputStream = new ZipOutputStream(IOHelper.newOutput(output))) {
|
||||||
{
|
|
||||||
outputStream.setMethod(ZipOutputStream.DEFLATED);
|
outputStream.setMethod(ZipOutputStream.DEFLATED);
|
||||||
outputStream.setLevel(Deflater.BEST_COMPRESSION);
|
outputStream.setLevel(Deflater.BEST_COMPRESSION);
|
||||||
try(ZipInputStream input = IOHelper.newZipInput(inputFile))
|
try (ZipInputStream input = IOHelper.newZipInput(inputFile)) {
|
||||||
{
|
|
||||||
ZipEntry e = input.getNextEntry();
|
ZipEntry e = input.getNextEntry();
|
||||||
while (e != null) {
|
while (e != null) {
|
||||||
if (e.isDirectory()) {
|
if (e.isDirectory()) {
|
||||||
|
|
|
@ -1,6 +1,18 @@
|
||||||
package pro.gravit.launchserver.binary.tasks;
|
package pro.gravit.launchserver.binary.tasks;
|
||||||
|
|
||||||
import static pro.gravit.utils.helper.IOHelper.newZipEntry;
|
import org.objectweb.asm.ClassReader;
|
||||||
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
|
import pro.gravit.launcher.AutogenConfig;
|
||||||
|
import pro.gravit.launcher.Launcher;
|
||||||
|
import pro.gravit.launcher.LauncherConfig;
|
||||||
|
import pro.gravit.launcher.serialize.HOutput;
|
||||||
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
import pro.gravit.launchserver.asm.ClassMetadataReader;
|
||||||
|
import pro.gravit.launchserver.binary.BuildContext;
|
||||||
|
import pro.gravit.launchserver.binary.LauncherConfigurator;
|
||||||
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -17,20 +29,7 @@
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
import org.objectweb.asm.ClassReader;
|
import static pro.gravit.utils.helper.IOHelper.newZipEntry;
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.AutogenConfig;
|
|
||||||
import pro.gravit.launcher.Launcher;
|
|
||||||
import pro.gravit.launcher.LauncherConfig;
|
|
||||||
import pro.gravit.launcher.serialize.HOutput;
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
|
||||||
import pro.gravit.launchserver.asm.ClassMetadataReader;
|
|
||||||
import pro.gravit.launchserver.binary.BuildContext;
|
|
||||||
import pro.gravit.launchserver.binary.LauncherConfigurator;
|
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
|
||||||
import pro.gravit.utils.helper.SecurityHelper;
|
|
||||||
|
|
||||||
public class MainBuildTask implements LauncherBuildTask {
|
public class MainBuildTask implements LauncherBuildTask {
|
||||||
private final LaunchServer server;
|
private final LaunchServer server;
|
||||||
|
@ -118,9 +117,9 @@ public String getName() {
|
||||||
public Path process(Path inputJar) throws IOException {
|
public Path process(Path inputJar) throws IOException {
|
||||||
Path outputJar = server.launcherBinary.nextPath("main");
|
Path outputJar = server.launcherBinary.nextPath("main");
|
||||||
try (ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(outputJar))) {
|
try (ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(outputJar))) {
|
||||||
ClassNode cn = new ClassNode();
|
ClassNode cn = new ClassNode();
|
||||||
new ClassReader(IOHelper.getResourceBytes(AutogenConfig.class.getName().replace('.', '/').concat(".class"))).accept(cn, 0);
|
new ClassReader(IOHelper.getResourceBytes(AutogenConfig.class.getName().replace('.', '/').concat(".class"))).accept(cn, 0);
|
||||||
LauncherConfigurator launcherConfigurator = new LauncherConfigurator(cn);
|
LauncherConfigurator launcherConfigurator = new LauncherConfigurator(cn);
|
||||||
BuildContext context = new BuildContext(output, launcherConfigurator, this);
|
BuildContext context = new BuildContext(output, launcherConfigurator, this);
|
||||||
server.buildHookManager.hook(context);
|
server.buildHookManager.hook(context);
|
||||||
launcherConfigurator.setStringField("address", server.config.netty.address);
|
launcherConfigurator.setStringField("address", server.config.netty.address);
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
package pro.gravit.launchserver.binary.tasks;
|
package pro.gravit.launchserver.binary.tasks;
|
||||||
|
|
||||||
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
import pro.gravit.utils.helper.UnpackHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.FileVisitResult;
|
import java.nio.file.FileVisitResult;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
@ -8,11 +13,6 @@
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
|
||||||
import pro.gravit.utils.helper.UnpackHelper;
|
|
||||||
|
|
||||||
public class PrepareBuildTask implements LauncherBuildTask {
|
public class PrepareBuildTask implements LauncherBuildTask {
|
||||||
private final LaunchServer server;
|
private final LaunchServer server;
|
||||||
private final Path result;
|
private final Path result;
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package pro.gravit.launchserver.binary.tasks;
|
package pro.gravit.launchserver.binary.tasks;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
@ -11,6 +8,9 @@
|
||||||
import proguard.ParseException;
|
import proguard.ParseException;
|
||||||
import proguard.ProGuard;
|
import proguard.ProGuard;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public class ProGuardBuildTask implements LauncherBuildTask {
|
public class ProGuardBuildTask implements LauncherBuildTask {
|
||||||
private final LaunchServer server;
|
private final LaunchServer server;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package pro.gravit.launchserver.command;
|
package pro.gravit.launchserver.command;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class Command extends pro.gravit.utils.command.Command {
|
public abstract class Command extends pro.gravit.utils.command.Command {
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package pro.gravit.launchserver.command.auth;
|
package pro.gravit.launchserver.command.auth;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.request.auth.password.AuthPlainPassword;
|
import pro.gravit.launcher.request.auth.password.AuthPlainPassword;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.auth.AuthProviderPair;
|
import pro.gravit.launchserver.auth.AuthProviderPair;
|
||||||
|
@ -10,6 +8,8 @@
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public final class AuthCommand extends Command {
|
public final class AuthCommand extends Command {
|
||||||
public AuthCommand(LaunchServer server) {
|
public AuthCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package pro.gravit.launchserver.command.auth;
|
package pro.gravit.launchserver.command.auth;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.auth.AuthProviderPair;
|
import pro.gravit.launchserver.auth.AuthProviderPair;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
import pro.gravit.utils.command.CommandException;
|
import pro.gravit.utils.command.CommandException;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public final class UUIDToUsernameCommand extends Command {
|
public final class UUIDToUsernameCommand extends Command {
|
||||||
public UUIDToUsernameCommand(LaunchServer server) {
|
public UUIDToUsernameCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package pro.gravit.launchserver.command.auth;
|
package pro.gravit.launchserver.command.auth;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.auth.AuthProviderPair;
|
import pro.gravit.launchserver.auth.AuthProviderPair;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
import pro.gravit.utils.command.CommandException;
|
import pro.gravit.utils.command.CommandException;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public final class UsernameToUUIDCommand extends Command {
|
public final class UsernameToUUIDCommand extends Command {
|
||||||
public UsernameToUUIDCommand(LaunchServer server) {
|
public UsernameToUUIDCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package pro.gravit.launchserver.command.basic;
|
package pro.gravit.launchserver.command.basic;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
public class ProguardCleanCommand extends Command {
|
public class ProguardCleanCommand extends Command {
|
||||||
public ProguardCleanCommand(LaunchServer server) {
|
public ProguardCleanCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package pro.gravit.launchserver.command.basic;
|
package pro.gravit.launchserver.command.basic;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class RegenProguardDictCommand extends Command {
|
public class RegenProguardDictCommand extends Command {
|
||||||
|
|
||||||
public RegenProguardDictCommand(LaunchServer server) {
|
public RegenProguardDictCommand(LaunchServer server) {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package pro.gravit.launchserver.command.basic;
|
package pro.gravit.launchserver.command.basic;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
public class RemoveMappingsProguardCommand extends Command {
|
public class RemoveMappingsProguardCommand extends Command {
|
||||||
|
|
||||||
public RemoveMappingsProguardCommand(LaunchServer server) {
|
public RemoveMappingsProguardCommand(LaunchServer server) {
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
package pro.gravit.launchserver.command.basic;
|
package pro.gravit.launchserver.command.basic;
|
||||||
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.security.KeyPair;
|
|
||||||
|
|
||||||
import org.bouncycastle.cert.X509CertificateHolder;
|
import org.bouncycastle.cert.X509CertificateHolder;
|
||||||
|
|
||||||
import pro.gravit.launcher.hwid.HWIDCheckHelper;
|
import pro.gravit.launcher.hwid.HWIDCheckHelper;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
|
@ -12,6 +8,9 @@
|
||||||
import pro.gravit.utils.helper.CommonHelper;
|
import pro.gravit.utils.helper.CommonHelper;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.security.KeyPair;
|
||||||
|
|
||||||
public class TestCommand extends Command {
|
public class TestCommand extends Command {
|
||||||
public TestCommand(LaunchServer server) {
|
public TestCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
@ -40,16 +39,16 @@ public void invoke(String... args) throws Exception {
|
||||||
if (args[0].equals("stop")) {
|
if (args[0].equals("stop")) {
|
||||||
handler.close();
|
handler.close();
|
||||||
}
|
}
|
||||||
if(args[0].equals("genCA")) {
|
if (args[0].equals("genCA")) {
|
||||||
server.certificateManager.generateCA();
|
server.certificateManager.generateCA();
|
||||||
server.certificateManager.writePrivateKey(Paths.get("ca.key"), server.certificateManager.caKey);
|
server.certificateManager.writePrivateKey(Paths.get("ca.key"), server.certificateManager.caKey);
|
||||||
server.certificateManager.writeCertificate(Paths.get("ca.crt"), server.certificateManager.ca);
|
server.certificateManager.writeCertificate(Paths.get("ca.crt"), server.certificateManager.ca);
|
||||||
}
|
}
|
||||||
if(args[0].equals("readCA")) {
|
if (args[0].equals("readCA")) {
|
||||||
server.certificateManager.ca = server.certificateManager.readCertificate(Paths.get("ca.crt"));
|
server.certificateManager.ca = server.certificateManager.readCertificate(Paths.get("ca.crt"));
|
||||||
server.certificateManager.caKey = server.certificateManager.readPrivateKey(Paths.get("ca.key"));
|
server.certificateManager.caKey = server.certificateManager.readPrivateKey(Paths.get("ca.key"));
|
||||||
}
|
}
|
||||||
if(args[0].equals("genCert")) {
|
if (args[0].equals("genCert")) {
|
||||||
verifyArgs(args, 2);
|
verifyArgs(args, 2);
|
||||||
String name = args[1];
|
String name = args[1];
|
||||||
KeyPair pair = server.certificateManager.generateKeyPair();
|
KeyPair pair = server.certificateManager.generateKeyPair();
|
||||||
|
@ -57,8 +56,7 @@ public void invoke(String... args) throws Exception {
|
||||||
server.certificateManager.writePrivateKey(Paths.get(name.concat(".key")), pair.getPrivate());
|
server.certificateManager.writePrivateKey(Paths.get(name.concat(".key")), pair.getPrivate());
|
||||||
server.certificateManager.writeCertificate(Paths.get(name.concat(".crt")), cert);
|
server.certificateManager.writeCertificate(Paths.get(name.concat(".crt")), cert);
|
||||||
}
|
}
|
||||||
if(args[0].equals("hwidcheck"))
|
if (args[0].equals("hwidcheck")) {
|
||||||
{
|
|
||||||
LogHelper.info("HWID String %s bad rating %d", args[1], HWIDCheckHelper.checkString(args[1]));
|
LogHelper.info("HWID String %s bad rating %d", args[1], HWIDCheckHelper.checkString(args[1]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,7 @@ public String getUsageDescription() {
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) {
|
public void invoke(String... args) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for(User user : server.config.dao.userService.findAllUsers())
|
for (User user : server.config.dao.userService.findAllUsers()) {
|
||||||
{
|
|
||||||
LogHelper.subInfo("[%s] UUID: %s", user.username, user.uuid.toString());
|
LogHelper.subInfo("[%s] UUID: %s", user.username, user.uuid.toString());
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,7 @@ public String getUsageDescription() {
|
||||||
public void invoke(String... args) throws Exception {
|
public void invoke(String... args) throws Exception {
|
||||||
verifyArgs(args, 1);
|
verifyArgs(args, 1);
|
||||||
User user = server.config.dao.userService.findUserByUsername(args[0]);
|
User user = server.config.dao.userService.findUserByUsername(args[0]);
|
||||||
if(user == null)
|
if (user == null) {
|
||||||
{
|
|
||||||
LogHelper.error("User %s not found", args[0]);
|
LogHelper.error("User %s not found", args[0]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package pro.gravit.launchserver.command.dao;
|
package pro.gravit.launchserver.command.dao;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
import pro.gravit.launchserver.dao.User;
|
import pro.gravit.launchserver.dao.User;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class RegisterCommand extends Command {
|
public class RegisterCommand extends Command {
|
||||||
public RegisterCommand(LaunchServer server) {
|
public RegisterCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
|
|
@ -25,8 +25,7 @@ public String getUsageDescription() {
|
||||||
public void invoke(String... args) throws Exception {
|
public void invoke(String... args) throws Exception {
|
||||||
verifyArgs(args, 2);
|
verifyArgs(args, 2);
|
||||||
User user = server.config.dao.userService.findUserByUsername(args[0]);
|
User user = server.config.dao.userService.findUserByUsername(args[0]);
|
||||||
if(user == null)
|
if (user == null) {
|
||||||
{
|
|
||||||
LogHelper.error("User %s not found", args[1]);
|
LogHelper.error("User %s not found", args[1]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
package pro.gravit.launchserver.command.dump;
|
package pro.gravit.launchserver.command.dump;
|
||||||
|
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import pro.gravit.launcher.Launcher;
|
||||||
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
import pro.gravit.launchserver.command.Command;
|
||||||
|
import pro.gravit.launchserver.socket.Client;
|
||||||
|
import pro.gravit.utils.command.SubCommand;
|
||||||
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
@ -8,16 +17,6 @@
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import com.google.gson.reflect.TypeToken;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.Launcher;
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
|
||||||
import pro.gravit.launchserver.command.Command;
|
|
||||||
import pro.gravit.launchserver.socket.Client;
|
|
||||||
import pro.gravit.utils.command.SubCommand;
|
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
public class DumpSessionsCommand extends Command {
|
public class DumpSessionsCommand extends Command {
|
||||||
public DumpSessionsCommand(LaunchServer server) {
|
public DumpSessionsCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
|
|
@ -4,37 +4,18 @@
|
||||||
import pro.gravit.launchserver.command.auth.AuthCommand;
|
import pro.gravit.launchserver.command.auth.AuthCommand;
|
||||||
import pro.gravit.launchserver.command.auth.UUIDToUsernameCommand;
|
import pro.gravit.launchserver.command.auth.UUIDToUsernameCommand;
|
||||||
import pro.gravit.launchserver.command.auth.UsernameToUUIDCommand;
|
import pro.gravit.launchserver.command.auth.UsernameToUUIDCommand;
|
||||||
import pro.gravit.launchserver.command.basic.BuildCommand;
|
import pro.gravit.launchserver.command.basic.*;
|
||||||
import pro.gravit.launchserver.command.basic.ProguardCleanCommand;
|
|
||||||
import pro.gravit.launchserver.command.basic.RegenProguardDictCommand;
|
|
||||||
import pro.gravit.launchserver.command.basic.RemoveMappingsProguardCommand;
|
|
||||||
import pro.gravit.launchserver.command.basic.RestartCommand;
|
|
||||||
import pro.gravit.launchserver.command.basic.StopCommand;
|
|
||||||
import pro.gravit.launchserver.command.basic.TestCommand;
|
|
||||||
import pro.gravit.launchserver.command.basic.VersionCommand;
|
|
||||||
import pro.gravit.launchserver.command.dao.GetAllUsersCommand;
|
import pro.gravit.launchserver.command.dao.GetAllUsersCommand;
|
||||||
import pro.gravit.launchserver.command.dao.GetUserCommand;
|
import pro.gravit.launchserver.command.dao.GetUserCommand;
|
||||||
import pro.gravit.launchserver.command.dao.RegisterCommand;
|
import pro.gravit.launchserver.command.dao.RegisterCommand;
|
||||||
import pro.gravit.launchserver.command.dao.SetUserPasswordCommand;
|
import pro.gravit.launchserver.command.dao.SetUserPasswordCommand;
|
||||||
import pro.gravit.launchserver.command.dump.DumpSessionsCommand;
|
import pro.gravit.launchserver.command.dump.DumpSessionsCommand;
|
||||||
import pro.gravit.launchserver.command.hash.DownloadAssetCommand;
|
import pro.gravit.launchserver.command.hash.*;
|
||||||
import pro.gravit.launchserver.command.hash.DownloadClientCommand;
|
|
||||||
import pro.gravit.launchserver.command.hash.IndexAssetCommand;
|
|
||||||
import pro.gravit.launchserver.command.hash.SyncBinariesCommand;
|
|
||||||
import pro.gravit.launchserver.command.hash.SyncProfilesCommand;
|
|
||||||
import pro.gravit.launchserver.command.hash.SyncUpdatesCommand;
|
|
||||||
import pro.gravit.launchserver.command.hash.UnindexAssetCommand;
|
|
||||||
import pro.gravit.launchserver.command.install.CheckInstallCommand;
|
import pro.gravit.launchserver.command.install.CheckInstallCommand;
|
||||||
import pro.gravit.launchserver.command.install.MultiCommand;
|
import pro.gravit.launchserver.command.install.MultiCommand;
|
||||||
import pro.gravit.launchserver.command.modules.LoadModuleCommand;
|
import pro.gravit.launchserver.command.modules.LoadModuleCommand;
|
||||||
import pro.gravit.launchserver.command.modules.ModulesCommand;
|
import pro.gravit.launchserver.command.modules.ModulesCommand;
|
||||||
import pro.gravit.launchserver.command.service.ClientsCommand;
|
import pro.gravit.launchserver.command.service.*;
|
||||||
import pro.gravit.launchserver.command.service.ComponentCommand;
|
|
||||||
import pro.gravit.launchserver.command.service.ConfigCommand;
|
|
||||||
import pro.gravit.launchserver.command.service.GetModulusCommand;
|
|
||||||
import pro.gravit.launchserver.command.service.GetPermissionsCommand;
|
|
||||||
import pro.gravit.launchserver.command.service.GivePermissionsCommand;
|
|
||||||
import pro.gravit.launchserver.command.service.ServerStatusCommand;
|
|
||||||
import pro.gravit.utils.command.BaseCommandCategory;
|
import pro.gravit.utils.command.BaseCommandCategory;
|
||||||
import pro.gravit.utils.command.basic.ClearCommand;
|
import pro.gravit.utils.command.basic.ClearCommand;
|
||||||
import pro.gravit.utils.command.basic.DebugCommand;
|
import pro.gravit.utils.command.basic.DebugCommand;
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package pro.gravit.launchserver.command.hash;
|
package pro.gravit.launchserver.command.hash;
|
||||||
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
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.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
public final class DownloadAssetCommand extends Command {
|
public final class DownloadAssetCommand extends Command {
|
||||||
|
|
||||||
public DownloadAssetCommand(LaunchServer server) {
|
public DownloadAssetCommand(LaunchServer server) {
|
||||||
|
@ -40,7 +40,7 @@ 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);
|
server.mirrorManager.downloadZip(assetDir, "assets/%s.zip", versionName);
|
||||||
|
|
||||||
// Finished
|
// Finished
|
||||||
server.syncUpdatesDir(Collections.singleton(dirName));
|
server.syncUpdatesDir(Collections.singleton(dirName));
|
||||||
|
|
|
@ -1,12 +1,5 @@
|
||||||
package pro.gravit.launchserver.command.hash;
|
package pro.gravit.launchserver.command.hash;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
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;
|
||||||
|
@ -16,6 +9,13 @@
|
||||||
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.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
public final class DownloadClientCommand extends Command {
|
public final class DownloadClientCommand extends Command {
|
||||||
|
|
||||||
public DownloadClientCommand(LaunchServer server) {
|
public DownloadClientCommand(LaunchServer server) {
|
||||||
|
@ -47,7 +47,7 @@ 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);
|
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);
|
||||||
|
@ -55,8 +55,7 @@ public void invoke(String... args) throws IOException, CommandException {
|
||||||
String profilePath = String.format("pro/gravit/launchserver/defaults/profile%s.cfg", versionName);
|
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)
|
} catch (IOException e) {
|
||||||
{
|
|
||||||
JsonElement clientJson = server.mirrorManager.jsonRequest(null, "GET", "clients/%s.json", versionName);
|
JsonElement clientJson = server.mirrorManager.jsonRequest(null, "GET", "clients/%s.json", versionName);
|
||||||
client = Launcher.gsonManager.configGson.fromJson(clientJson, ClientProfile.class);
|
client = Launcher.gsonManager.configGson.fromJson(clientJson, ClientProfile.class);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,15 @@
|
||||||
package pro.gravit.launchserver.command.hash;
|
package pro.gravit.launchserver.command.hash;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
import pro.gravit.launchserver.command.Command;
|
||||||
|
import pro.gravit.utils.command.CommandException;
|
||||||
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
|
import pro.gravit.utils.helper.SecurityHelper.DigestAlgorithm;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.FileVisitResult;
|
import java.nio.file.FileVisitResult;
|
||||||
|
@ -9,17 +19,6 @@
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
|
||||||
import pro.gravit.launchserver.command.Command;
|
|
||||||
import pro.gravit.utils.command.CommandException;
|
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
|
||||||
import pro.gravit.utils.helper.SecurityHelper;
|
|
||||||
import pro.gravit.utils.helper.SecurityHelper.DigestAlgorithm;
|
|
||||||
|
|
||||||
public final class IndexAssetCommand extends Command {
|
public final class IndexAssetCommand extends Command {
|
||||||
private static final Gson gson = new Gson();
|
private static final Gson gson = new Gson();
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package pro.gravit.launchserver.command.hash;
|
package pro.gravit.launchserver.command.hash;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public final class SyncBinariesCommand extends Command {
|
public final class SyncBinariesCommand extends Command {
|
||||||
public SyncBinariesCommand(LaunchServer server) {
|
public SyncBinariesCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package pro.gravit.launchserver.command.hash;
|
package pro.gravit.launchserver.command.hash;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public final class SyncProfilesCommand extends Command {
|
public final class SyncProfilesCommand extends Command {
|
||||||
public SyncProfilesCommand(LaunchServer server) {
|
public SyncProfilesCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package pro.gravit.launchserver.command.hash;
|
package pro.gravit.launchserver.command.hash;
|
||||||
|
|
||||||
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
import pro.gravit.launchserver.command.Command;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
|
||||||
import pro.gravit.launchserver.command.Command;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
public final class SyncUpdatesCommand extends Command {
|
public final class SyncUpdatesCommand extends Command {
|
||||||
public SyncUpdatesCommand(LaunchServer server) {
|
public SyncUpdatesCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
|
|
@ -1,21 +1,20 @@
|
||||||
package pro.gravit.launchserver.command.hash;
|
package pro.gravit.launchserver.command.hash;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
import pro.gravit.launchserver.command.Command;
|
||||||
|
import pro.gravit.utils.command.CommandException;
|
||||||
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
|
||||||
import pro.gravit.launchserver.command.Command;
|
|
||||||
import pro.gravit.utils.command.CommandException;
|
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
public final class UnindexAssetCommand extends Command {
|
public final class UnindexAssetCommand extends Command {
|
||||||
private static final JsonParser parser = new JsonParser();
|
private static final JsonParser parser = new JsonParser();
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package pro.gravit.launchserver.command.modules;
|
package pro.gravit.launchserver.command.modules;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.command.Command;
|
import pro.gravit.launchserver.command.Command;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
public class LoadModuleCommand extends Command {
|
public class LoadModuleCommand extends Command {
|
||||||
public LoadModuleCommand(LaunchServer server) {
|
public LoadModuleCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
|
|
@ -30,13 +30,12 @@ public void invoke(String... args) {
|
||||||
WebSocketFrameHandler frameHandler = channel.pipeline().get(WebSocketFrameHandler.class);
|
WebSocketFrameHandler frameHandler = channel.pipeline().get(WebSocketFrameHandler.class);
|
||||||
Client client = frameHandler.getClient();
|
Client client = frameHandler.getClient();
|
||||||
String ip = IOHelper.getIP(channel.remoteAddress());
|
String ip = IOHelper.getIP(channel.remoteAddress());
|
||||||
if(!client.isAuth)
|
if (!client.isAuth)
|
||||||
LogHelper.info("Channel %s | checkSign %s", ip, client.checkSign ? "true" : "false");
|
LogHelper.info("Channel %s | checkSign %s", ip, client.checkSign ? "true" : "false");
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
LogHelper.info("Client name %s | ip %s", client.username == null ? "null" : client.username, ip);
|
LogHelper.info("Client name %s | ip %s", client.username == null ? "null" : client.username, ip);
|
||||||
LogHelper.subInfo("Data: checkSign %s | isSecure %s | auth_id %s", client.checkSign ? "true" : "false", client.isSecure ? "true" : "false",
|
LogHelper.subInfo("Data: checkSign %s | isSecure %s | auth_id %s", client.checkSign ? "true" : "false", client.isSecure ? "true" : "false",
|
||||||
client.auth_id);
|
client.auth_id);
|
||||||
LogHelper.subInfo("Permissions: %s (long %d)", client.permissions == null ? "null" : client.permissions.toString(), client.permissions == null ? 0 : client.permissions.toLong());
|
LogHelper.subInfo("Permissions: %s (long %d)", client.permissions == null ? "null" : client.permissions.toString(), client.permissions == null ? 0 : client.permissions.toLong());
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package pro.gravit.launchserver.command.service;
|
package pro.gravit.launchserver.command.service;
|
||||||
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.Launcher;
|
import pro.gravit.launcher.Launcher;
|
||||||
import pro.gravit.launcher.NeedGarbageCollection;
|
import pro.gravit.launcher.NeedGarbageCollection;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
|
@ -11,6 +8,9 @@
|
||||||
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.Reader;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
public class ComponentCommand extends Command {
|
public class ComponentCommand extends Command {
|
||||||
public ComponentCommand(LaunchServer server) {
|
public ComponentCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
package pro.gravit.launchserver.components;
|
package pro.gravit.launchserver.components;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.NeedGarbageCollection;
|
import pro.gravit.launcher.NeedGarbageCollection;
|
||||||
import pro.gravit.launchserver.Reconfigurable;
|
import pro.gravit.launchserver.Reconfigurable;
|
||||||
import pro.gravit.utils.command.Command;
|
import pro.gravit.utils.command.Command;
|
||||||
import pro.gravit.utils.command.SubCommand;
|
import pro.gravit.utils.command.SubCommand;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class AbstractLimiter<T> extends Component implements NeedGarbageCollection, Reconfigurable {
|
public abstract class AbstractLimiter<T> extends Component implements NeedGarbageCollection, Reconfigurable {
|
||||||
public int rateLimit;
|
public int rateLimit;
|
||||||
public int rateLimitMillis;
|
public int rateLimitMillis;
|
||||||
|
@ -67,8 +67,7 @@ public void garbageCollection() {
|
||||||
map.entrySet().removeIf((e) -> e.getValue().time + rateLimitMillis < time);
|
map.entrySet().removeIf((e) -> e.getValue().time + rateLimitMillis < time);
|
||||||
}
|
}
|
||||||
|
|
||||||
static class LimitEntry
|
static class LimitEntry {
|
||||||
{
|
|
||||||
long time;
|
long time;
|
||||||
int trys;
|
int trys;
|
||||||
|
|
||||||
|
@ -82,27 +81,23 @@ public LimitEntry() {
|
||||||
trys = 0;
|
trys = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final transient Map<T, LimitEntry> map = new HashMap<>();
|
protected final transient Map<T, LimitEntry> map = new HashMap<>();
|
||||||
public boolean check(T address)
|
|
||||||
{
|
public boolean check(T address) {
|
||||||
if(exclude.contains(address)) return true;
|
if (exclude.contains(address)) return true;
|
||||||
LimitEntry entry = map.get(address);
|
LimitEntry entry = map.get(address);
|
||||||
if(entry == null)
|
if (entry == null) {
|
||||||
{
|
|
||||||
map.put(address, new LimitEntry());
|
map.put(address, new LimitEntry());
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
if(entry.trys < rateLimit)
|
if (entry.trys < rateLimit) {
|
||||||
{
|
|
||||||
entry.trys++;
|
entry.trys++;
|
||||||
entry.time = time;
|
entry.time = time;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(entry.time + rateLimitMillis < time)
|
if (entry.time + rateLimitMillis < time) {
|
||||||
{
|
|
||||||
entry.trys = 1;
|
entry.trys = 1;
|
||||||
entry.time = time;
|
entry.time = time;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -7,10 +7,11 @@
|
||||||
import pro.gravit.utils.HookException;
|
import pro.gravit.utils.HookException;
|
||||||
|
|
||||||
public class AuthLimiterComponent extends IPLimiter implements NeedGarbageCollection, AutoCloseable {
|
public class AuthLimiterComponent extends IPLimiter implements NeedGarbageCollection, AutoCloseable {
|
||||||
private transient LaunchServer srv;
|
private transient LaunchServer srv;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preInit(LaunchServer launchServer) {
|
public void preInit(LaunchServer launchServer) {
|
||||||
srv = launchServer;
|
srv = launchServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -29,10 +30,11 @@ public boolean preAuthHook(AuthResponse.AuthContext context, Client client) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String message;
|
public String message;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
srv.authHookManager.preHook.unregisterHook(this::preAuthHook);
|
srv.authHookManager.preHook.unregisterHook(this::preAuthHook);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package pro.gravit.launchserver.components;
|
package pro.gravit.launchserver.components;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.utils.command.Command;
|
import pro.gravit.utils.command.Command;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class CommandRemoverComponent extends Component implements AutoCloseable {
|
public class CommandRemoverComponent extends Component implements AutoCloseable {
|
||||||
public final String[] removeList = new String[]{};
|
public final String[] removeList = new String[]{};
|
||||||
public final transient Map<String, Command> commandsList = new HashMap<>();
|
public final transient Map<String, Command> commandsList = new HashMap<>();
|
||||||
|
@ -13,7 +13,7 @@ public class CommandRemoverComponent extends Component implements AutoCloseable
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preInit(LaunchServer launchServer) {
|
public void preInit(LaunchServer launchServer) {
|
||||||
server = launchServer;
|
server = launchServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package pro.gravit.launchserver.components;
|
package pro.gravit.launchserver.components;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.NeedGarbageCollection;
|
import pro.gravit.launcher.NeedGarbageCollection;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.manangers.hook.AuthHookManager;
|
import pro.gravit.launchserver.manangers.hook.AuthHookManager;
|
||||||
import pro.gravit.utils.HookException;
|
import pro.gravit.utils.HookException;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class RegLimiterComponent extends IPLimiter implements NeedGarbageCollection, AutoCloseable {
|
public class RegLimiterComponent extends IPLimiter implements NeedGarbageCollection, AutoCloseable {
|
||||||
|
|
||||||
public transient LaunchServer launchServer;
|
public transient LaunchServer launchServer;
|
||||||
|
@ -30,8 +30,7 @@ public void postInit(LaunchServer launchServer) {
|
||||||
launchServer.authHookManager.registraion.registerHook(this::registerHook);
|
launchServer.authHookManager.registraion.registerHook(this::registerHook);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean registerHook(AuthHookManager.RegContext context)
|
public boolean registerHook(AuthHookManager.RegContext context) {
|
||||||
{
|
|
||||||
if (!check(context.ip)) {
|
if (!check(context.ip)) {
|
||||||
throw new HookException(message);
|
throw new HookException(message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
package pro.gravit.launchserver.config;
|
package pro.gravit.launchserver.config;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import io.netty.channel.epoll.Epoll;
|
import io.netty.channel.epoll.Epoll;
|
||||||
import io.netty.handler.logging.LogLevel;
|
import io.netty.handler.logging.LogLevel;
|
||||||
import pro.gravit.launcher.Launcher;
|
import pro.gravit.launcher.Launcher;
|
||||||
|
@ -30,6 +24,12 @@
|
||||||
import pro.gravit.utils.helper.JVMHelper;
|
import pro.gravit.utils.helper.JVMHelper;
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public final class LaunchServerConfig {
|
public final class LaunchServerConfig {
|
||||||
private transient LaunchServer server = null;
|
private transient LaunchServer server = null;
|
||||||
|
|
||||||
|
@ -139,19 +139,17 @@ public void init(LaunchServer.ReloadType type) {
|
||||||
}
|
}
|
||||||
permissionsHandler.init(server);
|
permissionsHandler.init(server);
|
||||||
hwidHandler.init();
|
hwidHandler.init();
|
||||||
if(dao != null)
|
if (dao != null)
|
||||||
dao.init(server);
|
dao.init(server);
|
||||||
if (protectHandler != null) {
|
if (protectHandler != null) {
|
||||||
protectHandler.checkLaunchServerLicense();
|
protectHandler.checkLaunchServerLicense();
|
||||||
}
|
}
|
||||||
if(components != null)
|
if (components != null) {
|
||||||
{
|
components.forEach((k, v) -> server.registerObject("component.".concat(k), v));
|
||||||
components.forEach((k,v) -> server.registerObject("component.".concat(k), v));
|
|
||||||
}
|
}
|
||||||
server.registerObject("permissionsHandler", permissionsHandler);
|
server.registerObject("permissionsHandler", permissionsHandler);
|
||||||
server.registerObject("hwidHandler", hwidHandler);
|
server.registerObject("hwidHandler", hwidHandler);
|
||||||
if(!type.equals(LaunchServer.ReloadType.NO_AUTH))
|
if (!type.equals(LaunchServer.ReloadType.NO_AUTH)) {
|
||||||
{
|
|
||||||
for (AuthProviderPair pair : auth) {
|
for (AuthProviderPair pair : auth) {
|
||||||
server.registerObject("auth.".concat(pair.name).concat(".provider"), pair.provider);
|
server.registerObject("auth.".concat(pair.name).concat(".provider"), pair.provider);
|
||||||
server.registerObject("auth.".concat(pair.name).concat(".handler"), pair.handler);
|
server.registerObject("auth.".concat(pair.name).concat(".handler"), pair.handler);
|
||||||
|
@ -167,20 +165,17 @@ public void close(LaunchServer.ReloadType type) {
|
||||||
try {
|
try {
|
||||||
server.unregisterObject("permissionsHandler", permissionsHandler);
|
server.unregisterObject("permissionsHandler", permissionsHandler);
|
||||||
server.unregisterObject("hwidHandler", hwidHandler);
|
server.unregisterObject("hwidHandler", hwidHandler);
|
||||||
if(!type.equals(LaunchServer.ReloadType.NO_AUTH))
|
if (!type.equals(LaunchServer.ReloadType.NO_AUTH)) {
|
||||||
{
|
|
||||||
for (AuthProviderPair pair : auth) {
|
for (AuthProviderPair pair : auth) {
|
||||||
server.unregisterObject("auth.".concat(pair.name).concat(".provider"), pair.provider);
|
server.unregisterObject("auth.".concat(pair.name).concat(".provider"), pair.provider);
|
||||||
server.unregisterObject("auth.".concat(pair.name).concat(".handler"), pair.handler);
|
server.unregisterObject("auth.".concat(pair.name).concat(".handler"), pair.handler);
|
||||||
server.unregisterObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider);
|
server.unregisterObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(type.equals(LaunchServer.ReloadType.FULL))
|
if (type.equals(LaunchServer.ReloadType.FULL)) {
|
||||||
{
|
|
||||||
components.forEach((k, component) -> {
|
components.forEach((k, component) -> {
|
||||||
server.unregisterObject("component.".concat(k), component);
|
server.unregisterObject("component.".concat(k), component);
|
||||||
if(component instanceof AutoCloseable)
|
if (component instanceof AutoCloseable) {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
((AutoCloseable) component).close();
|
((AutoCloseable) component).close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -226,8 +221,7 @@ public static class ExeConf {
|
||||||
public String txtProductVersion;
|
public String txtProductVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CertificateConf
|
public static class CertificateConf {
|
||||||
{
|
|
||||||
public boolean enabled;
|
public boolean enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,6 +229,7 @@ public static class NettyUpdatesBind {
|
||||||
public String url;
|
public String url;
|
||||||
public boolean zip;
|
public boolean zip;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class LauncherConf {
|
public static class LauncherConf {
|
||||||
public String guardType;
|
public String guardType;
|
||||||
public boolean attachLibraryBeforeProGuard;
|
public boolean attachLibraryBeforeProGuard;
|
||||||
|
@ -276,8 +271,8 @@ public NettyBindAddress(String address, int port) {
|
||||||
this.port = port;
|
this.port = port;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env)
|
|
||||||
{
|
public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) {
|
||||||
LaunchServerConfig newConfig = new LaunchServerConfig();
|
LaunchServerConfig newConfig = new LaunchServerConfig();
|
||||||
newConfig.mirrors = new String[]{"https://mirror.gravit.pro/"};
|
newConfig.mirrors = new String[]{"https://mirror.gravit.pro/"};
|
||||||
newConfig.launch4j = new LaunchServerConfig.ExeConf();
|
newConfig.launch4j = new LaunchServerConfig.ExeConf();
|
||||||
|
@ -302,7 +297,7 @@ public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env)
|
||||||
, "std")};
|
, "std")};
|
||||||
newConfig.auth[0].displayName = "Default";
|
newConfig.auth[0].displayName = "Default";
|
||||||
newConfig.protectHandler = new StdProtectHandler();
|
newConfig.protectHandler = new StdProtectHandler();
|
||||||
if(env.equals(LaunchServer.LaunchServerEnv.TEST))
|
if (env.equals(LaunchServer.LaunchServerEnv.TEST))
|
||||||
newConfig.permissionsHandler = new DefaultPermissionsHandler();
|
newConfig.permissionsHandler = new DefaultPermissionsHandler();
|
||||||
else
|
else
|
||||||
newConfig.permissionsHandler = new JsonFilePermissionsHandler();
|
newConfig.permissionsHandler = new JsonFilePermissionsHandler();
|
||||||
|
|
|
@ -11,7 +11,10 @@ public class LaunchServerRuntimeConfig {
|
||||||
|
|
||||||
public void verify() {
|
public void verify() {
|
||||||
if (passwordEncryptKey == null) LogHelper.error("[RuntimeConfig] passwordEncryptKey must not be null");
|
if (passwordEncryptKey == null) LogHelper.error("[RuntimeConfig] passwordEncryptKey must not be null");
|
||||||
if (clientCheckSecret == null) { LogHelper.warning("[RuntimeConfig] clientCheckSecret must not be null"); clientCheckSecret = SecurityHelper.randomStringToken(); }
|
if (clientCheckSecret == null) {
|
||||||
|
LogHelper.warning("[RuntimeConfig] clientCheckSecret must not be null");
|
||||||
|
clientCheckSecret = SecurityHelper.randomStringToken();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
|
|
|
@ -1,22 +1,16 @@
|
||||||
package pro.gravit.launchserver.dao;
|
package pro.gravit.launchserver.dao;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.ClientPermissions;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.GenerationType;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.ClientPermissions;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
|
||||||
import pro.gravit.utils.helper.SecurityHelper;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "users")
|
@Table(name = "users")
|
||||||
public class User {
|
public class User {
|
||||||
|
@ -34,8 +28,8 @@ public class User {
|
||||||
public String serverID;
|
public String serverID;
|
||||||
private String password_salt;
|
private String password_salt;
|
||||||
public long permissions;
|
public long permissions;
|
||||||
public void setPassword(String password)
|
|
||||||
{
|
public void setPassword(String password) {
|
||||||
password_salt = SecurityHelper.randomStringAESKey();
|
password_salt = SecurityHelper.randomStringAESKey();
|
||||||
MessageDigest digest;
|
MessageDigest digest;
|
||||||
try {
|
try {
|
||||||
|
@ -46,8 +40,8 @@ public void setPassword(String password)
|
||||||
}
|
}
|
||||||
this.password = digest.digest(password.concat(password_salt).getBytes(StandardCharsets.UTF_8));
|
this.password = digest.digest(password.concat(password_salt).getBytes(StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
public boolean verifyPassword(String password)
|
|
||||||
{
|
public boolean verifyPassword(String password) {
|
||||||
MessageDigest digest;
|
MessageDigest digest;
|
||||||
try {
|
try {
|
||||||
digest = MessageDigest.getInstance("SHA-256");
|
digest = MessageDigest.getInstance("SHA-256");
|
||||||
|
@ -58,12 +52,12 @@ public boolean verifyPassword(String password)
|
||||||
byte[] enpassword = digest.digest(password.concat(password_salt).getBytes(StandardCharsets.UTF_8));
|
byte[] enpassword = digest.digest(password.concat(password_salt).getBytes(StandardCharsets.UTF_8));
|
||||||
return Arrays.equals(enpassword, this.password);
|
return Arrays.equals(enpassword, this.password);
|
||||||
}
|
}
|
||||||
public ClientPermissions getPermissions()
|
|
||||||
{
|
public ClientPermissions getPermissions() {
|
||||||
return new ClientPermissions(permissions);
|
return new ClientPermissions(permissions);
|
||||||
}
|
}
|
||||||
public void setPermissions(ClientPermissions permissions)
|
|
||||||
{
|
public void setPermissions(ClientPermissions permissions) {
|
||||||
this.permissions = permissions.toLong();
|
this.permissions = permissions.toLong();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,24 @@
|
||||||
package pro.gravit.launchserver.dao;
|
package pro.gravit.launchserver.dao;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.hwid.OshiHWID;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import pro.gravit.launcher.hwid.OshiHWID;
|
|
||||||
|
|
||||||
public interface UserDAO {
|
public interface UserDAO {
|
||||||
User findById(int id);
|
User findById(int id);
|
||||||
|
|
||||||
User findByUsername(String username);
|
User findByUsername(String username);
|
||||||
|
|
||||||
User findByUUID(UUID uuid);
|
User findByUUID(UUID uuid);
|
||||||
|
|
||||||
List<UserHWID> findHWID(OshiHWID hwid);
|
List<UserHWID> findHWID(OshiHWID hwid);
|
||||||
|
|
||||||
void save(User user);
|
void save(User user);
|
||||||
|
|
||||||
void update(User user);
|
void update(User user);
|
||||||
|
|
||||||
void delete(User user);
|
void delete(User user);
|
||||||
|
|
||||||
List<User> findAll();
|
List<User> findAll();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,11 @@
|
||||||
package pro.gravit.launchserver.dao;
|
package pro.gravit.launchserver.dao;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.GenerationType;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.hwid.HWID;
|
import pro.gravit.launcher.hwid.HWID;
|
||||||
import pro.gravit.launcher.hwid.OshiHWID;
|
import pro.gravit.launcher.hwid.OshiHWID;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "users_hwids")
|
@Table(name = "users_hwids")
|
||||||
public class UserHWID implements HWID {
|
public class UserHWID implements HWID {
|
||||||
|
@ -35,9 +30,9 @@ public class UserHWID implements HWID {
|
||||||
public String macAddr;
|
public String macAddr;
|
||||||
|
|
||||||
public boolean banned;
|
public boolean banned;
|
||||||
public OshiHWID toHWID()
|
|
||||||
{
|
public OshiHWID toHWID() {
|
||||||
if(oshi == null) oshi = oshiSupp.get();
|
if (oshi == null) oshi = oshiSupp.get();
|
||||||
return oshi;
|
return oshi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,12 +18,12 @@ public User findUser(int id) {
|
||||||
public User findUserByUsername(String username) {
|
public User findUserByUsername(String username) {
|
||||||
return usersDao.findByUsername(username);
|
return usersDao.findByUsername(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
public User findUserByUUID(UUID uuid) {
|
public User findUserByUUID(UUID uuid) {
|
||||||
return usersDao.findByUUID(uuid);
|
return usersDao.findByUUID(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public User registerNewUser(String username, String password)
|
public User registerNewUser(String username, String password) {
|
||||||
{
|
|
||||||
User user = new User();
|
User user = new User();
|
||||||
user.username = username;
|
user.username = username;
|
||||||
user.setPassword(password);
|
user.setPassword(password);
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
package pro.gravit.launchserver.dao.impl;
|
package pro.gravit.launchserver.dao.impl;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import pro.gravit.launcher.hwid.OshiHWID;
|
import pro.gravit.launcher.hwid.OshiHWID;
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.dao.User;
|
import pro.gravit.launchserver.dao.User;
|
||||||
import pro.gravit.launchserver.dao.UserDAO;
|
import pro.gravit.launchserver.dao.UserDAO;
|
||||||
import pro.gravit.launchserver.dao.UserHWID;
|
import pro.gravit.launchserver.dao.UserHWID;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class DefaultUserDAOImpl implements UserDAO {
|
public class DefaultUserDAOImpl implements UserDAO {
|
||||||
public DefaultUserDAOImpl(LaunchServer srv) { }
|
public DefaultUserDAOImpl(LaunchServer srv) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User findById(int id) {
|
public User findById(int id) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -1,32 +1,30 @@
|
||||||
package pro.gravit.launchserver.dao.impl;
|
package pro.gravit.launchserver.dao.impl;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
|
||||||
import javax.persistence.criteria.Root;
|
|
||||||
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
|
|
||||||
import pro.gravit.launcher.hwid.OshiHWID;
|
import pro.gravit.launcher.hwid.OshiHWID;
|
||||||
import pro.gravit.launchserver.dao.User;
|
import pro.gravit.launchserver.dao.User;
|
||||||
import pro.gravit.launchserver.dao.UserDAO;
|
import pro.gravit.launchserver.dao.UserDAO;
|
||||||
import pro.gravit.launchserver.dao.UserHWID;
|
import pro.gravit.launchserver.dao.UserHWID;
|
||||||
|
|
||||||
public class HibernateUserDAOImpl implements UserDAO {
|
import javax.persistence.EntityManager;
|
||||||
private final SessionFactory factory;
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
import javax.persistence.criteria.Root;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public HibernateUserDAOImpl(SessionFactory factory) {
|
public class HibernateUserDAOImpl implements UserDAO {
|
||||||
this.factory = factory;
|
private final SessionFactory factory;
|
||||||
}
|
|
||||||
|
public HibernateUserDAOImpl(SessionFactory factory) {
|
||||||
|
this.factory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
public User findById(int id) {
|
public User findById(int id) {
|
||||||
try (Session s = factory.openSession()) {
|
try (Session s = factory.openSession()) {
|
||||||
return s.get(User.class, id);
|
return s.get(User.class, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,32 +75,32 @@ public List<UserHWID> findHWID(OshiHWID hwid) {
|
||||||
|
|
||||||
public void save(User user) {
|
public void save(User user) {
|
||||||
try (Session session = factory.openSession()) {
|
try (Session session = factory.openSession()) {
|
||||||
Transaction tx1 = session.beginTransaction();
|
Transaction tx1 = session.beginTransaction();
|
||||||
session.save(user);
|
session.save(user);
|
||||||
tx1.commit();
|
tx1.commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(User user) {
|
public void update(User user) {
|
||||||
try (Session session = factory.openSession()) {
|
try (Session session = factory.openSession()) {
|
||||||
Transaction tx1 = session.beginTransaction();
|
Transaction tx1 = session.beginTransaction();
|
||||||
session.update(user);
|
session.update(user);
|
||||||
tx1.commit();
|
tx1.commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(User user) {
|
public void delete(User user) {
|
||||||
try (Session session = factory.openSession()) {
|
try (Session session = factory.openSession()) {
|
||||||
Transaction tx1 = session.beginTransaction();
|
Transaction tx1 = session.beginTransaction();
|
||||||
session.delete(user);
|
session.delete(user);
|
||||||
tx1.commit();
|
tx1.commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public List<User> findAll() {
|
public List<User> findAll() {
|
||||||
try (Session s = factory.openSession()) {
|
try (Session s = factory.openSession()) {
|
||||||
return (List<User>) s.createQuery("From User").list();
|
return (List<User>) s.createQuery("From User").list();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,9 +9,10 @@ public abstract class DaoProvider {
|
||||||
public static final ProviderMap<DaoProvider> providers = new ProviderMap<>("DaoProvider");
|
public static final ProviderMap<DaoProvider> providers = new ProviderMap<>("DaoProvider");
|
||||||
public UserDAO userDAO;
|
public UserDAO userDAO;
|
||||||
public UserService userService;
|
public UserService userService;
|
||||||
public static void registerProviders()
|
|
||||||
{
|
public static void registerProviders() {
|
||||||
providers.register("hibernate", HibernateDaoProvider.class);
|
providers.register("hibernate", HibernateDaoProvider.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void init(LaunchServer server);
|
public abstract void init(LaunchServer server);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
package pro.gravit.launchserver.dao.provider;
|
package pro.gravit.launchserver.dao.provider;
|
||||||
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
import org.hibernate.cfg.Configuration;
|
import org.hibernate.cfg.Configuration;
|
||||||
|
|
||||||
import pro.gravit.launchserver.LaunchServer;
|
import pro.gravit.launchserver.LaunchServer;
|
||||||
import pro.gravit.launchserver.dao.User;
|
import pro.gravit.launchserver.dao.User;
|
||||||
import pro.gravit.launchserver.dao.UserHWID;
|
import pro.gravit.launchserver.dao.UserHWID;
|
||||||
|
@ -11,6 +8,8 @@
|
||||||
import pro.gravit.launchserver.dao.impl.HibernateUserDAOImpl;
|
import pro.gravit.launchserver.dao.impl.HibernateUserDAOImpl;
|
||||||
import pro.gravit.utils.helper.CommonHelper;
|
import pro.gravit.utils.helper.CommonHelper;
|
||||||
|
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
public class HibernateDaoProvider extends DaoProvider {
|
public class HibernateDaoProvider extends DaoProvider {
|
||||||
public String driver;
|
public String driver;
|
||||||
public String url;
|
public String url;
|
||||||
|
@ -32,14 +31,14 @@ public void init(LaunchServer server) {
|
||||||
.setProperty("hibernate.connection.username", username)
|
.setProperty("hibernate.connection.username", username)
|
||||||
.setProperty("hibernate.connection.password", password)
|
.setProperty("hibernate.connection.password", password)
|
||||||
.setProperty("hibernate.connection.pool_size", pool_size);
|
.setProperty("hibernate.connection.pool_size", pool_size);
|
||||||
if(dialect != null)
|
if (dialect != null)
|
||||||
cfg.setProperty("hibernate.dialect", dialect);
|
cfg.setProperty("hibernate.dialect", dialect);
|
||||||
if(hibernateConfig != null)
|
if (hibernateConfig != null)
|
||||||
cfg.configure(Paths.get(hibernateConfig).toFile());
|
cfg.configure(Paths.get(hibernateConfig).toFile());
|
||||||
userDAO = new HibernateUserDAOImpl(cfg.buildSessionFactory());
|
userDAO = new HibernateUserDAOImpl(cfg.buildSessionFactory());
|
||||||
userService = new UserService(userDAO);
|
userService = new UserService(userDAO);
|
||||||
};
|
};
|
||||||
if(parallelHibernateInit)
|
if (parallelHibernateInit)
|
||||||
CommonHelper.newThread("Hibernate Thread", true, init);
|
CommonHelper.newThread("Hibernate Thread", true, init);
|
||||||
else
|
else
|
||||||
init.run();
|
init.run();
|
||||||
|
|
|
@ -1,6 +1,31 @@
|
||||||
package pro.gravit.launchserver.manangers;
|
package pro.gravit.launchserver.manangers;
|
||||||
|
|
||||||
|
|
||||||
|
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
|
||||||
|
import org.bouncycastle.asn1.x500.X500Name;
|
||||||
|
import org.bouncycastle.asn1.x500.X500NameBuilder;
|
||||||
|
import org.bouncycastle.asn1.x500.style.BCStyle;
|
||||||
|
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
|
||||||
|
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
|
||||||
|
import org.bouncycastle.cert.X509CertificateHolder;
|
||||||
|
import org.bouncycastle.cert.X509v3CertificateBuilder;
|
||||||
|
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
|
||||||
|
import org.bouncycastle.crypto.util.PrivateKeyFactory;
|
||||||
|
import org.bouncycastle.crypto.util.PrivateKeyInfoFactory;
|
||||||
|
import org.bouncycastle.operator.ContentSigner;
|
||||||
|
import org.bouncycastle.operator.DefaultDigestAlgorithmIdentifierFinder;
|
||||||
|
import org.bouncycastle.operator.OperatorCreationException;
|
||||||
|
import org.bouncycastle.operator.bc.BcECContentSignerBuilder;
|
||||||
|
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
|
||||||
|
import org.bouncycastle.util.io.pem.PemObject;
|
||||||
|
import org.bouncycastle.util.io.pem.PemReader;
|
||||||
|
import org.bouncycastle.util.io.pem.PemWriter;
|
||||||
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
import pro.gravit.utils.helper.JVMHelper;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
import pro.gravit.utils.helper.SecurityHelper;
|
||||||
|
import pro.gravit.utils.verify.LauncherTrustManager;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.nio.file.FileVisitResult;
|
import java.nio.file.FileVisitResult;
|
||||||
|
@ -22,32 +47,6 @@
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
|
|
||||||
import org.bouncycastle.asn1.x500.X500Name;
|
|
||||||
import org.bouncycastle.asn1.x500.X500NameBuilder;
|
|
||||||
import org.bouncycastle.asn1.x500.style.BCStyle;
|
|
||||||
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
|
|
||||||
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
|
|
||||||
import org.bouncycastle.cert.X509CertificateHolder;
|
|
||||||
import org.bouncycastle.cert.X509v3CertificateBuilder;
|
|
||||||
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
|
|
||||||
import org.bouncycastle.crypto.util.PrivateKeyFactory;
|
|
||||||
import org.bouncycastle.crypto.util.PrivateKeyInfoFactory;
|
|
||||||
import org.bouncycastle.operator.ContentSigner;
|
|
||||||
import org.bouncycastle.operator.DefaultDigestAlgorithmIdentifierFinder;
|
|
||||||
import org.bouncycastle.operator.OperatorCreationException;
|
|
||||||
import org.bouncycastle.operator.bc.BcECContentSignerBuilder;
|
|
||||||
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
|
|
||||||
import org.bouncycastle.util.io.pem.PemObject;
|
|
||||||
import org.bouncycastle.util.io.pem.PemReader;
|
|
||||||
import org.bouncycastle.util.io.pem.PemWriter;
|
|
||||||
|
|
||||||
import pro.gravit.utils.helper.IOHelper;
|
|
||||||
import pro.gravit.utils.helper.JVMHelper;
|
|
||||||
import pro.gravit.utils.helper.LogHelper;
|
|
||||||
import pro.gravit.utils.helper.SecurityHelper;
|
|
||||||
import pro.gravit.utils.verify.LauncherTrustManager;
|
|
||||||
|
|
||||||
public class CertificateManager {
|
public class CertificateManager {
|
||||||
public X509CertificateHolder ca;
|
public X509CertificateHolder ca;
|
||||||
public AsymmetricKeyParameter caKey;
|
public AsymmetricKeyParameter caKey;
|
||||||
|
@ -82,7 +81,7 @@ public X509CertificateHolder generateCertificate(String subjectName, PublicKey s
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generateCA() throws NoSuchAlgorithmException, IOException, OperatorCreationException, InvalidAlgorithmParameterException {
|
public void generateCA() throws NoSuchAlgorithmException, IOException, OperatorCreationException, InvalidAlgorithmParameterException {
|
||||||
ECGenParameterSpec ecGenSpec = new ECGenParameterSpec("secp384r1");
|
ECGenParameterSpec ecGenSpec = new ECGenParameterSpec("secp384r1");
|
||||||
KeyPairGenerator generator = KeyPairGenerator.getInstance("EC");
|
KeyPairGenerator generator = KeyPairGenerator.getInstance("EC");
|
||||||
generator.initialize(ecGenSpec, SecurityHelper.newRandom());
|
generator.initialize(ecGenSpec, SecurityHelper.newRandom());
|
||||||
KeyPair pair = generator.generateKeyPair();
|
KeyPair pair = generator.generateKeyPair();
|
||||||
|
@ -92,21 +91,21 @@ public void generateCA() throws NoSuchAlgorithmException, IOException, OperatorC
|
||||||
subject.addRDN(BCStyle.CN, orgName.concat(" CA"));
|
subject.addRDN(BCStyle.CN, orgName.concat(" CA"));
|
||||||
subject.addRDN(BCStyle.O, orgName);
|
subject.addRDN(BCStyle.O, orgName);
|
||||||
|
|
||||||
X509v3CertificateBuilder builder= new X509v3CertificateBuilder(
|
X509v3CertificateBuilder builder = new X509v3CertificateBuilder(
|
||||||
subject.build(),
|
subject.build(),
|
||||||
new BigInteger("0"),
|
new BigInteger("0"),
|
||||||
Date.from(startDate.atZone(ZoneId.systemDefault()).toInstant()),
|
Date.from(startDate.atZone(ZoneId.systemDefault()).toInstant()),
|
||||||
Date.from(startDate.plusDays(3650).atZone(ZoneId.systemDefault()).toInstant()),
|
Date.from(startDate.plusDays(3650).atZone(ZoneId.systemDefault()).toInstant()),
|
||||||
new X500Name("CN=ca"),
|
new X500Name("CN=ca"),
|
||||||
SubjectPublicKeyInfo.getInstance(pair.getPublic().getEncoded()));
|
SubjectPublicKeyInfo.getInstance(pair.getPublic().getEncoded()));
|
||||||
JcaContentSignerBuilder csBuilder= new JcaContentSignerBuilder("SHA256WITHECDSA");
|
JcaContentSignerBuilder csBuilder = new JcaContentSignerBuilder("SHA256WITHECDSA");
|
||||||
ContentSigner signer = csBuilder.build(pair.getPrivate());
|
ContentSigner signer = csBuilder.build(pair.getPrivate());
|
||||||
ca = builder.build(signer);
|
ca = builder.build(signer);
|
||||||
caKey = PrivateKeyFactory.createKey(pair.getPrivate().getEncoded());
|
caKey = PrivateKeyFactory.createKey(pair.getPrivate().getEncoded());
|
||||||
}
|
}
|
||||||
|
|
||||||
public KeyPair generateKeyPair() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException {
|
public KeyPair generateKeyPair() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException {
|
||||||
ECGenParameterSpec ecGenSpec = new ECGenParameterSpec("secp384r1");
|
ECGenParameterSpec ecGenSpec = new ECGenParameterSpec("secp384r1");
|
||||||
KeyPairGenerator generator = KeyPairGenerator.getInstance("EC");
|
KeyPairGenerator generator = KeyPairGenerator.getInstance("EC");
|
||||||
generator.initialize(ecGenSpec, SecurityHelper.newRandom());
|
generator.initialize(ecGenSpec, SecurityHelper.newRandom());
|
||||||
return generator.generateKeyPair();
|
return generator.generateKeyPair();
|
||||||
|
@ -149,11 +148,9 @@ public AsymmetricKeyParameter readPrivateKey(Path file) throws IOException {
|
||||||
|
|
||||||
public AsymmetricKeyParameter readPrivateKey(Reader reader) throws IOException {
|
public AsymmetricKeyParameter readPrivateKey(Reader reader) throws IOException {
|
||||||
AsymmetricKeyParameter ret;
|
AsymmetricKeyParameter ret;
|
||||||
try(PemReader reader1 = new PemReader(reader))
|
try (PemReader reader1 = new PemReader(reader)) {
|
||||||
{
|
|
||||||
byte[] bytes = reader1.readPemObject().getContent();
|
byte[] bytes = reader1.readPemObject().getContent();
|
||||||
try(ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes))
|
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes)) {
|
||||||
{
|
|
||||||
|
|
||||||
ret = PrivateKeyFactory.createKey(inputStream);
|
ret = PrivateKeyFactory.createKey(inputStream);
|
||||||
}
|
}
|
||||||
|
@ -167,8 +164,7 @@ public X509CertificateHolder readCertificate(Path file) throws IOException {
|
||||||
|
|
||||||
public X509CertificateHolder readCertificate(Reader reader) throws IOException {
|
public X509CertificateHolder readCertificate(Reader reader) throws IOException {
|
||||||
X509CertificateHolder ret;
|
X509CertificateHolder ret;
|
||||||
try(PemReader reader1 = new PemReader(reader))
|
try (PemReader reader1 = new PemReader(reader)) {
|
||||||
{
|
|
||||||
byte[] bytes = reader1.readPemObject().getContent();
|
byte[] bytes = reader1.readPemObject().getContent();
|
||||||
ret = new X509CertificateHolder(bytes);
|
ret = new X509CertificateHolder(bytes);
|
||||||
}
|
}
|
||||||
|
@ -176,12 +172,10 @@ public X509CertificateHolder readCertificate(Reader reader) throws IOException {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readTrustStore(Path dir) throws IOException, CertificateException {
|
public void readTrustStore(Path dir) throws IOException, CertificateException {
|
||||||
if(!IOHelper.isDir(dir))
|
if (!IOHelper.isDir(dir)) {
|
||||||
{
|
|
||||||
Files.createDirectories(dir);
|
Files.createDirectories(dir);
|
||||||
try(OutputStream outputStream = IOHelper.newOutput(dir.resolve("GravitCentralRootCA.crt"));
|
try (OutputStream outputStream = IOHelper.newOutput(dir.resolve("GravitCentralRootCA.crt"));
|
||||||
InputStream inputStream = IOHelper.newInput(IOHelper.getResourceURL("pro/gravit/launchserver/defaults/GravitCentralRootCA.crt")))
|
InputStream inputStream = IOHelper.newInput(IOHelper.getResourceURL("pro/gravit/launchserver/defaults/GravitCentralRootCA.crt"))) {
|
||||||
{
|
|
||||||
IOHelper.transfer(inputStream, outputStream);
|
IOHelper.transfer(inputStream, outputStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,10 +184,8 @@ public void readTrustStore(Path dir) throws IOException, CertificateException {
|
||||||
IOHelper.walk(dir, new SimpleFileVisitor<Path>() {
|
IOHelper.walk(dir, new SimpleFileVisitor<Path>() {
|
||||||
@Override
|
@Override
|
||||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||||
if(file.toFile().getName().endsWith(".crt"))
|
if (file.toFile().getName().endsWith(".crt")) {
|
||||||
{
|
try (InputStream inputStream = IOHelper.newInput(file)) {
|
||||||
try(InputStream inputStream = IOHelper.newInput(file))
|
|
||||||
{
|
|
||||||
certificates.add((X509Certificate) certFactory.generateCertificate(inputStream));
|
certificates.add((X509Certificate) certFactory.generateCertificate(inputStream));
|
||||||
} catch (CertificateException e) {
|
} catch (CertificateException e) {
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
|
@ -205,20 +197,18 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
||||||
trustManager = new LauncherTrustManager(certificates.toArray(new X509Certificate[0]));
|
trustManager = new LauncherTrustManager(certificates.toArray(new X509Certificate[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkClass(Class<?> clazz, LauncherTrustManager.CheckMode mode) throws SecurityException
|
public void checkClass(Class<?> clazz, LauncherTrustManager.CheckMode mode) throws SecurityException {
|
||||||
{
|
if (trustManager == null) return;
|
||||||
if(trustManager == null) return;
|
|
||||||
X509Certificate[] certificates = JVMHelper.getCertificates(clazz);
|
X509Certificate[] certificates = JVMHelper.getCertificates(clazz);
|
||||||
if(certificates == null)
|
if (certificates == null) {
|
||||||
{
|
if (mode == LauncherTrustManager.CheckMode.EXCEPTION_IN_NOT_SIGNED)
|
||||||
if(mode == LauncherTrustManager.CheckMode.EXCEPTION_IN_NOT_SIGNED)
|
|
||||||
throw new SecurityException(String.format("Class %s not signed", clazz.getName()));
|
throw new SecurityException(String.format("Class %s not signed", clazz.getName()));
|
||||||
else if(mode == LauncherTrustManager.CheckMode.WARN_IN_NOT_SIGNED)
|
else if (mode == LauncherTrustManager.CheckMode.WARN_IN_NOT_SIGNED)
|
||||||
LogHelper.warning("Class %s not signed", clazz.getName());
|
LogHelper.warning("Class %s not signed", clazz.getName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
trustManager.checkCertificate(certificates, (c,s) -> {
|
trustManager.checkCertificate(certificates, (c, s) -> {
|
||||||
|
|
||||||
});
|
});
|
||||||
} catch (CertificateException | NoSuchProviderException | NoSuchAlgorithmException | InvalidKeyException | SignatureException e) {
|
} catch (CertificateException | NoSuchProviderException | NoSuchAlgorithmException | InvalidKeyException | SignatureException e) {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package pro.gravit.launchserver.manangers;
|
package pro.gravit.launchserver.manangers;
|
||||||
|
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
|
|
||||||
import pro.gravit.launcher.hwid.HWID;
|
import pro.gravit.launcher.hwid.HWID;
|
||||||
import pro.gravit.launcher.hwid.HWIDProvider;
|
import pro.gravit.launcher.hwid.HWIDProvider;
|
||||||
import pro.gravit.launcher.managers.GsonManager;
|
import pro.gravit.launcher.managers.GsonManager;
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue