[FEATURE] Новые типы пароля для поддержки 2FA

This commit is contained in:
Gravit 2020-08-27 22:48:46 +07:00
parent 1362d71788
commit 886c085572
No known key found for this signature in database
GPG key ID: 98A079490768CCE5
8 changed files with 55 additions and 32 deletions

View file

@ -36,8 +36,16 @@ public final class ServerPinger {
private Instant cacheTime = null;
public ServerPinger(ClientProfile profile) {
this.address = Objects.requireNonNull(profile.getServerSocketAddress(), "address");
this.version = Objects.requireNonNull(profile.getVersion(), "version");
this(profile.getDefaultServerProfile(), profile.getVersion());
}
public ServerPinger(ClientProfile.ServerProfile profile, ClientProfile.Version version)
{
if(profile == null)
{
throw new NullPointerException("ServerProfile null");
}
this.address = profile.toSocketAddress();
this.version = Objects.requireNonNull(version, "version");
}
private static String readUTF16String(HInput input) throws IOException {

View file

@ -8,7 +8,7 @@
import java.util.UUID;
public class AuthRequestEvent extends RequestEvent {
public static final String TWO_FACTOR_NEED_ERROR_MESSAGE = "auth.require2fa";
@LauncherNetworkAPI
public ClientPermissions permissions;
@LauncherNetworkAPI

View file

@ -1,15 +0,0 @@
package pro.gravit.launcher.hwid;
@Deprecated
public interface HWID {
int getLevel(); //Уровень доверия, насколько уникальные значения
int getAntiLevel(); //Уровень лживости, насколько фальшивые значения
int compare(HWID hwid);
boolean isNull();
void normalize();
}

View file

@ -78,6 +78,10 @@ public static class ServerProfile
public String serverAddress;
public int serverPort;
public boolean isDefault = true;
public InetSocketAddress toSocketAddress()
{
return InetSocketAddress.createUnresolved(serverAddress, serverPort);
}
}
@LauncherNetworkAPI
private List<ServerProfile> servers = new ArrayList<>(1);

View file

@ -2,10 +2,8 @@
import pro.gravit.launcher.LauncherNetworkAPI;
import pro.gravit.launcher.events.request.AuthRequestEvent;
import pro.gravit.launcher.hwid.HWID;
import pro.gravit.launcher.request.Request;
import pro.gravit.launcher.request.auth.password.AuthECPassword;
import pro.gravit.launcher.request.auth.password.AuthPlainPassword;
import pro.gravit.launcher.request.auth.password.*;
import pro.gravit.launcher.request.websockets.WebSocketRequest;
import pro.gravit.utils.ProviderMap;
import pro.gravit.utils.helper.VerifyHelper;
@ -23,8 +21,6 @@ public final class AuthRequest extends Request<AuthRequestEvent> implements WebS
private final boolean getSession;
@LauncherNetworkAPI
private final ConnectTypes authType;
@LauncherNetworkAPI
public boolean initProxy;
public AuthRequest(String login, byte[] password) {
this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty");
@ -43,15 +39,6 @@ public AuthRequest(String login, byte[] password, String auth_id) {
authType = ConnectTypes.CLIENT;
}
@Deprecated
public AuthRequest(String login, byte[] password, HWID hwid, String auth_id) {
this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty");
this.password = new AuthECPassword(password.clone());
this.auth_id = auth_id;
getSession = true;
authType = ConnectTypes.CLIENT;
}
public AuthRequest(String login, byte[] encryptedPassword, String auth_id, ConnectTypes authType) {
this.login = login;
this.password = new AuthECPassword(encryptedPassword.clone());
@ -72,6 +59,9 @@ public static void registerProviders() {
if (!registerProviders) {
providers.register("plain", AuthPlainPassword.class);
providers.register("rsa", AuthECPassword.class);
providers.register("2fa", Auth2FAPassword.class);
providers.register("signature", AuthSignaturePassword.class);
providers.register("totp", AuthTOTPPassword.class);
registerProviders = true;
}
}

View file

@ -0,0 +1,12 @@
package pro.gravit.launcher.request.auth.password;
import pro.gravit.launcher.request.auth.AuthRequest;
public class Auth2FAPassword implements AuthRequest.AuthPasswordInterface {
public AuthRequest.AuthPasswordInterface firstPassword;
public AuthRequest.AuthPasswordInterface secondPassword;
@Override
public boolean check() {
return firstPassword != null && firstPassword.check() && secondPassword != null && secondPassword.check();
}
}

View file

@ -0,0 +1,13 @@
package pro.gravit.launcher.request.auth.password;
import pro.gravit.launcher.request.auth.AuthRequest;
public class AuthSignaturePassword implements AuthRequest.AuthPasswordInterface {
public byte[] signature;
public byte[] publicKey;
public byte[] salt;
@Override
public boolean check() {
return true;
}
}

View file

@ -0,0 +1,11 @@
package pro.gravit.launcher.request.auth.password;
import pro.gravit.launcher.request.auth.AuthRequest;
public class AuthTOTPPassword implements AuthRequest.AuthPasswordInterface {
public String totp;
@Override
public boolean check() {
return true;
}
}