From 30645741f4a6056f05871dcc19cc509d21225f0e Mon Sep 17 00:00:00 2001 From: Gravit Date: Thu, 4 Apr 2019 15:16:23 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD=D0=B0=20ServerWrapper=20=D1=87?= =?UTF-8?q?=D0=B0=D1=81=D1=82=D1=8C=20=D0=B2=D0=B5=D0=B1=D1=81=D0=BE=D0=BA?= =?UTF-8?q?=D0=B5=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../websocket/json/auth/AuthResponse.java | 2 ++ .../json/auth/CheckServerResponse.java | 3 ++- .../json/auth/JoinServerResponse.java | 1 + .../websocket/json/auth/ProfilesResponse.java | 2 +- .../launcher/request/auth/AuthRequest.java | 27 +++++++++++++++++-- .../websockets/JsonRequestAdapter.java | 5 ++++ .../request/websockets/JsonResultAdapter.java | 5 ++++ .../gravit/launcher/server/ServerWrapper.java | 22 +++++++++++++++ .../ru/gravit/launcher/LauncherConfig.java | 2 +- .../request/CheckServerRequestEvent.java | 2 +- 10 files changed, 65 insertions(+), 6 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java index 7f8b0818..676c2d6a 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java @@ -16,6 +16,7 @@ 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.LogHelper; import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.VerifyHelper; @@ -121,6 +122,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client result.session = clientData.session; } result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server, uuid, aresult.username, client, clientData.auth.textureProvider); + LogHelper.debug("Auth: %s accessToken %s uuid: %s", login, result.accessToken, uuid.toString()); service.sendObject(ctx, result); } catch (AuthException | HWIDException e) { service.sendObject(ctx, new ErrorRequestEvent(e.getMessage())); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java index e66e2263..acbb98ac 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java @@ -28,6 +28,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client result.uuid = pClient.auth.handler.checkServer(username, serverID); if (result.uuid != null) result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server, result.uuid, username, client, pClient.auth.textureProvider); + LogHelper.debug("checkServer: %s uuid: %s serverID: %s", result.playerProfile.username, result.uuid.toString(), serverID); } catch (AuthException e) { service.sendObject(ctx, new ErrorRequestEvent(e.getMessage())); return; @@ -36,7 +37,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client service.sendObject(ctx, new ErrorRequestEvent("Internal authHandler error")); return; } - service.sendObject(ctx, new CheckServerRequestEvent()); + service.sendObject(ctx, result); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/JoinServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/JoinServerResponse.java index e676ffd0..c5ff5234 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/JoinServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/JoinServerResponse.java @@ -30,6 +30,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client success = LaunchServer.server.config.getAuthProviderPair().handler.joinServer(username, accessToken, serverID); } else success = client.auth.handler.joinServer(username, accessToken, serverID); + LogHelper.debug("joinServer: %s accessToken: %s serverID: %s", username, accessToken, serverID); } catch (AuthException e) { service.sendObject(ctx, new ErrorRequestEvent(e.getMessage())); return; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java index 592928f5..a4d1a24b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java @@ -19,7 +19,7 @@ public String getType() { @Override public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { - if (!client.checkSign) { + if (!client.checkSign && !client.isAuth) { service.sendObject(ctx, new ErrorRequestEvent("Access denied")); return; } diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java index 562f41b8..ace13f29 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java @@ -16,14 +16,24 @@ import java.io.IOException; public final class AuthRequest extends Request implements RequestInterface { - + @LauncherNetworkAPI private final String login; - + @LauncherNetworkAPI private final byte[] encryptedPassword; + @LauncherNetworkAPI private final String auth_id; + @LauncherNetworkAPI private final HWID hwid; + @LauncherNetworkAPI private final String customText; + @LauncherNetworkAPI private final boolean getSession; + @LauncherNetworkAPI + private final ConnectTypes authType; + + public enum ConnectTypes { + SERVER, CLIENT, BOT + } @LauncherAPI public AuthRequest(LauncherConfig config, String login, byte[] password, HWID hwid) { @@ -34,6 +44,7 @@ public AuthRequest(LauncherConfig config, String login, byte[] password, HWID hw customText = ""; auth_id = ""; getSession = true; + authType = ConnectTypes.CLIENT; } @LauncherAPI @@ -45,6 +56,7 @@ public AuthRequest(LauncherConfig config, String login, byte[] password, HWID hw this.auth_id = auth_id; customText = ""; getSession = true; + authType = ConnectTypes.CLIENT; } @LauncherAPI @@ -56,6 +68,7 @@ public AuthRequest(LauncherConfig config, String login, byte[] password, HWID hw this.auth_id = auth_id; this.customText = customText; getSession = true; + authType = ConnectTypes.CLIENT; } @LauncherAPI @@ -63,6 +76,16 @@ public AuthRequest(String login, byte[] password, HWID hwid) { this(null, login, password, hwid); } + public AuthRequest(String login, byte[] encryptedPassword, String auth_id, ConnectTypes authType) { + this.login = login; + this.encryptedPassword = encryptedPassword; + this.auth_id = auth_id; + this.authType = authType; + this.hwid = null; + this.customText = ""; + this.getSession = false; + } + @Override public AuthRequestEvent requestWebSockets() throws Exception { return (AuthRequestEvent) LegacyRequestBridge.sendRequest(this); diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonRequestAdapter.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonRequestAdapter.java index be546079..f94fa03d 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonRequestAdapter.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonRequestAdapter.java @@ -1,6 +1,7 @@ package ru.gravit.launcher.request.websockets; import com.google.gson.*; +import ru.gravit.utils.helper.LogHelper; import java.lang.reflect.Type; @@ -16,6 +17,10 @@ public JsonRequestAdapter(ClientWebSocketService service) { public RequestInterface deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); Class cls = service.getRequestClass(typename); + if(cls == null) + { + LogHelper.error("Request type %s not found", typename); + } return (RequestInterface) context.deserialize(json, cls); diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonResultAdapter.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonResultAdapter.java index 1ddd605d..0eea6a7b 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonResultAdapter.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonResultAdapter.java @@ -2,6 +2,7 @@ import com.google.gson.*; import ru.gravit.launcher.request.ResultInterface; +import ru.gravit.utils.helper.LogHelper; import java.lang.reflect.Type; @@ -17,6 +18,10 @@ public JsonResultAdapter(ClientWebSocketService service) { public ResultInterface deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); Class cls = service.getResultClass(typename); + if(cls == null) + { + LogHelper.error("Result type %s not found", typename); + } return (ResultInterface) context.deserialize(json, cls); diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java index d74847a7..92898701 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java @@ -7,6 +7,7 @@ import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.events.request.ProfilesRequestEvent; import ru.gravit.launcher.profiles.ClientProfile; +import ru.gravit.launcher.request.auth.AuthRequest; import ru.gravit.launcher.request.auth.AuthServerRequest; import ru.gravit.launcher.request.update.ProfilesRequest; import ru.gravit.launcher.server.setup.ServerWrapperSetup; @@ -51,7 +52,13 @@ public ServerWrapper(Type type, Path configPath) { public boolean auth() { try { LauncherConfig cfg = Launcher.getConfig(); + if(!config.websocket.enabled) permissions = new AuthServerRequest(cfg, config.login, SecurityHelper.newRSAEncryptCipher(cfg.publicKey).doFinal(IOHelper.encode(config.password)), config.auth_id, config.title).request(); + else + { + AuthRequest request = new AuthRequest(config.login, SecurityHelper.newRSAEncryptCipher(cfg.publicKey).doFinal(IOHelper.encode(config.password)), config.auth_id, AuthRequest.ConnectTypes.SERVER); + permissions = request.request().permissions; + } ProfilesRequestEvent result = new ProfilesRequest(cfg).request(); for (ClientProfile p : result.profiles) { LogHelper.debug("Get profile: %s", p.getTitle()); @@ -184,6 +191,12 @@ public void updateLauncherConfig() { LauncherConfig cfg = null; try { cfg = new LauncherConfig(config.address, config.port, SecurityHelper.toPublicRSAKey(IOHelper.read(publicKeyFile)), new HashMap<>(), config.projectname); + if(config.websocket != null && config.websocket.enabled) + { + cfg.isNettyEnabled = true; + cfg.nettyAddress = config.websocket.address; + cfg.nettyPort = 1111; + } } catch (InvalidKeySpecException | IOException e) { LogHelper.error(e); } @@ -216,6 +229,9 @@ public Config getDefaultConfig() { newConfig.stopOnError = true; newConfig.reconnectCount = 10; newConfig.reconnectSleep = 1000; + newConfig.websocket = new WebSocketConf(); + newConfig.websocket.address = "ws://localhost:9274/api"; + newConfig.websocket.enabled = false; newConfig.env = LauncherConfig.LauncherEnvironment.STD; return newConfig; } @@ -229,6 +245,7 @@ public static final class Config { public String title; public String projectname; public String address; + public WebSocketConf websocket; public int port; public int reconnectCount; public int reconnectSleep; @@ -246,6 +263,11 @@ public static final class Config { public String auth_id = ""; public LauncherConfig.LauncherEnvironment env; } + public static final class WebSocketConf + { + public boolean enabled; + public String address; + } public ClientProfile profile; } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java index fa0202e6..cffa379a 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java @@ -38,7 +38,7 @@ public static AutogenConfig getAutogenConfig() { public final boolean isUsingWrapper; public final boolean isDownloadJava; public final boolean isWarningMissArchJava; - public final boolean isNettyEnabled; + public boolean isNettyEnabled; public final String guardLicenseName; public final String guardLicenseKey; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/CheckServerRequestEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/CheckServerRequestEvent.java index cbe1bd21..02d2ad86 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/events/request/CheckServerRequestEvent.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/CheckServerRequestEvent.java @@ -28,6 +28,6 @@ public UUID getUUID() { @Override public String getType() { - return "checkServe"; + return "checkServer"; } }