mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] AuthProvider preAuth
This commit is contained in:
parent
4c6360b8af
commit
f9129c28d2
4 changed files with 35 additions and 2 deletions
|
@ -46,6 +46,11 @@ public AuthHandler getAccociateHandler(int this_position) {
|
|||
|
||||
public abstract AuthProviderResult auth(String login, String password, String ip) throws Exception;
|
||||
|
||||
public void preAuth(String login, String password, String customText, String ip) throws Exception
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void close() throws IOException;
|
||||
|
||||
|
|
|
@ -36,10 +36,11 @@ public AuthResponse(LaunchServer server, long session, HInput input, HOutput out
|
|||
}
|
||||
|
||||
public static class AuthContext {
|
||||
public AuthContext(long session, String login, int password_lenght, String client, String hwid, boolean isServerAuth) {
|
||||
public AuthContext(long session, String login, int password_lenght, String customText, String client, String hwid, boolean isServerAuth) {
|
||||
this.session = session;
|
||||
this.login = login;
|
||||
this.password_lenght = password_lenght;
|
||||
this.customText = customText;
|
||||
this.client = client;
|
||||
this.hwid = hwid;
|
||||
this.isServerAuth = isServerAuth;
|
||||
|
@ -50,6 +51,7 @@ public AuthContext(long session, String login, int password_lenght, String clien
|
|||
public int password_lenght; //Use AuthProvider for get password
|
||||
public String client;
|
||||
public String hwid;
|
||||
public String customText;
|
||||
public boolean isServerAuth;
|
||||
}
|
||||
|
||||
|
@ -64,6 +66,7 @@ public void reply() throws Exception {
|
|||
String hwid_str = input.readString(SerializeLimits.MAX_HWID_STR);
|
||||
if (auth_id + 1 > server.config.authProvider.length || auth_id < 0) auth_id = 0;
|
||||
byte[] encryptedPassword = input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH);
|
||||
String customText = input.readString(SerializeLimits.MAX_CUSTOM_TEXT);
|
||||
// Decrypt password
|
||||
String password;
|
||||
try {
|
||||
|
@ -80,7 +83,7 @@ public void reply() throws Exception {
|
|||
AuthProvider provider = server.config.authProvider[auth_id];
|
||||
Client clientData = server.sessionManager.getClient(session);
|
||||
clientData.type = Client.Type.USER;
|
||||
AuthContext context = new AuthContext(session, login, password.length(), client, hwid_str, false);
|
||||
AuthContext context = new AuthContext(session, login, password.length(), customText, client, hwid_str, false);
|
||||
try {
|
||||
server.authHookManager.preHook(context, clientData);
|
||||
if (server.limiter.isLimit(ip)) {
|
||||
|
@ -90,6 +93,7 @@ public void reply() throws Exception {
|
|||
if (!clientData.checkSign) {
|
||||
throw new AuthException("You must using checkLauncher");
|
||||
}
|
||||
provider.preAuth(login,password,customText,ip);
|
||||
result = provider.auth(login, password, ip);
|
||||
if (!VerifyHelper.isValidUsername(result.username)) {
|
||||
AuthProvider.authError(String.format("Illegal result: '%s'", result.username));
|
||||
|
|
|
@ -34,6 +34,7 @@ private Result(PlayerProfile pp, String accessToken, ClientPermissions permissio
|
|||
private final byte[] encryptedPassword;
|
||||
private final int auth_id;
|
||||
private final HWID hwid;
|
||||
private final String customText;
|
||||
|
||||
@LauncherAPI
|
||||
public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword, HWID hwid) {
|
||||
|
@ -41,6 +42,16 @@ public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword
|
|||
this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty");
|
||||
this.encryptedPassword = encryptedPassword.clone();
|
||||
this.hwid = hwid;
|
||||
customText = "";
|
||||
auth_id = 0;
|
||||
}
|
||||
@LauncherAPI
|
||||
public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword, HWID hwid, String customText) {
|
||||
super(config);
|
||||
this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty");
|
||||
this.encryptedPassword = encryptedPassword.clone();
|
||||
this.hwid = hwid;
|
||||
this.customText = customText;
|
||||
auth_id = 0;
|
||||
}
|
||||
|
||||
|
@ -51,6 +62,16 @@ public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword
|
|||
this.encryptedPassword = encryptedPassword.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) {
|
||||
super(config);
|
||||
this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty");
|
||||
this.encryptedPassword = encryptedPassword.clone();
|
||||
this.hwid = hwid;
|
||||
this.auth_id = auth_id;
|
||||
this.customText = customText;
|
||||
}
|
||||
|
||||
@LauncherAPI
|
||||
|
@ -97,6 +118,7 @@ protected Result requestDo(HInput input, HOutput output) throws IOException {
|
|||
//output.writeLong(0);
|
||||
//output.writeLong(0);
|
||||
output.writeByteArray(encryptedPassword, SecurityHelper.CRYPTO_MAX_LENGTH);
|
||||
output.writeString(customText, SerializeLimits.MAX_CUSTOM_TEXT);
|
||||
output.flush();
|
||||
|
||||
// Read UUID and access token
|
||||
|
|
|
@ -6,6 +6,8 @@ public class SerializeLimits {
|
|||
@LauncherAPI
|
||||
public static final int MAX_LOGIN = 1024;
|
||||
@LauncherAPI
|
||||
public static final int MAX_CUSTOM_TEXT = 512;
|
||||
@LauncherAPI
|
||||
public static final int MAX_CLIENT = 128;
|
||||
@LauncherAPI
|
||||
public static final int MAX_SERVERID = 128;
|
||||
|
|
Loading…
Reference in a new issue