mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-01-09 00:59:44 +03:00
[ANY] Full IDEA reformat
This commit is contained in:
parent
82accb211d
commit
10888ed2e7
73 changed files with 572 additions and 618 deletions
|
@ -17,25 +17,6 @@ public class HttpRequester {
|
|||
public HttpRequester() {
|
||||
}
|
||||
|
||||
public static class SimpleErrorHandler<T> implements HttpHelper.HttpJsonErrorHandler<T, SimpleError> {
|
||||
private final Type type;
|
||||
|
||||
private SimpleErrorHandler(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpHelper.HttpOptional<T, SimpleError> applyJson(JsonElement response, int statusCode) {
|
||||
if(statusCode < 200 || statusCode >= 300) {
|
||||
return new HttpHelper.HttpOptional<>(null, Launcher.gsonManager.gson.fromJson(response, SimpleError.class), statusCode);
|
||||
}
|
||||
if(type == Void.class) {
|
||||
return new HttpHelper.HttpOptional<>(null, null, statusCode);
|
||||
}
|
||||
return new HttpHelper.HttpOptional<>(Launcher.gsonManager.gson.fromJson(response, type), null, statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> SimpleErrorHandler<T> makeEH(Class<T> clazz) {
|
||||
return new SimpleErrorHandler<>(clazz);
|
||||
}
|
||||
|
@ -78,6 +59,25 @@ public <T> HttpHelper.HttpOptional<T, SimpleError> send(HttpRequest request, Cla
|
|||
return HttpHelper.send(httpClient, request, makeEH(clazz));
|
||||
}
|
||||
|
||||
public static class SimpleErrorHandler<T> implements HttpHelper.HttpJsonErrorHandler<T, SimpleError> {
|
||||
private final Type type;
|
||||
|
||||
private SimpleErrorHandler(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpHelper.HttpOptional<T, SimpleError> applyJson(JsonElement response, int statusCode) {
|
||||
if (statusCode < 200 || statusCode >= 300) {
|
||||
return new HttpHelper.HttpOptional<>(null, Launcher.gsonManager.gson.fromJson(response, SimpleError.class), statusCode);
|
||||
}
|
||||
if (type == Void.class) {
|
||||
return new HttpHelper.HttpOptional<>(null, null, statusCode);
|
||||
}
|
||||
return new HttpHelper.HttpOptional<>(Launcher.gsonManager.gson.fromJson(response, type), null, statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SimpleError {
|
||||
public String error;
|
||||
public int code;
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
import pro.gravit.launcher.managers.ConfigManager;
|
||||
import pro.gravit.launcher.modules.events.ClosePhase;
|
||||
import pro.gravit.launcher.profiles.ClientProfile;
|
||||
import pro.gravit.launcher.request.Request;
|
||||
import pro.gravit.launchserver.auth.AuthProviderPair;
|
||||
import pro.gravit.launchserver.auth.core.RejectAuthCoreProvider;
|
||||
import pro.gravit.launchserver.binary.EXEL4JLauncherBinary;
|
||||
|
|
|
@ -38,15 +38,6 @@ public static Set<String> getFeatures(Class<?> clazz) {
|
|||
return list;
|
||||
}
|
||||
|
||||
public void internalShowOAuthWarnMessage() {
|
||||
if(!warnOAuthShow) {
|
||||
if(!(core instanceof MySQLCoreProvider) && !(core instanceof PostgresSQLCoreProvider)) { // MySQL and PostgreSQL upgraded later
|
||||
logger.warn("AuthCoreProvider {} ({}) not supported OAuth. Legacy session system may be removed in next release", name, core.getClass().getName());
|
||||
}
|
||||
warnOAuthShow = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void getFeatures(Class<?> clazz, Set<String> list) {
|
||||
Features features = clazz.getAnnotation(Features.class);
|
||||
if (features != null) {
|
||||
|
@ -64,6 +55,15 @@ public static void getFeatures(Class<?> clazz, Set<String> list) {
|
|||
}
|
||||
}
|
||||
|
||||
public void internalShowOAuthWarnMessage() {
|
||||
if (!warnOAuthShow) {
|
||||
if (!(core instanceof MySQLCoreProvider) && !(core instanceof PostgresSQLCoreProvider)) { // MySQL and PostgreSQL upgraded later
|
||||
logger.warn("AuthCoreProvider {} ({}) not supported OAuth. Legacy session system may be removed in next release", name, core.getClass().getName());
|
||||
}
|
||||
warnOAuthShow = true;
|
||||
}
|
||||
}
|
||||
|
||||
public final <T> T isSupport(Class<T> clazz) {
|
||||
if (core == null) return null;
|
||||
T result = null;
|
||||
|
|
|
@ -5,5 +5,6 @@
|
|||
|
||||
public interface SQLSourceConfig {
|
||||
Connection getConnection() throws SQLException;
|
||||
|
||||
void close();
|
||||
}
|
||||
|
|
|
@ -231,7 +231,7 @@ public ClientPermissions requestPermissions(String uuid) throws SQLException {
|
|||
}
|
||||
|
||||
public boolean isEnabledPermissions() {
|
||||
return permissionsTable != null && permissionsPermissionColumn != null && permissionsUUIDColumn != null;
|
||||
return permissionsPermissionColumn != null;
|
||||
}
|
||||
|
||||
private User query(String sql, String value) throws IOException {
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
|
||||
public class HttpAuthCoreProvider extends AuthCoreProvider implements AuthSupportHardware, AuthSupportRemoteClientAccess {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
private transient HttpRequester requester;
|
||||
public String bearerToken;
|
||||
public String getUserByUsernameUrl;
|
||||
public String getUserByLoginUrl;
|
||||
|
@ -52,6 +51,7 @@ public class HttpAuthCoreProvider extends AuthCoreProvider implements AuthSuppor
|
|||
public String unbanHardwareUrl;
|
||||
public String apiUrl;
|
||||
public List<String> apiFeatures;
|
||||
private transient HttpRequester requester;
|
||||
|
||||
@Override
|
||||
public User getUserByUsername(String username) {
|
||||
|
@ -280,14 +280,6 @@ public List<String> getClientApiFeatures() {
|
|||
return apiFeatures;
|
||||
}
|
||||
|
||||
public record HttpAuthReport(String minecraftAccessToken, String oauthAccessToken,
|
||||
String oauthRefreshToken, long oauthExpire,
|
||||
HttpUserSession session) {
|
||||
public AuthManager.AuthReport toAuthReport() {
|
||||
return new AuthManager.AuthReport(minecraftAccessToken, oauthAccessToken, oauthRefreshToken, oauthExpire, session);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean updateServerID(User user, String serverID) throws IOException {
|
||||
var result = requester.send(requester.post(updateServerIdUrl, new UpdateServerIdRequest(user.getUsername(), user.getUUID(), serverID),
|
||||
|
@ -306,6 +298,36 @@ public boolean joinServer(Client client, String username, String accessToken, St
|
|||
return result.isSuccessful();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(LaunchServer server) {
|
||||
requester = new HttpRequester();
|
||||
if (getUserByUsernameUrl == null) {
|
||||
throw new IllegalArgumentException("'getUserByUsernameUrl' can't be null");
|
||||
}
|
||||
if (getUserByUUIDUrl == null) {
|
||||
throw new IllegalArgumentException("'getUserByUUIDUrl' can't be null");
|
||||
}
|
||||
if (authorizeUrl == null) {
|
||||
throw new IllegalArgumentException("'authorizeUrl' can't be null");
|
||||
}
|
||||
if (checkServerUrl == null && joinServerUrl == null && updateServerIdUrl == null) {
|
||||
throw new IllegalArgumentException("Please set 'checkServerUrl' and 'joinServerUrl' or 'updateServerIdUrl'");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
|
||||
}
|
||||
|
||||
public record HttpAuthReport(String minecraftAccessToken, String oauthAccessToken,
|
||||
String oauthRefreshToken, long oauthExpire,
|
||||
HttpUserSession session) {
|
||||
public AuthManager.AuthReport toAuthReport() {
|
||||
return new AuthManager.AuthReport(minecraftAccessToken, oauthAccessToken, oauthRefreshToken, oauthExpire, session);
|
||||
}
|
||||
}
|
||||
|
||||
public static class UpdateServerIdRequest {
|
||||
public String username;
|
||||
public UUID uuid;
|
||||
|
@ -344,28 +366,6 @@ public JoinServerRequest(String username, String accessToken, String serverId) {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(LaunchServer server) {
|
||||
requester = new HttpRequester();
|
||||
if(getUserByUsernameUrl == null) {
|
||||
throw new IllegalArgumentException("'getUserByUsernameUrl' can't be null");
|
||||
}
|
||||
if(getUserByUUIDUrl == null) {
|
||||
throw new IllegalArgumentException("'getUserByUUIDUrl' can't be null");
|
||||
}
|
||||
if(authorizeUrl == null) {
|
||||
throw new IllegalArgumentException("'authorizeUrl' can't be null");
|
||||
}
|
||||
if(checkServerUrl == null && joinServerUrl == null && updateServerIdUrl == null) {
|
||||
throw new IllegalArgumentException("Please set 'checkServerUrl' and 'joinServerUrl' or 'updateServerIdUrl'");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
|
||||
}
|
||||
|
||||
public static class AuthorizeRequest {
|
||||
public String login;
|
||||
public AuthResponse.AuthContext context;
|
||||
|
@ -413,6 +413,106 @@ public HardwareRequest(byte[] key) {
|
|||
|
||||
}
|
||||
|
||||
public static class HttpUserSession implements UserSession {
|
||||
private String id;
|
||||
private HttpUser user;
|
||||
private long expireIn;
|
||||
|
||||
public HttpUserSession() {
|
||||
}
|
||||
|
||||
public HttpUserSession(String id, HttpUser user, long expireIn) {
|
||||
this.id = id;
|
||||
this.user = user;
|
||||
this.expireIn = expireIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getExpireIn() {
|
||||
return expireIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HttpUserSession{" +
|
||||
"id='" + id + '\'' +
|
||||
", user=" + user +
|
||||
", expireIn=" + expireIn +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
public static class HttpUserHardware implements UserHardware {
|
||||
private final HardwareReportRequest.HardwareInfo hardwareInfo;
|
||||
private final long id;
|
||||
private byte[] publicKey;
|
||||
private boolean banned;
|
||||
|
||||
public HttpUserHardware(HardwareReportRequest.HardwareInfo hardwareInfo, byte[] publicKey, long id, boolean banned) {
|
||||
this.hardwareInfo = hardwareInfo;
|
||||
this.publicKey = publicKey;
|
||||
this.id = id;
|
||||
this.banned = banned;
|
||||
}
|
||||
|
||||
public HttpUserHardware(HardwareReportRequest.HardwareInfo hardwareInfo) {
|
||||
this.hardwareInfo = hardwareInfo;
|
||||
this.id = Long.MIN_VALUE;
|
||||
}
|
||||
|
||||
public HttpUserHardware(HardwareReportRequest.HardwareInfo hardwareInfo, byte[] publicKey, boolean banned) {
|
||||
this.hardwareInfo = hardwareInfo;
|
||||
this.publicKey = publicKey;
|
||||
this.banned = banned;
|
||||
this.id = Long.MIN_VALUE;
|
||||
}
|
||||
|
||||
public HttpUserHardware(long id) {
|
||||
this.id = id;
|
||||
this.hardwareInfo = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HardwareReportRequest.HardwareInfo getHardwareInfo() {
|
||||
return hardwareInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getPublicKey() {
|
||||
return publicKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return String.valueOf(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBanned() {
|
||||
return banned;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HttpUserHardware{" +
|
||||
"hardwareInfo=" + hardwareInfo +
|
||||
", publicKey=" + (publicKey == null ? null : new String(Base64.getEncoder().encode(publicKey))) +
|
||||
", id=" + id +
|
||||
", banned=" + banned +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
public class HttpUser implements User, UserSupportTextures, UserSupportProperties, UserSupportHardware {
|
||||
private String username;
|
||||
private UUID uuid;
|
||||
|
@ -559,104 +659,4 @@ public UserHardware getHardware() {
|
|||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public static class HttpUserSession implements UserSession {
|
||||
private String id;
|
||||
private HttpUser user;
|
||||
private long expireIn;
|
||||
|
||||
public HttpUserSession() {
|
||||
}
|
||||
|
||||
public HttpUserSession(String id, HttpUser user, long expireIn) {
|
||||
this.id = id;
|
||||
this.user = user;
|
||||
this.expireIn = expireIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getExpireIn() {
|
||||
return expireIn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HttpUserSession{" +
|
||||
"id='" + id + '\'' +
|
||||
", user=" + user +
|
||||
", expireIn=" + expireIn +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
public static class HttpUserHardware implements UserHardware {
|
||||
private final HardwareReportRequest.HardwareInfo hardwareInfo;
|
||||
private final long id;
|
||||
private byte[] publicKey;
|
||||
private boolean banned;
|
||||
|
||||
public HttpUserHardware(HardwareReportRequest.HardwareInfo hardwareInfo, byte[] publicKey, long id, boolean banned) {
|
||||
this.hardwareInfo = hardwareInfo;
|
||||
this.publicKey = publicKey;
|
||||
this.id = id;
|
||||
this.banned = banned;
|
||||
}
|
||||
|
||||
public HttpUserHardware(HardwareReportRequest.HardwareInfo hardwareInfo) {
|
||||
this.hardwareInfo = hardwareInfo;
|
||||
this.id = Long.MIN_VALUE;
|
||||
}
|
||||
|
||||
public HttpUserHardware(HardwareReportRequest.HardwareInfo hardwareInfo, byte[] publicKey, boolean banned) {
|
||||
this.hardwareInfo = hardwareInfo;
|
||||
this.publicKey = publicKey;
|
||||
this.banned = banned;
|
||||
this.id = Long.MIN_VALUE;
|
||||
}
|
||||
|
||||
public HttpUserHardware(long id) {
|
||||
this.id = id;
|
||||
this.hardwareInfo = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HardwareReportRequest.HardwareInfo getHardwareInfo() {
|
||||
return hardwareInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getPublicKey() {
|
||||
return publicKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return String.valueOf(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBanned() {
|
||||
return banned;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HttpUserHardware{" +
|
||||
"hardwareInfo=" + hardwareInfo +
|
||||
", publicKey=" + (publicKey == null ? null : new String(Base64.getEncoder().encode(publicKey))) +
|
||||
", id=" + id +
|
||||
", banned=" + banned +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,14 @@
|
|||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MemoryAuthCoreProvider extends AuthCoreProvider {
|
||||
private transient final List<MemoryUser> memory = new ArrayList<>(16);
|
||||
|
||||
@Override
|
||||
public User getUserByUsername(String username) {
|
||||
synchronized (memory) {
|
||||
|
|
|
@ -1,33 +1,18 @@
|
|||
package pro.gravit.launchserver.auth.core;
|
||||
|
||||
import io.jsonwebtoken.ExpiredJwtException;
|
||||
import io.jsonwebtoken.JwtException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import pro.gravit.launcher.ClientPermissions;
|
||||
import pro.gravit.launcher.request.auth.AuthRequest;
|
||||
import pro.gravit.launcher.request.auth.password.AuthPlainPassword;
|
||||
import pro.gravit.launcher.request.secure.HardwareReportRequest;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.auth.AuthException;
|
||||
import pro.gravit.launchserver.auth.MySQLSourceConfig;
|
||||
import pro.gravit.launchserver.auth.SQLSourceConfig;
|
||||
import pro.gravit.launchserver.auth.core.interfaces.UserHardware;
|
||||
import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportHardware;
|
||||
import pro.gravit.launchserver.auth.core.interfaces.user.UserSupportHardware;
|
||||
import pro.gravit.launchserver.auth.password.PasswordVerifier;
|
||||
import pro.gravit.launchserver.helper.LegacySessionHelper;
|
||||
import pro.gravit.launchserver.manangers.AuthManager;
|
||||
import pro.gravit.launchserver.socket.response.auth.AuthResponse;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
import pro.gravit.utils.helper.SecurityHelper;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.sql.*;
|
||||
import java.time.Clock;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Base64;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
@ -108,6 +93,7 @@ private void setUserHardwareId(Connection connection, UUID uuid, long hwidId) th
|
|||
s.setString(2, uuid.toString());
|
||||
s.executeUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserHardware getHardwareInfoByPublicKey(byte[] publicKey) {
|
||||
try (Connection connection = mySQLHolder.getConnection()) {
|
||||
|
@ -320,6 +306,7 @@ public MySQLUser(UUID uuid, String username, String accessToken, String serverId
|
|||
super(uuid, username, accessToken, serverId, password, permissions);
|
||||
this.hwidId = hwidId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserHardware getHardware() {
|
||||
if (hardware != null) return hardware;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package pro.gravit.launchserver.auth.core;
|
||||
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.auth.PostgreSQLSourceConfig;
|
||||
import pro.gravit.launchserver.auth.SQLSourceConfig;
|
||||
|
||||
|
|
|
@ -4,5 +4,6 @@
|
|||
|
||||
public interface AuthSupportRemoteClientAccess {
|
||||
String getClientApiUrl();
|
||||
|
||||
List<String> getClientApiFeatures();
|
||||
}
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
|
||||
public interface UserSessionSupportKeys {
|
||||
ClientProfileKeys getClientProfileKeys();
|
||||
record ClientProfileKeys(PublicKey publicKey, PrivateKey privateKey, byte[] signature /* V2 */, long expiresAt, long refreshedAfter) {
|
||||
|
||||
record ClientProfileKeys(PublicKey publicKey, PrivateKey privateKey, byte[] signature /* V2 */, long expiresAt,
|
||||
long refreshedAfter) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
public class BCryptPasswordVerifier extends PasswordVerifier {
|
||||
public int cost = 10;
|
||||
|
||||
@Override
|
||||
public boolean check(String encryptedPassword, String password) {
|
||||
return OpenBSDBCrypt.checkPassword(encryptedPassword, password.toCharArray());
|
||||
|
|
|
@ -19,29 +19,6 @@ public class JsonPasswordVerifier extends PasswordVerifier {
|
|||
public String url;
|
||||
public String bearerToken;
|
||||
|
||||
@Override
|
||||
public boolean check(String encryptedPassword, String password) {
|
||||
JsonPasswordResponse response = jsonRequest(new JsonPasswordRequest(encryptedPassword, password), url, bearerToken, JsonPasswordResponse.class, client);
|
||||
if (response != null) {
|
||||
return response.success;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class JsonPasswordRequest {
|
||||
public String encryptedPassword;
|
||||
public String password;
|
||||
|
||||
public JsonPasswordRequest(String encryptedPassword, String password) {
|
||||
this.encryptedPassword = encryptedPassword;
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
|
||||
public static class JsonPasswordResponse {
|
||||
public boolean success;
|
||||
}
|
||||
|
||||
public static <T, R> R jsonRequest(T request, String url, String bearerToken, Class<R> clazz, HttpClient client) {
|
||||
HttpRequest.BodyPublisher publisher;
|
||||
if (request != null) {
|
||||
|
@ -78,4 +55,27 @@ public static <T, R> R jsonRequest(T request, String url, String bearerToken, Cl
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(String encryptedPassword, String password) {
|
||||
JsonPasswordResponse response = jsonRequest(new JsonPasswordRequest(encryptedPassword, password), url, bearerToken, JsonPasswordResponse.class, client);
|
||||
if (response != null) {
|
||||
return response.success;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class JsonPasswordRequest {
|
||||
public String encryptedPassword;
|
||||
public String password;
|
||||
|
||||
public JsonPasswordRequest(String encryptedPassword, String password) {
|
||||
this.encryptedPassword = encryptedPassword;
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
|
||||
public static class JsonPasswordResponse {
|
||||
public boolean success;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
import pro.gravit.launcher.events.request.GetSecureLevelInfoRequestEvent;
|
||||
import pro.gravit.launcher.events.request.HardwareReportRequestEvent;
|
||||
import pro.gravit.launcher.events.request.VerifySecureLevelKeyRequestEvent;
|
||||
import pro.gravit.launcher.request.secure.HardwareReportRequest;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.auth.AuthProviderPair;
|
||||
import pro.gravit.launchserver.auth.core.interfaces.UserHardware;
|
||||
|
|
|
@ -15,9 +15,10 @@
|
|||
import java.util.UUID;
|
||||
|
||||
public class JsonTextureProvider extends TextureProvider {
|
||||
public String url;
|
||||
private transient static final Type MAP_TYPE = new TypeToken<Map<String, Texture>>() {
|
||||
}.getType();
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
private transient static final Type MAP_TYPE = new TypeToken<Map<String, Texture>>() {}.getType();
|
||||
public String url;
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
|
|
|
@ -33,17 +33,6 @@ public static void registerProviders() {
|
|||
|
||||
public abstract Texture getSkinTexture(UUID uuid, String username, String client) throws IOException;
|
||||
|
||||
@Deprecated
|
||||
public static class SkinAndCloakTextures {
|
||||
public final Texture skin;
|
||||
public final Texture cloak;
|
||||
|
||||
public SkinAndCloakTextures(Texture skin, Texture cloak) {
|
||||
this.skin = skin;
|
||||
this.cloak = cloak;
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public SkinAndCloakTextures getTextures(UUID uuid, String username, String client) {
|
||||
|
||||
|
@ -92,4 +81,15 @@ public Map<String, Texture> getAssets(UUID uuid, String username, String client)
|
|||
|
||||
return map;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static class SkinAndCloakTextures {
|
||||
public final Texture skin;
|
||||
public final Texture cloak;
|
||||
|
||||
public SkinAndCloakTextures(Texture skin, Texture cloak) {
|
||||
this.skin = skin;
|
||||
this.cloak = cloak;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -211,7 +211,8 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
|
|||
try {
|
||||
cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, sKeySpec, iKeySpec);
|
||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException e) {
|
||||
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException |
|
||||
InvalidAlgorithmParameterException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
try (OutputStream stream = new CipherOutputStream(new NoCloseOutputStream(output), cipher)) {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
public class DebugCommand extends Command {
|
||||
private transient Logger logger = LogManager.getLogger();
|
||||
|
||||
public DebugCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
|
|
@ -10,9 +10,7 @@
|
|||
import pro.gravit.launchserver.command.Command;
|
||||
import pro.gravit.utils.Downloader;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
import proguard.OutputWriter;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.io.Writer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
@ -22,11 +20,9 @@
|
|||
import java.util.List;
|
||||
|
||||
public final class DownloadAssetCommand extends Command {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
private static final String MINECRAFT_VERSIONS_URL = "https://launchermeta.mojang.com/mc/game/version_manifest.json";
|
||||
|
||||
private static final String RESOURCES_DOWNLOAD_URL = "https://resources.download.minecraft.net/";
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public DownloadAssetCommand(LaunchServer server) {
|
||||
super(server);
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
public class TokenCommand extends Command {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
public TokenCommand(LaunchServer server) {
|
||||
super(server);
|
||||
this.childCommands.put("info", new SubCommand("[token]", "print token info") {
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
import pro.gravit.utils.helper.UnpackHelper;
|
||||
import proguard.Configuration;
|
||||
import proguard.ConfigurationParser;
|
||||
import proguard.ParseException;
|
||||
import proguard.ProGuard;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -23,71 +23,11 @@
|
|||
|
||||
public final class HttpHelper {
|
||||
private static transient final Logger logger = LogManager.getLogger();
|
||||
|
||||
private HttpHelper() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public static class HttpOptional<T,E> {
|
||||
protected final T result;
|
||||
protected final E error;
|
||||
protected final int statusCode;
|
||||
|
||||
public HttpOptional(T result, E error, int statusCode) {
|
||||
this.result = result;
|
||||
this.error = error;
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
public T result() {
|
||||
return result;
|
||||
}
|
||||
public E error() {
|
||||
return error;
|
||||
}
|
||||
public int statusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
public boolean isSuccessful() {
|
||||
return statusCode >= 200 && statusCode < 300;
|
||||
}
|
||||
public T getOrThrow() throws RequestException {
|
||||
if(isSuccessful()) {
|
||||
return result;
|
||||
} else {
|
||||
throw new RequestException(error == null ? String.format("statusCode %d", statusCode) : error.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface HttpErrorHandler<T, E> {
|
||||
HttpOptional<T,E> apply(HttpResponse<InputStream> response);
|
||||
}
|
||||
|
||||
public interface HttpJsonErrorHandler<T, E> extends HttpErrorHandler<T,E> {
|
||||
HttpOptional<T,E> applyJson(JsonElement response, int statusCode);
|
||||
default HttpOptional<T,E> apply(HttpResponse<InputStream> response) {
|
||||
try(Reader reader = new InputStreamReader(response.body())) {
|
||||
var element = Launcher.gsonManager.gson.fromJson(reader, JsonElement.class);
|
||||
return applyJson(element, response.statusCode());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class BasicJsonHttpErrorHandler<T> implements HttpJsonErrorHandler<T, Void> {
|
||||
private final Class<T> type;
|
||||
|
||||
public BasicJsonHttpErrorHandler(Class<T> type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpOptional<T, Void> applyJson(JsonElement response, int statusCode) {
|
||||
return new HttpOptional<>(Launcher.gsonManager.gson.fromJson(response, type), null, statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T, E> HttpOptional<T, E> send(HttpClient client, HttpRequest request, HttpErrorHandler<T, E> handler) throws IOException {
|
||||
try {
|
||||
var response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
|
||||
|
@ -97,7 +37,6 @@ public static<T,E> HttpOptional<T,E> send(HttpClient client, HttpRequest request
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static <T, E> CompletableFuture<HttpOptional<T, E>> sendAsync(HttpClient client, HttpRequest request, HttpErrorHandler<T, E> handler) throws IOException {
|
||||
return client.sendAsync(request, HttpResponse.BodyHandlers.ofInputStream()).thenApply(handler::apply);
|
||||
}
|
||||
|
@ -120,6 +59,73 @@ public static<T> HttpRequest.BodyPublisher jsonBodyPublisher(T obj) {
|
|||
return HttpRequest.BodyPublishers.ofString(Launcher.gsonManager.gson.toJson(obj));
|
||||
}
|
||||
|
||||
|
||||
public interface HttpErrorHandler<T, E> {
|
||||
HttpOptional<T, E> apply(HttpResponse<InputStream> response);
|
||||
}
|
||||
|
||||
public interface HttpJsonErrorHandler<T, E> extends HttpErrorHandler<T, E> {
|
||||
HttpOptional<T, E> applyJson(JsonElement response, int statusCode);
|
||||
|
||||
default HttpOptional<T, E> apply(HttpResponse<InputStream> response) {
|
||||
try (Reader reader = new InputStreamReader(response.body())) {
|
||||
var element = Launcher.gsonManager.gson.fromJson(reader, JsonElement.class);
|
||||
return applyJson(element, response.statusCode());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class HttpOptional<T, E> {
|
||||
protected final T result;
|
||||
protected final E error;
|
||||
protected final int statusCode;
|
||||
|
||||
public HttpOptional(T result, E error, int statusCode) {
|
||||
this.result = result;
|
||||
this.error = error;
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
public T result() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public E error() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public int statusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public boolean isSuccessful() {
|
||||
return statusCode >= 200 && statusCode < 300;
|
||||
}
|
||||
|
||||
public T getOrThrow() throws RequestException {
|
||||
if (isSuccessful()) {
|
||||
return result;
|
||||
} else {
|
||||
throw new RequestException(error == null ? String.format("statusCode %d", statusCode) : error.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class BasicJsonHttpErrorHandler<T> implements HttpJsonErrorHandler<T, Void> {
|
||||
private final Class<T> type;
|
||||
|
||||
public BasicJsonHttpErrorHandler(Class<T> type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpOptional<T, Void> applyJson(JsonElement response, int statusCode) {
|
||||
return new HttpOptional<>(Launcher.gsonManager.gson.fromJson(response, type), null, statusCode);
|
||||
}
|
||||
}
|
||||
|
||||
private static class JsonBodyHandler<T> implements HttpResponse.BodyHandler<T> {
|
||||
private final HttpResponse.BodyHandler<InputStream> delegate;
|
||||
private final Function<InputStream, T> func;
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
import java.security.interfaces.ECPrivateKey;
|
||||
import java.security.interfaces.ECPublicKey;
|
||||
import java.time.Clock;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.Date;
|
||||
|
|
|
@ -27,13 +27,7 @@
|
|||
import pro.gravit.utils.helper.SecurityHelper;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.KeyPair;
|
||||
import java.security.SecureRandom;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.*;
|
||||
|
||||
public class AuthManager {
|
||||
|
@ -60,9 +54,6 @@ public String newCheckServerToken(String serverName, String authId) {
|
|||
.compact();
|
||||
}
|
||||
|
||||
public record CheckServerTokenInfo(String serverName, String authId) {
|
||||
}
|
||||
|
||||
public CheckServerTokenInfo parseCheckServerToken(String token) {
|
||||
try {
|
||||
var jwt = checkServerTokenParser.parseClaimsJws(token).getBody();
|
||||
|
@ -72,29 +63,6 @@ public CheckServerTokenInfo parseCheckServerToken(String token) {
|
|||
}
|
||||
}
|
||||
|
||||
public static class CheckServerVerifier implements RestoreResponse.ExtendedTokenProvider {
|
||||
private final LaunchServer server;
|
||||
|
||||
public CheckServerVerifier(LaunchServer server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(Client client, AuthProviderPair pair, String extendedToken) {
|
||||
var info = server.authManager.parseCheckServerToken(extendedToken);
|
||||
if(info == null) {
|
||||
return false;
|
||||
}
|
||||
client.auth_id = info.authId;
|
||||
client.auth = server.config.getAuthProviderPair(info.authId);
|
||||
if(client.permissions == null) client.permissions = new ClientPermissions();
|
||||
client.permissions.addPerm("launchserver.checkserver");
|
||||
client.permissions.addPerm(String.format("launchserver.profile.%s.show", info.serverName));
|
||||
client.setProperty("launchserver.serverName", info.serverName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create AuthContext
|
||||
*
|
||||
|
@ -325,6 +293,32 @@ private AuthRequest.AuthPasswordInterface tryDecryptPasswordPlain(AuthRequest.Au
|
|||
return password;
|
||||
}
|
||||
|
||||
public record CheckServerTokenInfo(String serverName, String authId) {
|
||||
}
|
||||
|
||||
public static class CheckServerVerifier implements RestoreResponse.ExtendedTokenProvider {
|
||||
private final LaunchServer server;
|
||||
|
||||
public CheckServerVerifier(LaunchServer server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(Client client, AuthProviderPair pair, String extendedToken) {
|
||||
var info = server.authManager.parseCheckServerToken(extendedToken);
|
||||
if (info == null) {
|
||||
return false;
|
||||
}
|
||||
client.auth_id = info.authId;
|
||||
client.auth = server.config.getAuthProviderPair(info.authId);
|
||||
if (client.permissions == null) client.permissions = new ClientPermissions();
|
||||
client.permissions.addPerm("launchserver.checkserver");
|
||||
client.permissions.addPerm(String.format("launchserver.profile.%s.show", info.serverName));
|
||||
client.setProperty("launchserver.serverName", info.serverName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CheckServerReport {
|
||||
public UUID uuid;
|
||||
public User user;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package pro.gravit.launchserver.manangers.hook;
|
||||
|
||||
import pro.gravit.launchserver.auth.core.User;
|
||||
import pro.gravit.launchserver.manangers.AuthManager;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
import pro.gravit.launchserver.socket.response.auth.AuthResponse;
|
||||
|
|
|
@ -93,6 +93,22 @@ public static void registerResponses() {
|
|||
providers.register("getPublicKey", GetPublicKeyResponse.class);
|
||||
}
|
||||
|
||||
public static String getIPFromContext(ChannelHandlerContext ctx) {
|
||||
var handler = ctx.pipeline().get(WebSocketFrameHandler.class);
|
||||
if (handler == null || handler.context == null || handler.context.ip == null) {
|
||||
return IOHelper.getIP(ctx.channel().remoteAddress());
|
||||
}
|
||||
return handler.context.ip;
|
||||
}
|
||||
|
||||
public static String getIPFromChannel(Channel channel) {
|
||||
var handler = channel.pipeline().get(WebSocketFrameHandler.class);
|
||||
if (handler == null || handler.context == null || handler.context.ip == null) {
|
||||
return IOHelper.getIP(channel.remoteAddress());
|
||||
}
|
||||
return handler.context.ip;
|
||||
}
|
||||
|
||||
public void forEachActiveChannels(BiConsumer<Channel, WebSocketFrameHandler> callback) {
|
||||
for (Channel channel : channels) {
|
||||
if (channel == null || channel.pipeline() == null) continue;
|
||||
|
@ -176,22 +192,6 @@ public void registerClient(Channel channel) {
|
|||
channels.add(channel);
|
||||
}
|
||||
|
||||
public static String getIPFromContext(ChannelHandlerContext ctx) {
|
||||
var handler = ctx.pipeline().get(WebSocketFrameHandler.class);
|
||||
if(handler == null || handler.context == null || handler.context.ip == null) {
|
||||
return IOHelper.getIP(ctx.channel().remoteAddress());
|
||||
}
|
||||
return handler.context.ip;
|
||||
}
|
||||
|
||||
public static String getIPFromChannel(Channel channel) {
|
||||
var handler = channel.pipeline().get(WebSocketFrameHandler.class);
|
||||
if(handler == null || handler.context == null || handler.context.ip == null) {
|
||||
return IOHelper.getIP(channel.remoteAddress());
|
||||
}
|
||||
return handler.context.ip;
|
||||
}
|
||||
|
||||
public void sendObject(ChannelHandlerContext ctx, Object obj) {
|
||||
String msg = gson.toJson(obj, WebSocketEvent.class);
|
||||
if (logger.isTraceEnabled()) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package pro.gravit.launchserver.socket.response.auth;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import pro.gravit.launcher.ClientPermissions;
|
||||
import pro.gravit.launcher.events.request.AdditionalDataRequestEvent;
|
||||
import pro.gravit.launchserver.auth.AuthProviderPair;
|
||||
import pro.gravit.launchserver.auth.core.User;
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
import pro.gravit.launchserver.socket.response.SimpleResponse;
|
||||
import pro.gravit.utils.HookException;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class AuthResponse extends SimpleResponse {
|
||||
private transient final Logger logger = LogManager.getLogger();
|
||||
public String login;
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import pro.gravit.launcher.events.request.FetchClientProfileKeyRequestEvent;
|
||||
import pro.gravit.launchserver.auth.core.User;
|
||||
import pro.gravit.launchserver.auth.core.UserSession;
|
||||
import pro.gravit.launchserver.auth.core.interfaces.session.UserSessionSupportKeys;
|
||||
import pro.gravit.launchserver.socket.Client;
|
||||
|
|
|
@ -13,20 +13,6 @@
|
|||
import java.util.Set;
|
||||
|
||||
public class ProfilesResponse extends SimpleResponse {
|
||||
@Override
|
||||
public String getType() {
|
||||
return "profiles";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(ChannelHandlerContext ctx, Client client) {
|
||||
if (server.config.protectHandler instanceof ProfilesProtectHandler && !((ProfilesProtectHandler) server.config.protectHandler).canGetProfiles(client)) {
|
||||
sendError("Access denied");
|
||||
return;
|
||||
}
|
||||
sendResult(new ProfilesRequestEvent(getListVisibleProfiles(server, client)));
|
||||
}
|
||||
|
||||
public static List<ClientProfile> getListVisibleProfiles(LaunchServer server, Client client) {
|
||||
List<ClientProfile> profileList;
|
||||
Set<ClientProfile> serverProfiles = server.getProfiles();
|
||||
|
@ -42,4 +28,18 @@ public static List<ClientProfile> getListVisibleProfiles(LaunchServer server, Cl
|
|||
}
|
||||
return profileList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "profiles";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(ChannelHandlerContext ctx, Client client) {
|
||||
if (server.config.protectHandler instanceof ProfilesProtectHandler && !((ProfilesProtectHandler) server.config.protectHandler).canGetProfiles(client)) {
|
||||
sendError("Access denied");
|
||||
return;
|
||||
}
|
||||
sendResult(new ProfilesRequestEvent(getListVisibleProfiles(server, client)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
import pro.gravit.launcher.request.Request;
|
||||
import pro.gravit.launcher.request.RequestService;
|
||||
import pro.gravit.launcher.request.WebSocketEvent;
|
||||
import pro.gravit.launcher.request.websockets.ClientWebSocketService;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
||||
public class BasicLauncherEventHandler implements RequestService.EventHandler {
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package pro.gravit.launcher.api;
|
||||
|
||||
import pro.gravit.launcher.LauncherEngine;
|
||||
import pro.gravit.launcher.profiles.ClientProfile;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
||||
public class SystemService {
|
||||
private SystemService() {
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
import pro.gravit.launcher.Launcher;
|
||||
import pro.gravit.launcher.LauncherConfig;
|
||||
import pro.gravit.launcher.LauncherEngine;
|
||||
import pro.gravit.launcher.LauncherNetworkAPI;
|
||||
import pro.gravit.launcher.client.events.client.ClientProcessBuilderCreateEvent;
|
||||
import pro.gravit.launcher.client.events.client.ClientProcessBuilderLaunchedEvent;
|
||||
import pro.gravit.launcher.client.events.client.ClientProcessBuilderParamsWrittedEvent;
|
||||
|
@ -28,7 +27,6 @@
|
|||
import java.net.SocketAddress;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package pro.gravit.launcher.utils;
|
||||
|
||||
import pro.gravit.launcher.AsyncDownloader;
|
||||
import pro.gravit.launcher.Launcher;
|
||||
import pro.gravit.launcher.LauncherEngine;
|
||||
import pro.gravit.launcher.LauncherInject;
|
||||
import pro.gravit.launcher.events.request.LauncherRequestEvent;
|
||||
import pro.gravit.launcher.request.update.LauncherRequest;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
@ -13,12 +11,10 @@
|
|||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
@ -30,9 +26,11 @@
|
|||
public class LauncherUpdater {
|
||||
@LauncherInject("launcher.certificatePinning")
|
||||
private static boolean isCertificatePinning;
|
||||
|
||||
public static void nothing() {
|
||||
|
||||
}
|
||||
|
||||
private static Path getLauncherPath() {
|
||||
Path pathToCore = IOHelper.getCodeSource(IOHelper.class);
|
||||
Path pathToApi = IOHelper.getCodeSource(LauncherRequest.class);
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package pro.gravit.launcher.utils;
|
||||
|
||||
import pro.gravit.utils.helper.JVMHelper;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
public final class NativeJVMHalt {
|
||||
public final int haltCode;
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package pro.gravit.launcher;
|
||||
|
||||
import pro.gravit.launcher.serialize.HInput;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class ClientPermissions {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package pro.gravit.launcher.profiles;
|
||||
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
import pro.gravit.utils.helper.VerifyHelper;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
public class ArchTrigger extends OptionalTrigger {
|
||||
public JVMHelper.ARCH arch;
|
||||
|
||||
@Override
|
||||
protected boolean isTriggered(OptionalFile optional, OptionalTriggerContext context) {
|
||||
return context.getJavaVersion().arch == arch;
|
||||
|
|
|
@ -28,6 +28,10 @@ public abstract class Request<R extends WebSocketEvent> implements WebSocketRequ
|
|||
public final UUID requestUUID = UUID.randomUUID();
|
||||
private transient final AtomicBoolean started = new AtomicBoolean(false);
|
||||
|
||||
public static RequestService getRequestService() {
|
||||
return requestService;
|
||||
}
|
||||
|
||||
public static void setRequestService(RequestService service) {
|
||||
requestService = service;
|
||||
if (service instanceof StdWebSocketService) {
|
||||
|
@ -35,10 +39,6 @@ public static void setRequestService(RequestService service) {
|
|||
}
|
||||
}
|
||||
|
||||
public static RequestService getRequestService() {
|
||||
return requestService;
|
||||
}
|
||||
|
||||
public static boolean isAvailable() {
|
||||
return requestService != null;
|
||||
}
|
||||
|
@ -121,18 +121,6 @@ public static RequestRestoreReport reconnect() throws Exception {
|
|||
return restore();
|
||||
}
|
||||
|
||||
public static class RequestRestoreReport {
|
||||
public final boolean legacySession;
|
||||
public final boolean refreshed;
|
||||
public final List<String> invalidExtendedTokens;
|
||||
|
||||
public RequestRestoreReport(boolean legacySession, boolean refreshed, List<String> invalidExtendedTokens) {
|
||||
this.legacySession = legacySession;
|
||||
this.refreshed = refreshed;
|
||||
this.invalidExtendedTokens = invalidExtendedTokens;
|
||||
}
|
||||
}
|
||||
|
||||
public static RequestRestoreReport restore() throws Exception {
|
||||
boolean refreshed = false;
|
||||
RestoreRequest request;
|
||||
|
@ -224,4 +212,16 @@ public interface ExtendedTokenCallback {
|
|||
String tryGetNewToken(String name);
|
||||
}
|
||||
|
||||
public static class RequestRestoreReport {
|
||||
public final boolean legacySession;
|
||||
public final boolean refreshed;
|
||||
public final List<String> invalidExtendedTokens;
|
||||
|
||||
public RequestRestoreReport(boolean legacySession, boolean refreshed, List<String> invalidExtendedTokens) {
|
||||
this.legacySession = legacySession;
|
||||
this.refreshed = refreshed;
|
||||
this.invalidExtendedTokens = invalidExtendedTokens;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,8 +6,11 @@
|
|||
|
||||
public interface RequestService {
|
||||
<T extends WebSocketEvent> CompletableFuture<T> request(Request<T> request) throws IOException;
|
||||
|
||||
void registerEventHandler(EventHandler handler);
|
||||
|
||||
void unregisterEventHandler(EventHandler handler);
|
||||
|
||||
default <T extends WebSocketEvent> T requestSync(Request<T> request) throws IOException {
|
||||
try {
|
||||
return request(request).get();
|
||||
|
|
|
@ -5,21 +5,13 @@
|
|||
import pro.gravit.launcher.events.request.LauncherRequestEvent;
|
||||
import pro.gravit.launcher.request.Request;
|
||||
import pro.gravit.launcher.request.RequestService;
|
||||
import pro.gravit.launcher.request.websockets.StdWebSocketService;
|
||||
import pro.gravit.launcher.request.websockets.WebSocketRequest;
|
||||
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 java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class LauncherRequest extends Request<LauncherRequestEvent> implements WebSocketRequest {
|
||||
public static final Path BINARY_PATH = IOHelper.getCodeSource(Launcher.class);
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
import pro.gravit.launcher.request.Request;
|
||||
import pro.gravit.launcher.request.websockets.WebSocketRequest;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
import pro.gravit.utils.helper.VerifyHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
import pro.gravit.launcher.events.request.ProfileByUsernameRequestEvent;
|
||||
import pro.gravit.launcher.request.Request;
|
||||
import pro.gravit.launcher.request.websockets.WebSocketRequest;
|
||||
import pro.gravit.utils.helper.VerifyHelper;
|
||||
|
||||
public final class ProfileByUsernameRequest extends Request<ProfileByUsernameRequestEvent> implements WebSocketRequest {
|
||||
@LauncherNetworkAPI
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
public class OfflineRequestService implements RequestService {
|
||||
private final HashSet<EventHandler> eventHandlers = new HashSet<>();
|
||||
private final Map<Class<?>, RequestProcessor<?, ?>> processors = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends WebSocketEvent> CompletableFuture<T> request(Request<T> request) throws IOException {
|
||||
|
|
|
@ -55,7 +55,6 @@ public static CompletableFuture<StdWebSocketService> initWebSockets(String addre
|
|||
}
|
||||
|
||||
|
||||
|
||||
@Deprecated
|
||||
public void registerEventHandler(ClientWebSocketService.EventHandler handler) {
|
||||
legacyEventHandlers.add(handler);
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
import pro.gravit.utils.command.CommandException;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineFactory;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Base64;
|
||||
import java.util.Collection;
|
||||
|
|
|
@ -39,6 +39,7 @@ public final class IOHelper {
|
|||
public static final FileSystem FS = FileSystems.getDefault();
|
||||
// Platform-dependent
|
||||
public static final String PLATFORM_SEPARATOR = FS.getSeparator();
|
||||
private static final Pattern PLATFORM_SEPARATOR_PATTERN = Pattern.compile(PLATFORM_SEPARATOR, Pattern.LITERAL);
|
||||
public static final boolean POSIX = FS.supportedFileAttributeViews().contains("posix") || FS.supportedFileAttributeViews().contains("Posix");
|
||||
public static final Path JVM_DIR = Paths.get(System.getProperty("java.home"));
|
||||
public static final Path HOME_DIR = Paths.get(System.getProperty("user.home"));
|
||||
|
@ -54,7 +55,6 @@ public final class IOHelper {
|
|||
private static final Set<FileVisitOption> WALK_OPTIONS = Collections.singleton(FileVisitOption.FOLLOW_LINKS);
|
||||
// Other constants
|
||||
private static final Pattern CROSS_SEPARATOR_PATTERN = Pattern.compile(CROSS_SEPARATOR, Pattern.LITERAL);
|
||||
private static final Pattern PLATFORM_SEPARATOR_PATTERN = Pattern.compile(PLATFORM_SEPARATOR, Pattern.LITERAL);
|
||||
|
||||
private IOHelper() {
|
||||
}
|
||||
|
|
|
@ -20,12 +20,10 @@ public final class JVMHelper {
|
|||
public static final OperatingSystemMXBean OPERATING_SYSTEM_MXBEAN =
|
||||
ManagementFactory.getOperatingSystemMXBean();
|
||||
public static final OS OS_TYPE = OS.byName(OPERATING_SYSTEM_MXBEAN.getName());
|
||||
// System properties
|
||||
public static final String OS_VERSION = OPERATING_SYSTEM_MXBEAN.getVersion();
|
||||
|
||||
@Deprecated
|
||||
public static final int OS_BITS = getCorrectOSArch();
|
||||
|
||||
// System properties
|
||||
public static final String OS_VERSION = OPERATING_SYSTEM_MXBEAN.getVersion();
|
||||
public static final ARCH ARCH_TYPE = getArch(System.getProperty("os.arch"));
|
||||
public static final int JVM_BITS = Integer.parseInt(System.getProperty("sun.arch.data.model"));
|
||||
public static final SecurityManager SECURITY_MANAGER = System.getSecurityManager();
|
||||
|
@ -46,16 +44,6 @@ public final class JVMHelper {
|
|||
private JVMHelper() {
|
||||
}
|
||||
|
||||
public enum ARCH {
|
||||
X86("x86"), X86_64("x86-64"), ARM64("arm64"), ARM32("arm32");
|
||||
|
||||
public final String name;
|
||||
|
||||
ARCH(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
public static ARCH getArch(String arch) {
|
||||
if (arch.equals("amd64") || arch.equals("x86-64") || arch.equals("x86_64")) return ARCH.X86_64;
|
||||
if (arch.equals("i386") || arch.equals("i686") || arch.equals("x86")) return ARCH.X86;
|
||||
|
@ -110,19 +98,16 @@ public static Class<?> firstClass(String... names) throws ClassNotFoundException
|
|||
throw new ClassNotFoundException(Arrays.toString(names));
|
||||
}
|
||||
|
||||
|
||||
public static void fullGC() {
|
||||
RUNTIME.gc();
|
||||
RUNTIME.runFinalization();
|
||||
LogHelper.debug("Used heap: %d MiB", RUNTIME.totalMemory() - RUNTIME.freeMemory() >> 20);
|
||||
}
|
||||
|
||||
|
||||
public static String[] getClassPath() {
|
||||
return System.getProperty("java.class.path").split(File.pathSeparator);
|
||||
}
|
||||
|
||||
|
||||
public static URL[] getClassPathURL() {
|
||||
String[] cp = System.getProperty("java.class.path").split(File.pathSeparator);
|
||||
URL[] list = new URL[cp.length];
|
||||
|
@ -164,35 +149,29 @@ private static int getCorrectOSArch() {
|
|||
return System.getProperty("os.arch").contains("64") ? 64 : 32;
|
||||
}
|
||||
|
||||
|
||||
public static String getEnvPropertyCaseSensitive(String name) {
|
||||
return System.getenv().get(name);
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
public static boolean isJVMMatchesSystemArch() {
|
||||
return JVM_BITS == OS_BITS;
|
||||
}
|
||||
|
||||
|
||||
public static String jvmProperty(String name, String value) {
|
||||
return String.format("-D%s=%s", name, value);
|
||||
}
|
||||
|
||||
|
||||
public static String systemToJvmProperty(String name) {
|
||||
return String.format("-D%s=%s", name, System.getProperties().getProperty(name));
|
||||
}
|
||||
|
||||
|
||||
public static void addSystemPropertyToArgs(Collection<String> args, String name) {
|
||||
String property = System.getProperty(name);
|
||||
if (property != null)
|
||||
args.add(String.format("-D%s=%s", name, property));
|
||||
}
|
||||
|
||||
|
||||
public static void verifySystemProperties(Class<?> mainClass, boolean requireSystem) {
|
||||
Locale.setDefault(Locale.US);
|
||||
// Verify class loader
|
||||
|
@ -204,6 +183,17 @@ public static void verifySystemProperties(Class<?> mainClass, boolean requireSys
|
|||
LogHelper.debug("Verifying JVM architecture");
|
||||
}
|
||||
|
||||
|
||||
public enum ARCH {
|
||||
X86("x86"), X86_64("x86-64"), ARM64("arm64"), ARM32("arm32");
|
||||
|
||||
public final String name;
|
||||
|
||||
ARCH(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
public enum OS {
|
||||
MUSTDIE("mustdie"), LINUX("linux"), MACOSX("macosx");
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
public class JavaHelper {
|
||||
private static List<JavaVersion> javaVersionsCache;
|
||||
|
||||
public static Path tryGetOpenJFXPath(Path jvmDir) {
|
||||
String dirName = jvmDir.getFileName().toString();
|
||||
Path parent = jvmDir.getParent();
|
||||
|
|
Loading…
Reference in a new issue