From 16803776d04e458a545a21c6d1e840149c9a99ba Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 28 Nov 2018 17:52:20 +0700 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B5=D0=B8=20=D0=B1=D0=B8=D0=B1=D0=BB?= =?UTF-8?q?=D0=B8=D0=BE=D1=82=D0=B5=D0=BA=D0=B8=20OSHI=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20HWID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/hwid/AcceptHWIDHandler.java | 4 +- .../gravit/launchserver/auth/hwid/HWID.java | 77 ------------------- .../launchserver/auth/hwid/HWIDHandler.java | 4 +- .../auth/hwid/JsonHWIDHandler.java | 36 ++++----- .../auth/hwid/MysqlHWIDHandler.java | 24 +++--- .../launchserver/command/auth/BanCommand.java | 2 +- .../command/auth/UnbanCommand.java | 2 +- .../response/auth/AuthResponse.java | 9 +-- .../websocket/json/auth/AuthResponse.java | 2 +- Launcher/build.gradle | 1 + .../dialog/overlay/processing/processing.js | 2 +- .../ru/gravit/launcher/FunctionalBridge.java | 8 ++ .../launcher/hwid/OshiHWIDProvider.java | 45 +++++++++++ .../launcher/request/auth/AuthRequest.java | 20 ++--- .../main/java/ru/gravit/launcher/HWID.java | 6 ++ .../launcher/LauncherHWIDInterface.java | 5 ++ .../java/ru/gravit/launcher/OshiHWID.java | 27 +++++++ 17 files changed, 141 insertions(+), 133 deletions(-) delete mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWID.java create mode 100644 Launcher/src/main/java/ru/gravit/launcher/hwid/OshiHWIDProvider.java create mode 100644 libLauncher/src/main/java/ru/gravit/launcher/HWID.java create mode 100644 libLauncher/src/main/java/ru/gravit/launcher/LauncherHWIDInterface.java create mode 100644 libLauncher/src/main/java/ru/gravit/launcher/OshiHWID.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java index 18930538..4d277426 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java @@ -1,8 +1,10 @@ package ru.gravit.launchserver.auth.hwid; +import java.util.ArrayList; import java.util.Collections; import java.util.List; +import ru.gravit.launcher.HWID; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; public class AcceptHWIDHandler extends HWIDHandler { @@ -28,7 +30,7 @@ public void close() { @Override public List getHwid(String username) { - return Collections.singletonList(nullHWID); + return new ArrayList<>(); } @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWID.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWID.java deleted file mode 100644 index 54bb0446..00000000 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWID.java +++ /dev/null @@ -1,77 +0,0 @@ -package ru.gravit.launchserver.auth.hwid; - -import java.io.IOException; - -import ru.gravit.launcher.serialize.HInput; -import ru.gravit.launcher.serialize.HOutput; - -public class HWID { - public static HWID fromData(HInput in) throws IOException { - return gen(in.readLong(), in.readLong(), in.readLong()); - } - - public static HWID gen(long hwid_hdd, long hwid_bios, long hwid_cpu) { - return new HWID(hwid_hdd, hwid_bios, hwid_cpu); - } - - private long hwid_bios; - - private long hwid_hdd; - - private long hwid_cpu; - - private HWID(long hwid_hdd, long hwid_bios, long hwid_cpu) { - this.hwid_hdd = hwid_hdd; - this.hwid_bios = hwid_bios; - this.hwid_cpu = hwid_cpu; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof HWID)) - return false; - HWID other = (HWID) obj; - if (hwid_bios != other.hwid_bios) - return false; - if (hwid_cpu != other.hwid_cpu) - return false; - return hwid_hdd == other.hwid_hdd; - } - - public long getHwid_bios() { - return hwid_bios; - } - - public long getHwid_cpu() { - return hwid_cpu; - } - - public long getHwid_hdd() { - return hwid_hdd; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (int) (hwid_bios ^ hwid_bios >>> 32); - result = prime * result + (int) (hwid_cpu ^ hwid_cpu >>> 32); - result = prime * result + (int) (hwid_hdd ^ hwid_hdd >>> 32); - return result; - } - - public void toData(HOutput out) throws IOException { - out.writeLong(hwid_hdd); - out.writeLong(hwid_bios); - out.writeLong(hwid_cpu); - } - - @Override - public String toString() { - return String.format("HWID {hwid_bios=%s, hwid_hdd=%s, hwid_cpu=%s}", hwid_bios, hwid_hdd, hwid_cpu); - } -} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java index ffcaa4de..10338fc4 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/HWIDHandler.java @@ -5,13 +5,13 @@ import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; +import ru.gravit.launcher.HWID; import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.launcher.serialize.config.ConfigObject; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; public abstract class HWIDHandler extends ConfigObject implements AutoCloseable { private static final Map> HW_HANDLERS = new ConcurrentHashMap<>(4); - public static final HWID nullHWID = HWID.gen(0, 0, 0); private static boolean registredHandl = false; @@ -44,7 +44,7 @@ protected HWIDHandler(BlockConfigEntry block) { public abstract void ban(List hwid) throws HWIDException; public void check(HWID hwid, String username) throws HWIDException { - if (nullHWID.equals(hwid)) return; + if (hwid.isNull()) return; check0(hwid, username); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java index aa895878..95e80d98 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java @@ -2,6 +2,8 @@ import com.google.gson.Gson; import com.google.gson.JsonElement; +import ru.gravit.launcher.HWID; +import ru.gravit.launcher.OshiHWID; import ru.gravit.utils.HTTPRequest; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; @@ -25,30 +27,20 @@ public final class JsonHWIDHandler extends HWIDHandler { public class banRequest { - long hwid_hdd; - - public banRequest(long hwid_hdd, long hwid_cpu, long hwid_bios) { - this.hwid_hdd = hwid_hdd; - this.hwid_cpu = hwid_cpu; - this.hwid_bios = hwid_bios; + public banRequest(String hwid) { + this.hwid = hwid; } - - long hwid_cpu; - long hwid_bios; + String hwid; } public class checkRequest { - public checkRequest(String username, long hwid_hdd, long hwid_cpu, long hwid_bios) { + public checkRequest(String username, String hwid) { this.username = username; - this.hwid_hdd = hwid_hdd; - this.hwid_cpu = hwid_cpu; - this.hwid_bios = hwid_bios; + this.hwid = hwid; } String username; - long hwid_hdd; - long hwid_cpu; - long hwid_bios; + String hwid; } public class Result @@ -62,9 +54,7 @@ public class BannedResult } public class HWIDResult { - long hwid_hdd; - long hwid_cpu; - long hwid_bios; + String string; } public class HWIDRequest { @@ -90,7 +80,7 @@ public HWIDRequest(String username) { @Override public void ban(List l_hwid) throws HWIDException { for (HWID hwid : l_hwid) { - banRequest request = new banRequest(hwid.getHwid_hdd(),hwid.getHwid_cpu(),hwid.getHwid_bios()); + banRequest request = new banRequest(hwid.getSerializeString()); try { JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlBan); Result r = gson.fromJson(result,Result.class); @@ -104,7 +94,7 @@ public void ban(List l_hwid) throws HWIDException { @Override public void check0(HWID hwid, String username) throws HWIDException { - checkRequest request = new checkRequest(username,hwid.getHwid_hdd(),hwid.getHwid_cpu(),hwid.getHwid_bios()); + checkRequest request = new checkRequest(username,hwid.getSerializeString()); try { JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlBan); BannedResult r = gson.fromJson(result,BannedResult.class); @@ -131,7 +121,7 @@ public List getHwid(String username) throws HWIDException { HWIDResult[] r = gson.fromJson(result,HWIDResult[].class); for( HWIDResult hw : r) { - hwids.add(HWID.gen(hw.hwid_hdd,hw.hwid_bios,hw.hwid_cpu)); + hwids.add(OshiHWID.gson.fromJson(hw.string,OshiHWID.class)); } } catch (IOException e) { LogHelper.error(e); @@ -143,7 +133,7 @@ public List getHwid(String username) throws HWIDException { @Override public void unban(List l_hwid) throws HWIDException { for (HWID hwid : l_hwid) { - banRequest request = new banRequest(hwid.getHwid_hdd(),hwid.getHwid_cpu(),hwid.getHwid_bios()); + banRequest request = new banRequest(hwid.getSerializeString()); try { JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlUnBan); Result r = gson.fromJson(result,Result.class); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java index 9af04cd6..49a9fa70 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java @@ -1,5 +1,7 @@ package ru.gravit.launchserver.auth.hwid; +import ru.gravit.launcher.HWID; +import ru.gravit.launcher.OshiHWID; import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; @@ -22,7 +24,7 @@ public class MysqlHWIDHandler extends HWIDHandler { private final String banMessage; private final String isBannedName; private final String loginName; - private final String hddName, cpuName, biosName; + private final String hwidName, cpuName, biosName; private final String[] queryParams; private final String queryUpd; private final String[] queryParamsUpd; @@ -45,8 +47,8 @@ public MysqlHWIDHandler(BlockConfigEntry block) { loginName = VerifyHelper.verify(block.getEntryValue("loginName", StringConfigEntry.class), VerifyHelper.NOT_EMPTY, "loginName can't be empty"); banMessage = block.hasEntry("banMessage") ? block.getEntryValue("banMessage", StringConfigEntry.class) : "You HWID Banned"; - hddName = VerifyHelper.verify(block.getEntryValue("hddName", StringConfigEntry.class), - VerifyHelper.NOT_EMPTY, "hddName can't be empty"); + hwidName = VerifyHelper.verify(block.getEntryValue("hwidName", StringConfigEntry.class), + VerifyHelper.NOT_EMPTY, "hwidName can't be empty"); cpuName = VerifyHelper.verify(block.getEntryValue("cpuName", StringConfigEntry.class), VerifyHelper.NOT_EMPTY, "cpuName can't be empty"); biosName = VerifyHelper.verify(block.getEntryValue("biosName", StringConfigEntry.class), @@ -72,7 +74,7 @@ public void check0(HWID hwid, String username) throws HWIDException { Connection c = mySQLHolder.getConnection(); PreparedStatement s = c.prepareStatement(query); - String[] replaceParams = {"hwid_hdd", String.valueOf(hwid.getHwid_hdd()), "hwid_cpu", String.valueOf(hwid.getHwid_cpu()), "hwid_bios", String.valueOf(hwid.getHwid_bios()), "login", username}; + String[] replaceParams = {"hwid", String.valueOf(hwid.getSerializeString()), "login", username}; for (int i = 0; i < queryParams.length; i++) { s.setString(i + 1, CommonHelper.replace(queryParams[i], replaceParams)); } @@ -109,7 +111,7 @@ public void writeHWID(HWID hwid, String username, Connection c) { LogHelper.debug("Write HWID %s from username %s", hwid.toString(), username); try (PreparedStatement a = c.prepareStatement(queryUpd)) { //IF - String[] replaceParamsUpd = {"hwid_hdd", String.valueOf(hwid.getHwid_hdd()), "hwid_cpu", String.valueOf(hwid.getHwid_cpu()), "hwid_bios", String.valueOf(hwid.getHwid_bios()), "login", username}; + String[] replaceParamsUpd = {"hwid", String.valueOf(hwid.getSerializeString()), "login", username}; for (int i = 0; i < queryParamsUpd.length; i++) { a.setString(i + 1, CommonHelper.replace(queryParamsUpd[i], replaceParamsUpd)); } @@ -130,7 +132,7 @@ public void setIsBanned(HWID hwid, boolean isBanned) { } try (PreparedStatement a = c.prepareStatement(queryBan)) { //IF - String[] replaceParamsUpd = {"hwid_hdd", String.valueOf(hwid.getHwid_hdd()), "hwid_cpu", String.valueOf(hwid.getHwid_cpu()), "hwid_bios", String.valueOf(hwid.getHwid_bios()), "isBanned", isBanned ? "1" : "0"}; + String[] replaceParamsUpd = {"hwid", String.valueOf(hwid.getSerializeString()), "isBanned", isBanned ? "1" : "0"}; for (int i = 0; i < queryParamsBan.length; i++) { a.setString(i + 1, CommonHelper.replace(queryParamsBan[i], replaceParamsUpd)); } @@ -166,19 +168,17 @@ public List getHwid(String username) { for (int i = 0; i < queryParamsSelect.length; i++) { s.setString(i + 1, CommonHelper.replace(queryParamsSelect[i], replaceParams)); } - long hdd, cpu, bios; + String hwid_str; try (ResultSet set = s.executeQuery()) { if (!set.next()) { LogHelper.error(new HWIDException("HWID not found")); return new ArrayList<>(); } - hdd = set.getLong(hddName); - cpu = set.getLong(cpuName); - bios = set.getLong(biosName); + hwid_str = set.getString(hwidName); } ArrayList list = new ArrayList<>(); - HWID hwid = HWID.gen(hdd, bios, cpu); - if (hdd == 0 && cpu == 0 && bios == 0) { + HWID hwid = OshiHWID.gson.fromJson(hwid_str,OshiHWID.class); + if (hwid.isNull()) { LogHelper.warning("Null HWID"); } else { list.add(hwid); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/BanCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/BanCommand.java index b289d597..9ba187f2 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/BanCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/BanCommand.java @@ -3,7 +3,7 @@ import java.util.List; import ru.gravit.launchserver.LaunchServer; -import ru.gravit.launchserver.auth.hwid.HWID; +import ru.gravit.launcher.HWID; import ru.gravit.launchserver.command.Command; public class BanCommand extends Command { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UnbanCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UnbanCommand.java index 726e0c33..66c3d80b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UnbanCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/auth/UnbanCommand.java @@ -3,7 +3,7 @@ import java.util.List; import ru.gravit.launchserver.LaunchServer; -import ru.gravit.launchserver.auth.hwid.HWID; +import ru.gravit.launcher.HWID; import ru.gravit.launchserver.command.Command; public class UnbanCommand extends Command { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java index b21b10e7..aa3f2612 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java @@ -7,6 +7,7 @@ import javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; +import ru.gravit.launcher.OshiHWID; import ru.gravit.launchserver.socket.Client; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; @@ -19,7 +20,7 @@ import ru.gravit.launcher.serialize.signed.SignedObjectHolder; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.auth.AuthException; -import ru.gravit.launchserver.auth.hwid.HWID; +import ru.gravit.launcher.HWID; import ru.gravit.launchserver.auth.hwid.HWIDException; import ru.gravit.launchserver.auth.provider.AuthProvider; import ru.gravit.launchserver.auth.provider.AuthProviderResult; @@ -45,9 +46,7 @@ public void reply() throws Exception { if (isClient) client = input.readString(SerializeLimits.MAX_CLIENT); int auth_id = input.readInt(); - long hwid_hdd = input.readLong(); - long hwid_cpu = input.readLong(); - long hwid_bios = input.readLong(); + String hwid_str = input.readString(0); if (auth_id + 1 > server.config.authProvider.length || auth_id < 0) auth_id = 0; byte[] encryptedPassword = input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH); // Decrypt password @@ -93,7 +92,7 @@ public void reply() throws Exception { throw new AuthException("You profile not found"); } } - server.config.hwidHandler.check(HWID.gen(hwid_hdd, hwid_bios, hwid_cpu), result.username); + server.config.hwidHandler.check(OshiHWID.gson.fromJson(hwid_str,OshiHWID.class), result.username); } catch (AuthException | HWIDException e) { requestError(e.getMessage()); return; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java index a6082551..5da19986 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java @@ -5,7 +5,7 @@ import ru.gravit.launcher.serialize.signed.SignedObjectHolder; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.auth.AuthException; -import ru.gravit.launchserver.auth.hwid.HWID; +import ru.gravit.launcher.HWID; import ru.gravit.launchserver.auth.hwid.HWIDException; import ru.gravit.launchserver.auth.provider.AuthProvider; import ru.gravit.launchserver.auth.provider.AuthProviderResult; diff --git a/Launcher/build.gradle b/Launcher/build.gradle index 0103a307..7521000f 100644 --- a/Launcher/build.gradle +++ b/Launcher/build.gradle @@ -23,6 +23,7 @@ dependencies { compile project(':LauncherAPI') compile 'org.javassist:javassist:3.23.1-GA' + compile group: 'com.github.oshi', name: 'oshi-core', version: '3.11.0' } task genRuntimeJS(type: Zip) { diff --git a/Launcher/runtime/dialog/overlay/processing/processing.js b/Launcher/runtime/dialog/overlay/processing/processing.js index fcf41938..9eb19fa5 100644 --- a/Launcher/runtime/dialog/overlay/processing/processing.js +++ b/Launcher/runtime/dialog/overlay/processing/processing.js @@ -118,7 +118,7 @@ function makeSetProfileRequest(profile, callback) { function makeAuthRequest(login, rsaPassword, callback) { var task = rsaPassword === null ? newTask(offlineAuthRequest(login)) : - newRequestTask(new AuthRequest(login, rsaPassword)); + newRequestTask(new AuthRequest(login, rsaPassword, FunctionalBridge.getHWID())); processing.setTaskProperties(task, callback, null, true); task.updateMessage("Авторизация на сервере"); startTask(task); diff --git a/Launcher/src/main/java/ru/gravit/launcher/FunctionalBridge.java b/Launcher/src/main/java/ru/gravit/launcher/FunctionalBridge.java index eb9b8157..82a08c51 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/FunctionalBridge.java +++ b/Launcher/src/main/java/ru/gravit/launcher/FunctionalBridge.java @@ -5,6 +5,7 @@ import ru.gravit.launcher.client.ClientLauncher; import ru.gravit.launcher.hasher.FileNameMatcher; import ru.gravit.launcher.hasher.HashedDir; +import ru.gravit.launcher.hwid.OshiHWIDProvider; import ru.gravit.launcher.request.Request; import ru.gravit.launcher.request.update.LegacyLauncherRequest; import ru.gravit.launcher.request.websockets.RequestInterface; @@ -20,6 +21,8 @@ public class FunctionalBridge { public static LauncherSettings settings; @LauncherAPI public static RequestWorker worker; + @LauncherAPI + public static OshiHWIDProvider hwidProvider = new OshiHWIDProvider(); @LauncherAPI public HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, SignedObjectHolder hdir, FileNameMatcher matcher, boolean digest) throws Exception { @@ -65,4 +68,9 @@ public void startTask(@SuppressWarnings("rawtypes") Task task) LogHelper.error(e); } } + @LauncherAPI + public HWID getHWID() + { + return hwidProvider.getHWID(); + } } diff --git a/Launcher/src/main/java/ru/gravit/launcher/hwid/OshiHWIDProvider.java b/Launcher/src/main/java/ru/gravit/launcher/hwid/OshiHWIDProvider.java new file mode 100644 index 00000000..24374f1b --- /dev/null +++ b/Launcher/src/main/java/ru/gravit/launcher/hwid/OshiHWIDProvider.java @@ -0,0 +1,45 @@ +package ru.gravit.launcher.hwid; + +import oshi.SystemInfo; +import oshi.hardware.HWDiskStore; +import ru.gravit.launcher.HWID; +import ru.gravit.launcher.LauncherHWIDInterface; +import ru.gravit.launcher.OshiHWID; +import ru.gravit.utils.helper.LogHelper; + +public class OshiHWIDProvider implements LauncherHWIDInterface { + public static SystemInfo systemInfo = new SystemInfo(); + public String getSerial() + { + try { + return systemInfo.getHardware().getComputerSystem().getSerialNumber(); + } catch (Exception e) + { + LogHelper.error(e); + return ""; + } + + } + public String getHWDisk() + { + for(HWDiskStore s : systemInfo.getHardware().getDiskStores()) + { + if(!s.getModel().contains("USB")) + return s.getSerial(); + } + return ""; + } + public long getTotalMemory() + { + return systemInfo.getHardware().getMemory().getTotal(); + } + + @Override + public HWID getHWID() { + OshiHWID hwid = new OshiHWID(); + hwid.serialNumber = getSerial(); + hwid.totalMemory = getTotalMemory(); + hwid.HWDiskSerial = getHWDisk(); + return hwid; + } +} diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java index ae374851..66d0f4aa 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java @@ -5,6 +5,7 @@ import ru.gravit.launcher.Launcher; import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherConfig; +import ru.gravit.launcher.LauncherHWIDInterface; import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.launcher.profiles.PlayerProfile; @@ -33,31 +34,34 @@ private Result(PlayerProfile pp, String accessToken) { private final byte[] encryptedPassword; private final int auth_id; + private final LauncherHWIDInterface hwid; @LauncherAPI - public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword) { + public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword, LauncherHWIDInterface hwid) { super(config); this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty"); this.encryptedPassword = encryptedPassword.clone(); + this.hwid = hwid; auth_id = 0; } @LauncherAPI - public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword, int auth_id) { + public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword, LauncherHWIDInterface hwid, 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; } @LauncherAPI - public AuthRequest(String login, byte[] encryptedPassword) { - this(null, login, encryptedPassword); + public AuthRequest(String login, byte[] encryptedPassword, LauncherHWIDInterface hwid) { + this(null, login, encryptedPassword,hwid); } @LauncherAPI - public AuthRequest(String login, byte[] encryptedPassword, int auth_id) { - this(null, login, encryptedPassword, auth_id); + public AuthRequest(String login, byte[] encryptedPassword, LauncherHWIDInterface hwid, int auth_id) { + this(null, login, encryptedPassword, hwid, auth_id); } @Override @@ -72,9 +76,7 @@ protected Result requestDo(HInput input, HOutput output) throws IOException { if (Launcher.profile != null) output.writeString(Launcher.profile.getTitle(), SerializeLimits.MAX_CLIENT); output.writeInt(auth_id); - output.writeLong(Launcher.isUsingAvanguard() ? GuardBind.avnGetHddId() : 0); - output.writeLong(Launcher.isUsingAvanguard() ? GuardBind.avnGetCpuid() : 0); - output.writeLong(Launcher.isUsingAvanguard() ? GuardBind.avnGetSmbiosId() : 0); + output.writeString(hwid.getHWID().getSerializeString(),0); output.writeByteArray(encryptedPassword, SecurityHelper.CRYPTO_MAX_LENGTH); output.flush(); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/HWID.java b/libLauncher/src/main/java/ru/gravit/launcher/HWID.java new file mode 100644 index 00000000..cc510103 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/HWID.java @@ -0,0 +1,6 @@ +package ru.gravit.launcher; + +public interface HWID { + String getSerializeString(); + boolean isNull(); +} diff --git a/libLauncher/src/main/java/ru/gravit/launcher/LauncherHWIDInterface.java b/libLauncher/src/main/java/ru/gravit/launcher/LauncherHWIDInterface.java new file mode 100644 index 00000000..758f8ac0 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/LauncherHWIDInterface.java @@ -0,0 +1,5 @@ +package ru.gravit.launcher; + +public interface LauncherHWIDInterface { + HWID getHWID(); +} diff --git a/libLauncher/src/main/java/ru/gravit/launcher/OshiHWID.java b/libLauncher/src/main/java/ru/gravit/launcher/OshiHWID.java new file mode 100644 index 00000000..5b1a7a0c --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/OshiHWID.java @@ -0,0 +1,27 @@ +package ru.gravit.launcher; + +import com.google.gson.Gson; + +public class OshiHWID implements HWID { + public static Gson gson = new Gson(); + public long totalMemory = 0; + public String serialNumber; + public String HWDiskSerial; + + @Override + public String getSerializeString() { + return gson.toJson(this); + } + public int getLevel() //Уровень доверия, насколько уникальные значения + { + int result = 0; + if(totalMemory != 0) result++; + if(serialNumber != null) result+=5; + if(HWDiskSerial != null) result+=8; + return result; + } + @Override + public boolean isNull() { + return getLevel() < 2; + } +}