mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
[FEATURE] Регистрация в лаунчере
This commit is contained in:
parent
494e714bb3
commit
5df618787f
6 changed files with 58 additions and 30 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -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";
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue