[FIX] onHardwareReport NPE

This commit is contained in:
Gravita 2023-10-31 16:22:44 +07:00
parent 4b222b9526
commit 90e116720c
3 changed files with 11 additions and 6 deletions

View file

@ -49,6 +49,10 @@ public void onHardwareReport(HardwareReportResponse response, Client client) {
response.sendError("Access denied"); response.sendError("Access denied");
return; return;
} }
if(client.trustLevel.hardwareInfo != null) {
response.sendResult(new HardwareReportRequestEvent(createHardwareToken(client.username, client.trustLevel.hardwareInfo), SECONDS.toMillis(server.config.netty.security.hardwareTokenExpire)));
return;
}
logger.debug("HardwareInfo received"); logger.debug("HardwareInfo received");
{ {
var authSupportHardware = client.auth.isSupport(AuthSupportHardware.class); var authSupportHardware = client.auth.isSupport(AuthSupportHardware.class);
@ -63,7 +67,7 @@ public void onHardwareReport(HardwareReportResponse response, Client client) {
if (hardware.isBanned()) { if (hardware.isBanned()) {
throw new SecurityException("Your hardware banned"); throw new SecurityException("Your hardware banned");
} }
client.trustLevel.hardwareInfo = hardware.getHardwareInfo(); client.trustLevel.hardwareInfo = hardware;
response.sendResult(new HardwareReportRequestEvent(createHardwareToken(client.username, hardware), SECONDS.toMillis(server.config.netty.security.hardwareTokenExpire))); response.sendResult(new HardwareReportRequestEvent(createHardwareToken(client.username, hardware), SECONDS.toMillis(server.config.netty.security.hardwareTokenExpire)));
} else { } else {
logger.error("AuthCoreProvider not supported hardware"); logger.error("AuthCoreProvider not supported hardware");
@ -83,7 +87,7 @@ public VerifySecureLevelKeyRequestEvent onSuccessVerify(Client client) {
if (hardware.isBanned()) { if (hardware.isBanned()) {
throw new SecurityException("Your hardware banned"); throw new SecurityException("Your hardware banned");
} }
client.trustLevel.hardwareInfo = hardware.getHardwareInfo(); client.trustLevel.hardwareInfo = hardware;
authSupportHardware.connectUserAndHardware(client.sessionObject, hardware); authSupportHardware.connectUserAndHardware(client.sessionObject, hardware);
return new VerifySecureLevelKeyRequestEvent(false, false, createPublicKeyToken(client.username, client.trustLevel.publicKey), SECONDS.toMillis(server.config.netty.security.publicKeyTokenExpire)); return new VerifySecureLevelKeyRequestEvent(false, false, createPublicKeyToken(client.username, client.trustLevel.publicKey), SECONDS.toMillis(server.config.netty.security.publicKeyTokenExpire));
} else { } else {
@ -145,7 +149,7 @@ public boolean accept(Client client, AuthProviderPair pair, String extendedToken
if (hardwareSupport == null) return false; if (hardwareSupport == null) return false;
UserHardware hardware = hardwareSupport.getHardwareInfoById(hardwareInfoId); UserHardware hardware = hardwareSupport.getHardwareInfoById(hardwareInfoId);
if (client.trustLevel == null) client.trustLevel = new Client.TrustLevel(); if (client.trustLevel == null) client.trustLevel = new Client.TrustLevel();
client.trustLevel.hardwareInfo = hardware.getHardwareInfo(); client.trustLevel.hardwareInfo = hardware;
return true; return true;
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Hardware JWT error", e); logger.error("Hardware JWT error", e);

View file

@ -5,6 +5,7 @@
import pro.gravit.launcher.request.secure.HardwareReportRequest; import pro.gravit.launcher.request.secure.HardwareReportRequest;
import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.LaunchServer;
import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.AuthProviderPair;
import pro.gravit.launchserver.auth.core.interfaces.UserHardware;
import pro.gravit.launchserver.socket.response.auth.AuthResponse; import pro.gravit.launchserver.socket.response.auth.AuthResponse;
import java.util.HashMap; import java.util.HashMap;
@ -87,7 +88,7 @@ public static class TrustLevel {
public byte[] verifySecureKey; public byte[] verifySecureKey;
public boolean keyChecked; public boolean keyChecked;
public byte[] publicKey; public byte[] publicKey;
public HardwareReportRequest.HardwareInfo hardwareInfo; public UserHardware hardwareInfo;
// May be used later // May be used later
public double rating; public double rating;
public long latestMillis; public long latestMillis;

View file

@ -6,9 +6,9 @@ public final class Version implements Comparable<Version> {
public static final int MAJOR = 5; public static final int MAJOR = 5;
public static final int MINOR = 5; public static final int MINOR = 5;
public static final int PATCH = 0; public static final int PATCH = 1;
public static final int BUILD = 1; public static final int BUILD = 1;
public static final Version.Type RELEASE = Type.STABLE; public static final Version.Type RELEASE = Type.DEV;
public final int major; public final int major;
public final int minor; public final int minor;
public final int patch; public final int patch;