mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] Портирование AuthRequest/LauncherRequest
This commit is contained in:
parent
40fe55a46d
commit
98354345a0
7 changed files with 110 additions and 53 deletions
|
@ -75,7 +75,7 @@ public void registerResponses() {
|
|||
registerResponse("checkServer", CheckServerResponse.class);
|
||||
registerResponse("joinServer", JoinServerResponse.class);
|
||||
registerResponse("profiles", ProfilesResponse.class);
|
||||
registerResponse("launcherUpdate", LauncherResponse.class);
|
||||
registerResponse("launcher", LauncherResponse.class);
|
||||
registerResponse("updateList", UpdateListResponse.class);
|
||||
registerResponse("cmdExec", UpdateListResponse.class);
|
||||
}
|
||||
|
@ -99,14 +99,17 @@ public void sendEvent(EventResult obj) {
|
|||
channels.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj)));
|
||||
}
|
||||
|
||||
public static class ErrorResult {
|
||||
public static class ErrorResult implements ResultInterface {
|
||||
public ErrorResult(String error) {
|
||||
this.error = error;
|
||||
this.type = "requestError";
|
||||
}
|
||||
|
||||
public final String error;
|
||||
public final String type;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
||||
public static class SuccessResult {
|
||||
|
@ -119,15 +122,18 @@ public SuccessResult(String requesttype) {
|
|||
public final String type;
|
||||
}
|
||||
|
||||
public static class EventResult {
|
||||
public static class EventResult implements ResultInterface {
|
||||
public EventResult() {
|
||||
this.type = "event";
|
||||
|
||||
}
|
||||
|
||||
public final String type;
|
||||
@Override
|
||||
public String getType() {
|
||||
return "event";
|
||||
}
|
||||
}
|
||||
|
||||
public static class ExceptionResult {
|
||||
public static class ExceptionResult implements ResultInterface {
|
||||
public ExceptionResult(Exception e) {
|
||||
this.message = e.getMessage();
|
||||
this.clazz = e.getClass().getName();
|
||||
|
@ -137,5 +143,10 @@ public ExceptionResult(Exception e) {
|
|||
public final String message;
|
||||
public final String clazz;
|
||||
public final String type;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "exception";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,11 @@
|
|||
import ru.gravit.launchserver.socket.websocket.WebSocketService;
|
||||
import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface;
|
||||
import ru.gravit.utils.helper.IOHelper;
|
||||
import ru.gravit.utils.helper.SecurityHelper;
|
||||
import ru.gravit.utils.helper.VerifyHelper;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -25,6 +28,7 @@ public class AuthResponse implements JsonResponseInterface {
|
|||
public String customText;
|
||||
|
||||
public String password;
|
||||
public byte[] encryptedPassword;
|
||||
|
||||
public AuthResponse(String login, String password, int authid, OshiHWID hwid) {
|
||||
this.login = login;
|
||||
|
@ -59,6 +63,15 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client
|
|||
AuthProvider.authError("Don't skip Launcher Update");
|
||||
return;
|
||||
}
|
||||
if(password == null)
|
||||
{
|
||||
try {
|
||||
password = IOHelper.decode(SecurityHelper.newRSADecryptCipher(LaunchServer.server.privateKey).
|
||||
doFinal(encryptedPassword));
|
||||
} catch (IllegalBlockSizeException | BadPaddingException ignored) {
|
||||
throw new AuthException("Password decryption error");
|
||||
}
|
||||
}
|
||||
clientData.permissions = LaunchServer.server.config.permissionsHandler.getPermissions(login);
|
||||
if(authType == ConnectTypes.BOT && !clientData.permissions.canBot)
|
||||
{
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
public class LauncherResponse implements JsonResponseInterface {
|
||||
public Version version;
|
||||
public String hash;
|
||||
public byte[] digest;
|
||||
public int launcher_type;
|
||||
//REPLACED TO REAL URL
|
||||
public static final String JAR_URL = "http://localhost:9752/Launcher.jar";
|
||||
|
@ -21,12 +22,16 @@ public class LauncherResponse implements JsonResponseInterface {
|
|||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "launcherUpdate";
|
||||
return "launcher";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) {
|
||||
byte[] bytes = Base64.getDecoder().decode(hash);
|
||||
byte[] bytes;
|
||||
if(hash != null)
|
||||
bytes = Base64.getDecoder().decode(hash);
|
||||
else
|
||||
bytes = digest;
|
||||
if (launcher_type == 1) // JAR
|
||||
{
|
||||
byte[] hash = LaunchServer.server.launcherBinary.getBytes().getDigest();
|
||||
|
|
|
@ -29,9 +29,9 @@ public static void requestError(String message) throws RequestException {
|
|||
}
|
||||
|
||||
@LauncherAPI
|
||||
protected final LauncherConfig config;
|
||||
protected transient final LauncherConfig config;
|
||||
|
||||
private final AtomicBoolean started = new AtomicBoolean(false);
|
||||
private transient final AtomicBoolean started = new AtomicBoolean(false);
|
||||
|
||||
@LauncherAPI
|
||||
protected Request() {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import ru.gravit.launcher.profiles.PlayerProfile;
|
||||
import ru.gravit.launcher.request.Request;
|
||||
import ru.gravit.launcher.request.RequestType;
|
||||
import ru.gravit.launcher.request.websockets.LegacyRequestBridge;
|
||||
import ru.gravit.launcher.request.websockets.RequestInterface;
|
||||
import ru.gravit.launcher.serialize.HInput;
|
||||
import ru.gravit.launcher.serialize.HOutput;
|
||||
|
@ -14,7 +15,7 @@
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class AuthRequest extends Request<AuthRequestEvent> {
|
||||
public final class AuthRequest extends Request<AuthRequestEvent> implements RequestInterface {
|
||||
|
||||
private final String login;
|
||||
|
||||
|
@ -24,51 +25,55 @@ public final class AuthRequest extends Request<AuthRequestEvent> {
|
|||
private final String customText;
|
||||
|
||||
@LauncherAPI
|
||||
public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword, HWID hwid) {
|
||||
public AuthRequest(LauncherConfig config, String login, byte[] password, HWID hwid) {
|
||||
super(config);
|
||||
this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty");
|
||||
this.encryptedPassword = encryptedPassword.clone();
|
||||
this.encryptedPassword = password.clone();
|
||||
this.hwid = hwid;
|
||||
customText = "";
|
||||
auth_id = 0;
|
||||
}
|
||||
@LauncherAPI
|
||||
public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword, HWID hwid, String customText) {
|
||||
public AuthRequest(LauncherConfig config, String login, byte[] password, HWID hwid, String customText) {
|
||||
super(config);
|
||||
this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty");
|
||||
this.encryptedPassword = encryptedPassword.clone();
|
||||
this.encryptedPassword = password.clone();
|
||||
this.hwid = hwid;
|
||||
this.customText = customText;
|
||||
auth_id = 0;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword, HWID hwid, int auth_id) {
|
||||
public AuthRequest(LauncherConfig config, String login, byte[] password, HWID hwid, int auth_id) {
|
||||
super(config);
|
||||
this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty");
|
||||
this.encryptedPassword = encryptedPassword.clone();
|
||||
this.encryptedPassword = password.clone();
|
||||
this.hwid = hwid;
|
||||
this.auth_id = auth_id;
|
||||
customText = "";
|
||||
}
|
||||
@LauncherAPI
|
||||
public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword, HWID hwid, String customText, int auth_id) {
|
||||
public AuthRequest(LauncherConfig config, String login, byte[] password, HWID hwid, String customText, int auth_id) {
|
||||
super(config);
|
||||
this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty");
|
||||
this.encryptedPassword = encryptedPassword.clone();
|
||||
this.encryptedPassword = password.clone();
|
||||
this.hwid = hwid;
|
||||
this.auth_id = auth_id;
|
||||
this.customText = customText;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public AuthRequest(String login, byte[] encryptedPassword, HWID hwid) {
|
||||
this(null, login, encryptedPassword, hwid);
|
||||
public AuthRequest(String login, byte[] password, HWID hwid) {
|
||||
this(null, login, password, hwid);
|
||||
}
|
||||
@Override
|
||||
public AuthRequestEvent requestWebSockets() throws Exception
|
||||
{
|
||||
return (AuthRequestEvent) LegacyRequestBridge.sendRequest(this);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public AuthRequest(String login, byte[] encryptedPassword, HWID hwid, int auth_id) {
|
||||
this(null, login, encryptedPassword, hwid, auth_id);
|
||||
public AuthRequest(String login, byte[] password, HWID hwid, int auth_id) {
|
||||
this(null, login, password, hwid, auth_id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -115,4 +120,9 @@ protected AuthRequestEvent requestDo(HInput input, HOutput output) throws IOExce
|
|||
ClientPermissions permissions = new ClientPermissions(input);
|
||||
return new AuthRequestEvent(pp, accessToken, permissions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "auth";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,12 @@
|
|||
import ru.gravit.launcher.Launcher;
|
||||
import ru.gravit.launcher.LauncherAPI;
|
||||
import ru.gravit.launcher.LauncherConfig;
|
||||
import ru.gravit.launcher.LauncherNetworkAPI;
|
||||
import ru.gravit.launcher.events.request.LauncherRequestEvent;
|
||||
import ru.gravit.launcher.request.Request;
|
||||
import ru.gravit.launcher.request.RequestType;
|
||||
import ru.gravit.launcher.request.websockets.LegacyRequestBridge;
|
||||
import ru.gravit.launcher.request.websockets.RequestInterface;
|
||||
import ru.gravit.launcher.serialize.HInput;
|
||||
import ru.gravit.launcher.serialize.HOutput;
|
||||
import ru.gravit.utils.helper.IOHelper;
|
||||
|
@ -17,27 +21,11 @@
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class LauncherRequest extends Request<LauncherRequest.Result> {
|
||||
public static final class Result {
|
||||
private final byte[] binary;
|
||||
private final byte[] digest;
|
||||
|
||||
public Result(byte[] binary, byte[] sign) {
|
||||
this.binary = binary == null ? null : binary.clone();
|
||||
this.digest = sign.clone();
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public byte[] getBinary() {
|
||||
return binary == null ? null : binary.clone();
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public byte[] getDigest() {
|
||||
return digest.clone();
|
||||
}
|
||||
}
|
||||
|
||||
public final class LauncherRequest extends Request<LauncherRequestEvent> implements RequestInterface {
|
||||
@LauncherNetworkAPI
|
||||
public byte[] digest;
|
||||
@LauncherNetworkAPI
|
||||
public int launcher_type = EXE_BINARY ? 2 : 1;
|
||||
@LauncherAPI
|
||||
public static final Path BINARY_PATH = IOHelper.getCodeSource(Launcher.class);
|
||||
|
||||
|
@ -45,7 +33,7 @@ public byte[] getDigest() {
|
|||
public static final boolean EXE_BINARY = IOHelper.hasExtension(BINARY_PATH, "exe");
|
||||
|
||||
@LauncherAPI
|
||||
public static void update(LauncherConfig config, Result result) throws IOException {
|
||||
public static void update(LauncherConfig config, LauncherRequestEvent result) throws IOException {
|
||||
List<String> args = new ArrayList<>(8);
|
||||
args.add(IOHelper.resolveJavaBin(null).toString());
|
||||
if (LogHelper.isDebugEnabled())
|
||||
|
@ -71,9 +59,21 @@ public LauncherRequest() {
|
|||
this(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LauncherRequestEvent requestWebSockets() throws Exception
|
||||
{
|
||||
return (LauncherRequestEvent) LegacyRequestBridge.sendRequest(this);
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
public LauncherRequest(LauncherConfig config) {
|
||||
super(config);
|
||||
Path launcherPath = IOHelper.getCodeSource(LauncherRequest.class);
|
||||
try {
|
||||
digest = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA512, launcherPath);
|
||||
} catch (IOException e) {
|
||||
LogHelper.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -82,9 +82,7 @@ public Integer getLegacyType() {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Result requestDo(HInput input, HOutput output) throws Exception {
|
||||
Path launcherPath = IOHelper.getCodeSource(LauncherRequest.class);
|
||||
byte[] digest = SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA512, launcherPath);
|
||||
protected LauncherRequestEvent requestDo(HInput input, HOutput output) throws Exception {
|
||||
output.writeBoolean(EXE_BINARY);
|
||||
output.writeByteArray(digest, 0);
|
||||
output.flush();
|
||||
|
@ -94,11 +92,16 @@ protected Result requestDo(HInput input, HOutput output) throws Exception {
|
|||
boolean shouldUpdate = input.readBoolean();
|
||||
if (shouldUpdate) {
|
||||
byte[] binary = input.readByteArray(0);
|
||||
Result result = new Result(binary, digest);
|
||||
LauncherRequestEvent result = new LauncherRequestEvent(binary, digest);
|
||||
update(Launcher.getConfig(), result);
|
||||
}
|
||||
|
||||
// Return request result
|
||||
return new Result(null, digest);
|
||||
return new LauncherRequestEvent(null, digest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "launcher";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,10 @@ public class LauncherRequestEvent implements EventInterface, ResultInterface {
|
|||
private static final UUID uuid = UUID.fromString("d54cc12a-4f59-4f23-9b10-f527fdd2e38f");
|
||||
@LauncherNetworkAPI
|
||||
public String url;
|
||||
@LauncherNetworkAPI
|
||||
public byte[] digest;
|
||||
@LauncherNetworkAPI
|
||||
public byte[] binary;
|
||||
|
||||
public LauncherRequestEvent(boolean needUpdate, String url) {
|
||||
this.needUpdate = needUpdate;
|
||||
|
@ -17,6 +21,17 @@ public LauncherRequestEvent(boolean needUpdate, String url) {
|
|||
}
|
||||
|
||||
public boolean needUpdate;
|
||||
|
||||
public LauncherRequestEvent(boolean b, byte[] digest) {
|
||||
this.needUpdate = b;
|
||||
this.digest = digest;
|
||||
}
|
||||
|
||||
public LauncherRequestEvent(byte[] binary, byte[] digest) { //Legacy support constructor
|
||||
this.binary = binary;
|
||||
this.digest = digest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
|
|
Loading…
Reference in a new issue