diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerRuntimeConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerRuntimeConfig.java index 434df53f..fdc4eb42 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerRuntimeConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerRuntimeConfig.java @@ -6,6 +6,7 @@ public class LaunchServerRuntimeConfig { public String clientToken; public String oemUnlockKey; + public String registerApiKey; public void verify() { if (clientToken == null) LogHelper.error("[RuntimeConfig] clientToken must not be null"); @@ -13,5 +14,6 @@ public void verify() { public void reset() { clientToken = SecurityHelper.randomStringToken(); + registerApiKey = SecurityHelper.randomStringToken(); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java index e939c68d..8d149f62 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java @@ -31,13 +31,7 @@ import pro.gravit.launchserver.socket.response.admin.AddLogListenerResponse; import pro.gravit.launchserver.socket.response.admin.ExecCommandResponse; import pro.gravit.launchserver.socket.response.admin.ProxyCommandResponse; -import pro.gravit.launchserver.socket.response.auth.AuthResponse; -import pro.gravit.launchserver.socket.response.auth.CheckServerResponse; -import pro.gravit.launchserver.socket.response.auth.GetAvailabilityAuthResponse; -import pro.gravit.launchserver.socket.response.auth.JoinServerResponse; -import pro.gravit.launchserver.socket.response.auth.ProfilesResponse; -import pro.gravit.launchserver.socket.response.auth.RestoreSessionResponse; -import pro.gravit.launchserver.socket.response.auth.SetProfileResponse; +import pro.gravit.launchserver.socket.response.auth.*; import pro.gravit.launchserver.socket.response.profile.BatchProfileByUsername; import pro.gravit.launchserver.socket.response.profile.ProfileByUUIDResponse; import pro.gravit.launchserver.socket.response.profile.ProfileByUsername; @@ -183,6 +177,7 @@ public void registerResponses() { registerResponse("verifySecureToken", VerifySecureTokenResponse.class); registerResponse("getAvailabilityAuth", GetAvailabilityAuthResponse.class); registerResponse("proxy", ProxyCommandResponse.class); + registerResponse("register", RegisterResponse.class); } public void sendObject(ChannelHandlerContext ctx, Object obj) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/SimpleResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/SimpleResponse.java index cd90c345..783daaaf 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/SimpleResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/SimpleResponse.java @@ -31,9 +31,4 @@ public void sendError(String errorMessage) { event.requestUUID = requestUUID; service.sendObject(ctx, event); } - - @Override - public void execute(ChannelHandlerContext ctx, Client client) throws Exception { - - } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RegisterResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RegisterResponse.java new file mode 100644 index 00000000..c1833660 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RegisterResponse.java @@ -0,0 +1,42 @@ +package pro.gravit.launchserver.socket.response.auth; + +import io.netty.channel.ChannelHandlerContext; +import pro.gravit.launchserver.dao.User; +import pro.gravit.launchserver.socket.Client; +import pro.gravit.launchserver.socket.response.SimpleResponse; + +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; +import java.util.UUID; + +public class RegisterResponse extends SimpleResponse { + public String login; + public String password; + public byte[] verifyHash; + @Override + public void execute(ChannelHandlerContext ctx, Client client) throws Exception + { + byte[] normalHash = registerHash(login, server.runtime.registerApiKey); + if(!( client.isAuth && client.permissions.canAdmin ) && !Arrays.equals(normalHash, verifyHash)) + { + sendError("Hash invalid"); + return; + } + User user = new User(); + user.username = login; + user.setPassword(password); + user.uuid = UUID.randomUUID(); + server.userService.saveUser(user); + } + @Override + public String getType() { + return "register"; + } + public static byte[] registerHash(String login, String secret) throws NoSuchAlgorithmException { + String text = login.concat("+").concat(secret); + MessageDigest digest = MessageDigest.getInstance("SHA-256"); + return digest.digest(text.getBytes(StandardCharsets.UTF_8)); + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/RegisterRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/RegisterRequestEvent.java new file mode 100644 index 00000000..f08506c8 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/RegisterRequestEvent.java @@ -0,0 +1,10 @@ +package pro.gravit.launcher.events.request; + +import pro.gravit.launcher.events.RequestEvent; + +public class RegisterRequestEvent extends RequestEvent { + @Override + public String getType() { + return "register"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java index f0e2ff5b..7e2217cc 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -12,24 +12,7 @@ import com.google.gson.GsonBuilder; import pro.gravit.launcher.events.ExceptionEvent; -import pro.gravit.launcher.events.request.AuthRequestEvent; -import pro.gravit.launcher.events.request.BatchProfileByUsernameRequestEvent; -import pro.gravit.launcher.events.request.CheckServerRequestEvent; -import pro.gravit.launcher.events.request.ErrorRequestEvent; -import pro.gravit.launcher.events.request.ExecCommandRequestEvent; -import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent; -import pro.gravit.launcher.events.request.GetSecureTokenRequestEvent; -import pro.gravit.launcher.events.request.JoinServerRequestEvent; -import pro.gravit.launcher.events.request.LauncherRequestEvent; -import pro.gravit.launcher.events.request.LogEvent; -import pro.gravit.launcher.events.request.ProfileByUUIDRequestEvent; -import pro.gravit.launcher.events.request.ProfileByUsernameRequestEvent; -import pro.gravit.launcher.events.request.ProfilesRequestEvent; -import pro.gravit.launcher.events.request.RestoreSessionRequestEvent; -import pro.gravit.launcher.events.request.SetProfileRequestEvent; -import pro.gravit.launcher.events.request.UpdateListRequestEvent; -import pro.gravit.launcher.events.request.UpdateRequestEvent; -import pro.gravit.launcher.events.request.VerifySecureTokenRequestEvent; +import pro.gravit.launcher.events.request.*; import pro.gravit.launcher.hasher.HashedEntry; import pro.gravit.launcher.hasher.HashedEntryAdapter; import pro.gravit.launcher.request.ResultInterface; @@ -138,6 +121,7 @@ public void registerResults() { registerResult("cmdExec", ExecCommandRequestEvent.class); registerResult("getAvailabilityAuth", GetAvailabilityAuthRequestEvent.class); registerResult("exception", ExceptionEvent.class); + registerResult("register", RegisterRequestEvent.class); } public void registerHandler(EventHandler eventHandler) {