mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FIX] MySQLCoreProvider HWID fix
This commit is contained in:
parent
0c281ab50d
commit
81be9d21de
6 changed files with 129 additions and 122 deletions
|
@ -177,6 +177,7 @@ public void invoke(String... args) throws Exception {
|
|||
}
|
||||
{
|
||||
var instance = isSupport(AuthSupportHardware.class);
|
||||
if (instance != null) {
|
||||
map.put("gethardwarebyid", new SubCommand("[id]", "get hardware by id") {
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
|
@ -234,7 +235,7 @@ public void invoke(String... args) throws Exception {
|
|||
}
|
||||
Iterable<User> users = instance.getUsersByHardwareInfo(hardware);
|
||||
for (User user : users) {
|
||||
logger.info("User {}", user.getUsername());
|
||||
logger.info("User {}", user);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -279,6 +280,7 @@ public void invoke(String... args) throws Exception {
|
|||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.sql.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
@ -61,11 +61,11 @@ public class MySQLCoreProvider extends AuthCoreProvider implements AuthSupportHa
|
|||
private transient String updateAuthSQL;
|
||||
private transient String updateServerIDSQL;
|
||||
|
||||
public String defaultQueryByUUIDSQL;
|
||||
public String defaultQueryByUsernameSQL;
|
||||
public String defaultQueryByLoginSQL;
|
||||
public String defaultUpdateAuthSQL;
|
||||
public String defaultUpdateServerIdSQL;
|
||||
public String customQueryByUUIDSQL;
|
||||
public String customQueryByUsernameSQL;
|
||||
public String customQueryByLoginSQL;
|
||||
public String customUpdateAuthSQL;
|
||||
public String customUpdateServerIdSQL;
|
||||
|
||||
@Override
|
||||
public User getUserByUsername(String username) {
|
||||
|
@ -143,23 +143,26 @@ public void init(LaunchServer server) {
|
|||
if (table == null) logger.error("table cannot be null");
|
||||
// Prepare SQL queries
|
||||
String userInfoCols = String.format("%s, %s, %s, %s, %s, %s", uuidColumn, usernameColumn, accessTokenColumn, serverIDColumn, passwordColumn, hardwareIdColumn);
|
||||
queryByUUIDSQL = defaultQueryByUUIDSQL != null ? defaultQueryByUUIDSQL : String.format("SELECT %s FROM %s WHERE %s=? LIMIT 1", userInfoCols,
|
||||
queryByUUIDSQL = customQueryByUUIDSQL != null ? customQueryByUUIDSQL : String.format("SELECT %s FROM %s WHERE %s=? LIMIT 1", userInfoCols,
|
||||
table, uuidColumn);
|
||||
queryByUsernameSQL = defaultQueryByUsernameSQL != null ? defaultQueryByUsernameSQL : String.format("SELECT %s FROM %s WHERE %s=? LIMIT 1",
|
||||
queryByUsernameSQL = customQueryByUsernameSQL != null ? customQueryByUsernameSQL : String.format("SELECT %s FROM %s WHERE %s=? LIMIT 1",
|
||||
userInfoCols, table, usernameColumn);
|
||||
queryByLoginSQL = defaultQueryByLoginSQL != null ? defaultQueryByLoginSQL : queryByUsernameSQL;
|
||||
queryByLoginSQL = customQueryByLoginSQL != null ? customQueryByLoginSQL : queryByUsernameSQL;
|
||||
|
||||
updateAuthSQL = defaultUpdateAuthSQL != null ? defaultUpdateAuthSQL : String.format("UPDATE %s SET %s=?, %s=NULL WHERE %s=? LIMIT 1",
|
||||
updateAuthSQL = customUpdateAuthSQL != null ? customUpdateAuthSQL : String.format("UPDATE %s SET %s=?, %s=NULL WHERE %s=? LIMIT 1",
|
||||
table, accessTokenColumn, serverIDColumn, uuidColumn);
|
||||
updateServerIDSQL = defaultUpdateServerIdSQL != null ? defaultUpdateServerIdSQL : String.format("UPDATE %s SET %s=? WHERE %s=? LIMIT 1",
|
||||
updateServerIDSQL = customUpdateServerIdSQL != null ? customUpdateServerIdSQL : String.format("UPDATE %s SET %s=? WHERE %s=? LIMIT 1",
|
||||
table, serverIDColumn, uuidColumn);
|
||||
String hardwareInfoCols = "id, hwDiskId, baseboardSerialNumber, displayId, bitness, totalMemory, logicalProcessors, physicalProcessors, processorMaxFreq, battery, id, graphicCard, banned";
|
||||
String hardwareInfoCols = "id, hwDiskId, baseboardSerialNumber, displayId, bitness, totalMemory, logicalProcessors, physicalProcessors, processorMaxFreq, battery, id, graphicCard, banned, publicKey";
|
||||
if(sqlFindHardwareByPublicKey == null) sqlFindHardwareByPublicKey = String.format("SELECT %s FROM %s WHERE `publicKey` = ?", hardwareInfoCols, tableHWID);
|
||||
if(sqlFindHardwareById == null) sqlFindHardwareById = String.format("SELECT %s FROM %s WHERE `id` = ?", hardwareInfoCols, tableHWID);
|
||||
if(sqlUsersByHwidId == null) sqlUsersByHwidId = String.format("SELECT %s FROM %s WHERE `%s` = ?", userInfoCols, table, hardwareIdColumn);
|
||||
if(sqlFindHardwareByData == null) sqlFindHardwareByData = String.format("SELECT %s FROM %s", hardwareInfoCols, tableHWID);
|
||||
if(sqlCreateHardware == null) sqlCreateHardware = String.format("INSERT INTO `%s` (`publickey`, `hwDiskId`, `baseboardSerialNumber`, `displayId`, `bitness`, `totalMemory`, `logicalProcessors`, `physicalProcessors`, `processorMaxFreq`, `battery`, `graphicCard`, `banned`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '0')", tableHWID);
|
||||
if(sqlCreateHWIDLog == null) sqlCreateHWIDLog = String.format("INSERT INTO %s (`hwidId`, `newPublicKey`) VALUES (?, ?)", tableHWIDLog);
|
||||
if (sqlFindHardwareByData == null)
|
||||
sqlFindHardwareByData = String.format("SELECT %s FROM %s", hardwareInfoCols, tableHWID);
|
||||
if (sqlCreateHardware == null)
|
||||
sqlCreateHardware = String.format("INSERT INTO `%s` (`publickey`, `hwDiskId`, `baseboardSerialNumber`, `displayId`, `bitness`, `totalMemory`, `logicalProcessors`, `physicalProcessors`, `processorMaxFreq`, `graphicCard`, `battery`, `banned`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '0')", tableHWID);
|
||||
if (sqlCreateHWIDLog == null)
|
||||
sqlCreateHWIDLog = String.format("INSERT INTO %s (`hwidId`, `newPublicKey`) VALUES (?, ?)", tableHWIDLog);
|
||||
if(sqlUpdateHardwarePublicKey == null) sqlUpdateHardwarePublicKey = String.format("UPDATE %s SET `publicKey` = ? WHERE `id` = ?", tableHWID);
|
||||
sqlUpdateHardwareBanned = String.format("UPDATE %s SET `banned` = ? WHERE `id` = ?", tableHWID);
|
||||
sqlUpdateUsers = String.format("UPDATE %s SET `%s` = ? WHERE `%s` = ?", table, hardwareIdColumn, uuidColumn);
|
||||
|
@ -256,7 +259,7 @@ public UserHardware getHardwareInfoByPublicKey(byte[] publicKey) {
|
|||
}
|
||||
}
|
||||
} catch (SQLException | IOException throwables) {
|
||||
logger.error(throwables);
|
||||
logger.error("SQL Error", throwables);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -275,7 +278,7 @@ public UserHardware getHardwareInfoByData(HardwareReportRequest.HardwareInfo inf
|
|||
}
|
||||
}
|
||||
} catch (SQLException | IOException throwables) {
|
||||
logger.error(throwables);
|
||||
logger.error("SQL Error", throwables);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -293,7 +296,7 @@ public UserHardware getHardwareInfoById(String id) {
|
|||
}
|
||||
}
|
||||
} catch (SQLException | IOException throwables) {
|
||||
logger.error(throwables);
|
||||
logger.error("SQL Error", throwables);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -323,7 +326,7 @@ public UserHardware createHardwareInfo(HardwareReportRequest.HardwareInfo hardwa
|
|||
}
|
||||
return null;
|
||||
} catch (SQLException throwables) {
|
||||
logger.error(throwables);
|
||||
logger.error("SQL Error", throwables);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -337,7 +340,7 @@ public void connectUserAndHardware(User user, UserHardware hardware) {
|
|||
try (Connection connection = mySQLHolder.getConnection()) {
|
||||
setUserHardwareId(connection, user.getUUID(), mySQLUserHardware.id);
|
||||
} catch (SQLException throwables) {
|
||||
logger.error(throwables);
|
||||
logger.error("SQL Error", throwables);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -363,7 +366,7 @@ public Iterable<User> getUsersByHardwareInfo(UserHardware hardware) {
|
|||
s.setLong(1, Long.parseLong(hardware.getId()));
|
||||
s.setQueryTimeout(MySQLSourceConfig.TIMEOUT);
|
||||
try (ResultSet set = s.executeQuery()) {
|
||||
while (set.next()) {
|
||||
while (!set.isLast()) {
|
||||
users.add(constructUser(set));
|
||||
}
|
||||
}
|
||||
|
@ -503,7 +506,7 @@ public boolean isBanned() {
|
|||
public String toString() {
|
||||
return "MySQLUserHardware{" +
|
||||
"hardwareInfo=" + hardwareInfo +
|
||||
", publicKey=" + (publicKey == null ? null : SecurityHelper.toHex(publicKey)) +
|
||||
", publicKey=" + (publicKey == null ? null : new String(Base64.getEncoder().encode(publicKey))) +
|
||||
", id=" + id +
|
||||
", banned=" + banned +
|
||||
'}';
|
||||
|
|
|
@ -48,7 +48,7 @@ public void invoke(String... args) {
|
|||
logger.info("Data: checkSign {} | auth_id {}", client.checkSign ? "true" : "false",
|
||||
client.auth_id);
|
||||
if (client.trustLevel != null) {
|
||||
logger.info("trustLevel | key {} | pubkey {}", client.trustLevel.keyChecked ? "checked" : "unchecked", client.trustLevel.publicKey == null ? "null" : Base64.getEncoder().encode(client.trustLevel.publicKey));
|
||||
logger.info("trustLevel | key {} | pubkey {}", client.trustLevel.keyChecked ? "checked" : "unchecked", client.trustLevel.publicKey == null ? "null" : new String(Base64.getEncoder().encode(client.trustLevel.publicKey)));
|
||||
}
|
||||
logger.info("Permissions: {} (permissions {} | flags {})", client.permissions == null ? "null" : client.permissions.toString(), client.permissions == null ? 0 : client.permissions.permissions, client.permissions == null ? 0 : client.permissions.flags);
|
||||
}
|
||||
|
|
|
@ -84,7 +84,10 @@ public final void setFlag(long mask, boolean value) {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("permissions %d | flags %d", permissions, flags);
|
||||
return "ClientPermissions{" +
|
||||
"permissions=" + permissions +
|
||||
", flags=" + flags +
|
||||
'}';
|
||||
}
|
||||
|
||||
public enum PermissionConsts {
|
||||
|
|
|
@ -2,9 +2,8 @@
|
|||
|
||||
import pro.gravit.launcher.events.request.HardwareReportRequestEvent;
|
||||
import pro.gravit.launcher.request.Request;
|
||||
import pro.gravit.utils.helper.SecurityHelper;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
|
||||
public class HardwareReportRequest extends Request<HardwareReportRequestEvent> {
|
||||
public HardwareInfo hardware;
|
||||
|
@ -36,7 +35,7 @@ public String toString() {
|
|||
", processorMaxFreq=" + processorMaxFreq +
|
||||
", battery=" + battery +
|
||||
", hwDiskId='" + hwDiskId + '\'' +
|
||||
", displayId=" + (displayId == null ? null : SecurityHelper.toHex(displayId)) +
|
||||
", displayId=" + (displayId == null ? null : new String(Base64.getEncoder().encode(displayId))) +
|
||||
", baseboardSerialNumber='" + baseboardSerialNumber + '\'' +
|
||||
", graphicCard='" + graphicCard + '\'' +
|
||||
'}';
|
||||
|
|
2
modules
2
modules
|
@ -1 +1 @@
|
|||
Subproject commit e8bc82be4d0fb86041fe464cad32314430552386
|
||||
Subproject commit 0472083e090ff249cb6795d209c34ad79f391f7a
|
Loading…
Reference in a new issue