Использованеи библиотеки OSHI для получения HWID

This commit is contained in:
Gravit 2018-11-28 17:52:20 +07:00
parent 8597206e84
commit 16803776d0
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
17 changed files with 141 additions and 133 deletions

View file

@ -1,8 +1,10 @@
package ru.gravit.launchserver.auth.hwid; package ru.gravit.launchserver.auth.hwid;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import ru.gravit.launcher.HWID;
import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry;
public class AcceptHWIDHandler extends HWIDHandler { public class AcceptHWIDHandler extends HWIDHandler {
@ -28,7 +30,7 @@ public void close() {
@Override @Override
public List<HWID> getHwid(String username) { public List<HWID> getHwid(String username) {
return Collections.singletonList(nullHWID); return new ArrayList<>();
} }
@Override @Override

View file

@ -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);
}
}

View file

@ -5,13 +5,13 @@
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import ru.gravit.launcher.HWID;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
import ru.gravit.launcher.serialize.config.ConfigObject; import ru.gravit.launcher.serialize.config.ConfigObject;
import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry;
public abstract class HWIDHandler extends ConfigObject implements AutoCloseable { public abstract class HWIDHandler extends ConfigObject implements AutoCloseable {
private static final Map<String, Adapter<HWIDHandler>> HW_HANDLERS = new ConcurrentHashMap<>(4); private static final Map<String, Adapter<HWIDHandler>> HW_HANDLERS = new ConcurrentHashMap<>(4);
public static final HWID nullHWID = HWID.gen(0, 0, 0);
private static boolean registredHandl = false; private static boolean registredHandl = false;
@ -44,7 +44,7 @@ protected HWIDHandler(BlockConfigEntry block) {
public abstract void ban(List<HWID> hwid) throws HWIDException; public abstract void ban(List<HWID> hwid) throws HWIDException;
public void check(HWID hwid, String username) throws HWIDException { public void check(HWID hwid, String username) throws HWIDException {
if (nullHWID.equals(hwid)) return; if (hwid.isNull()) return;
check0(hwid, username); check0(hwid, username);
} }

View file

@ -2,6 +2,8 @@
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import ru.gravit.launcher.HWID;
import ru.gravit.launcher.OshiHWID;
import ru.gravit.utils.HTTPRequest; import ru.gravit.utils.HTTPRequest;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
@ -25,30 +27,20 @@ public final class JsonHWIDHandler extends HWIDHandler {
public class banRequest public class banRequest
{ {
long hwid_hdd; public banRequest(String hwid) {
this.hwid = hwid;
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;
} }
String hwid;
long hwid_cpu;
long hwid_bios;
} }
public class checkRequest 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.username = username;
this.hwid_hdd = hwid_hdd; this.hwid = hwid;
this.hwid_cpu = hwid_cpu;
this.hwid_bios = hwid_bios;
} }
String username; String username;
long hwid_hdd; String hwid;
long hwid_cpu;
long hwid_bios;
} }
public class Result public class Result
@ -62,9 +54,7 @@ public class BannedResult
} }
public class HWIDResult public class HWIDResult
{ {
long hwid_hdd; String string;
long hwid_cpu;
long hwid_bios;
} }
public class HWIDRequest public class HWIDRequest
{ {
@ -90,7 +80,7 @@ public HWIDRequest(String username) {
@Override @Override
public void ban(List<HWID> l_hwid) throws HWIDException { public void ban(List<HWID> l_hwid) throws HWIDException {
for (HWID hwid : l_hwid) { 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 { try {
JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlBan); JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlBan);
Result r = gson.fromJson(result,Result.class); Result r = gson.fromJson(result,Result.class);
@ -104,7 +94,7 @@ public void ban(List<HWID> l_hwid) throws HWIDException {
@Override @Override
public void check0(HWID hwid, String username) throws HWIDException { 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 { try {
JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlBan); JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlBan);
BannedResult r = gson.fromJson(result,BannedResult.class); BannedResult r = gson.fromJson(result,BannedResult.class);
@ -131,7 +121,7 @@ public List<HWID> getHwid(String username) throws HWIDException {
HWIDResult[] r = gson.fromJson(result,HWIDResult[].class); HWIDResult[] r = gson.fromJson(result,HWIDResult[].class);
for( HWIDResult hw : r) 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) { } catch (IOException e) {
LogHelper.error(e); LogHelper.error(e);
@ -143,7 +133,7 @@ public List<HWID> getHwid(String username) throws HWIDException {
@Override @Override
public void unban(List<HWID> l_hwid) throws HWIDException { public void unban(List<HWID> l_hwid) throws HWIDException {
for (HWID hwid : l_hwid) { 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 { try {
JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlUnBan); JsonElement result = HTTPRequest.jsonRequest(gson.toJsonTree(request), urlUnBan);
Result r = gson.fromJson(result,Result.class); Result r = gson.fromJson(result,Result.class);

View file

@ -1,5 +1,7 @@
package ru.gravit.launchserver.auth.hwid; 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.CommonHelper;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry;
@ -22,7 +24,7 @@ public class MysqlHWIDHandler extends HWIDHandler {
private final String banMessage; private final String banMessage;
private final String isBannedName; private final String isBannedName;
private final String loginName; private final String loginName;
private final String hddName, cpuName, biosName; private final String hwidName, cpuName, biosName;
private final String[] queryParams; private final String[] queryParams;
private final String queryUpd; private final String queryUpd;
private final String[] queryParamsUpd; private final String[] queryParamsUpd;
@ -45,8 +47,8 @@ public MysqlHWIDHandler(BlockConfigEntry block) {
loginName = VerifyHelper.verify(block.getEntryValue("loginName", StringConfigEntry.class), loginName = VerifyHelper.verify(block.getEntryValue("loginName", StringConfigEntry.class),
VerifyHelper.NOT_EMPTY, "loginName can't be empty"); VerifyHelper.NOT_EMPTY, "loginName can't be empty");
banMessage = block.hasEntry("banMessage") ? block.getEntryValue("banMessage", StringConfigEntry.class) : "You HWID Banned"; banMessage = block.hasEntry("banMessage") ? block.getEntryValue("banMessage", StringConfigEntry.class) : "You HWID Banned";
hddName = VerifyHelper.verify(block.getEntryValue("hddName", StringConfigEntry.class), hwidName = VerifyHelper.verify(block.getEntryValue("hwidName", StringConfigEntry.class),
VerifyHelper.NOT_EMPTY, "hddName can't be empty"); VerifyHelper.NOT_EMPTY, "hwidName can't be empty");
cpuName = VerifyHelper.verify(block.getEntryValue("cpuName", StringConfigEntry.class), cpuName = VerifyHelper.verify(block.getEntryValue("cpuName", StringConfigEntry.class),
VerifyHelper.NOT_EMPTY, "cpuName can't be empty"); VerifyHelper.NOT_EMPTY, "cpuName can't be empty");
biosName = VerifyHelper.verify(block.getEntryValue("biosName", StringConfigEntry.class), 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(); Connection c = mySQLHolder.getConnection();
PreparedStatement s = c.prepareStatement(query); 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++) { for (int i = 0; i < queryParams.length; i++) {
s.setString(i + 1, CommonHelper.replace(queryParams[i], replaceParams)); 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); LogHelper.debug("Write HWID %s from username %s", hwid.toString(), username);
try (PreparedStatement a = c.prepareStatement(queryUpd)) { try (PreparedStatement a = c.prepareStatement(queryUpd)) {
//IF //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++) { for (int i = 0; i < queryParamsUpd.length; i++) {
a.setString(i + 1, CommonHelper.replace(queryParamsUpd[i], replaceParamsUpd)); 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)) { try (PreparedStatement a = c.prepareStatement(queryBan)) {
//IF //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++) { for (int i = 0; i < queryParamsBan.length; i++) {
a.setString(i + 1, CommonHelper.replace(queryParamsBan[i], replaceParamsUpd)); a.setString(i + 1, CommonHelper.replace(queryParamsBan[i], replaceParamsUpd));
} }
@ -166,19 +168,17 @@ public List<HWID> getHwid(String username) {
for (int i = 0; i < queryParamsSelect.length; i++) { for (int i = 0; i < queryParamsSelect.length; i++) {
s.setString(i + 1, CommonHelper.replace(queryParamsSelect[i], replaceParams)); s.setString(i + 1, CommonHelper.replace(queryParamsSelect[i], replaceParams));
} }
long hdd, cpu, bios; String hwid_str;
try (ResultSet set = s.executeQuery()) { try (ResultSet set = s.executeQuery()) {
if (!set.next()) { if (!set.next()) {
LogHelper.error(new HWIDException("HWID not found")); LogHelper.error(new HWIDException("HWID not found"));
return new ArrayList<>(); return new ArrayList<>();
} }
hdd = set.getLong(hddName); hwid_str = set.getString(hwidName);
cpu = set.getLong(cpuName);
bios = set.getLong(biosName);
} }
ArrayList<HWID> list = new ArrayList<>(); ArrayList<HWID> list = new ArrayList<>();
HWID hwid = HWID.gen(hdd, bios, cpu); HWID hwid = OshiHWID.gson.fromJson(hwid_str,OshiHWID.class);
if (hdd == 0 && cpu == 0 && bios == 0) { if (hwid.isNull()) {
LogHelper.warning("Null HWID"); LogHelper.warning("Null HWID");
} else { } else {
list.add(hwid); list.add(hwid);

View file

@ -3,7 +3,7 @@
import java.util.List; import java.util.List;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.auth.hwid.HWID; import ru.gravit.launcher.HWID;
import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.Command;
public class BanCommand extends Command { public class BanCommand extends Command {

View file

@ -3,7 +3,7 @@
import java.util.List; import java.util.List;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.auth.hwid.HWID; import ru.gravit.launcher.HWID;
import ru.gravit.launchserver.command.Command; import ru.gravit.launchserver.command.Command;
public class UnbanCommand extends Command { public class UnbanCommand extends Command {

View file

@ -7,6 +7,7 @@
import javax.crypto.BadPaddingException; import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException; import javax.crypto.IllegalBlockSizeException;
import ru.gravit.launcher.OshiHWID;
import ru.gravit.launchserver.socket.Client; import ru.gravit.launchserver.socket.Client;
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.LogHelper;
@ -19,7 +20,7 @@
import ru.gravit.launcher.serialize.signed.SignedObjectHolder; import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.auth.AuthException; 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.hwid.HWIDException;
import ru.gravit.launchserver.auth.provider.AuthProvider; import ru.gravit.launchserver.auth.provider.AuthProvider;
import ru.gravit.launchserver.auth.provider.AuthProviderResult; import ru.gravit.launchserver.auth.provider.AuthProviderResult;
@ -45,9 +46,7 @@ public void reply() throws Exception {
if (isClient) if (isClient)
client = input.readString(SerializeLimits.MAX_CLIENT); client = input.readString(SerializeLimits.MAX_CLIENT);
int auth_id = input.readInt(); int auth_id = input.readInt();
long hwid_hdd = input.readLong(); String hwid_str = input.readString(0);
long hwid_cpu = input.readLong();
long hwid_bios = input.readLong();
if (auth_id + 1 > server.config.authProvider.length || auth_id < 0) auth_id = 0; if (auth_id + 1 > server.config.authProvider.length || auth_id < 0) auth_id = 0;
byte[] encryptedPassword = input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH); byte[] encryptedPassword = input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH);
// Decrypt password // Decrypt password
@ -93,7 +92,7 @@ public void reply() throws Exception {
throw new AuthException("You profile not found"); 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) { } catch (AuthException | HWIDException e) {
requestError(e.getMessage()); requestError(e.getMessage());
return; return;

View file

@ -5,7 +5,7 @@
import ru.gravit.launcher.serialize.signed.SignedObjectHolder; import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.auth.AuthException; 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.hwid.HWIDException;
import ru.gravit.launchserver.auth.provider.AuthProvider; import ru.gravit.launchserver.auth.provider.AuthProvider;
import ru.gravit.launchserver.auth.provider.AuthProviderResult; import ru.gravit.launchserver.auth.provider.AuthProviderResult;

View file

@ -23,6 +23,7 @@
dependencies { dependencies {
compile project(':LauncherAPI') compile project(':LauncherAPI')
compile 'org.javassist:javassist:3.23.1-GA' compile 'org.javassist:javassist:3.23.1-GA'
compile group: 'com.github.oshi', name: 'oshi-core', version: '3.11.0'
} }
task genRuntimeJS(type: Zip) { task genRuntimeJS(type: Zip) {

View file

@ -118,7 +118,7 @@ function makeSetProfileRequest(profile, callback) {
function makeAuthRequest(login, rsaPassword, callback) { function makeAuthRequest(login, rsaPassword, callback) {
var task = rsaPassword === null ? newTask(offlineAuthRequest(login)) : 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); processing.setTaskProperties(task, callback, null, true);
task.updateMessage("Авторизация на сервере"); task.updateMessage("Авторизация на сервере");
startTask(task); startTask(task);

View file

@ -5,6 +5,7 @@
import ru.gravit.launcher.client.ClientLauncher; import ru.gravit.launcher.client.ClientLauncher;
import ru.gravit.launcher.hasher.FileNameMatcher; import ru.gravit.launcher.hasher.FileNameMatcher;
import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hasher.HashedDir;
import ru.gravit.launcher.hwid.OshiHWIDProvider;
import ru.gravit.launcher.request.Request; import ru.gravit.launcher.request.Request;
import ru.gravit.launcher.request.update.LegacyLauncherRequest; import ru.gravit.launcher.request.update.LegacyLauncherRequest;
import ru.gravit.launcher.request.websockets.RequestInterface; import ru.gravit.launcher.request.websockets.RequestInterface;
@ -20,6 +21,8 @@ public class FunctionalBridge {
public static LauncherSettings settings; public static LauncherSettings settings;
@LauncherAPI @LauncherAPI
public static RequestWorker worker; public static RequestWorker worker;
@LauncherAPI
public static OshiHWIDProvider hwidProvider = new OshiHWIDProvider();
@LauncherAPI @LauncherAPI
public HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, SignedObjectHolder<HashedDir> hdir, FileNameMatcher matcher, boolean digest) throws Exception { public HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, SignedObjectHolder<HashedDir> hdir, FileNameMatcher matcher, boolean digest) throws Exception {
@ -65,4 +68,9 @@ public void startTask(@SuppressWarnings("rawtypes") Task task)
LogHelper.error(e); LogHelper.error(e);
} }
} }
@LauncherAPI
public HWID getHWID()
{
return hwidProvider.getHWID();
}
} }

View file

@ -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;
}
}

View file

@ -5,6 +5,7 @@
import ru.gravit.launcher.Launcher; import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.LauncherConfig; import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.LauncherHWIDInterface;
import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.SecurityHelper;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launcher.profiles.PlayerProfile;
@ -33,31 +34,34 @@ private Result(PlayerProfile pp, String accessToken) {
private final byte[] encryptedPassword; private final byte[] encryptedPassword;
private final int auth_id; private final int auth_id;
private final LauncherHWIDInterface hwid;
@LauncherAPI @LauncherAPI
public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword) { public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword, LauncherHWIDInterface hwid) {
super(config); super(config);
this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty"); this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty");
this.encryptedPassword = encryptedPassword.clone(); this.encryptedPassword = encryptedPassword.clone();
this.hwid = hwid;
auth_id = 0; auth_id = 0;
} }
@LauncherAPI @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); super(config);
this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty"); this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty");
this.encryptedPassword = encryptedPassword.clone(); this.encryptedPassword = encryptedPassword.clone();
this.hwid = hwid;
this.auth_id = auth_id; this.auth_id = auth_id;
} }
@LauncherAPI @LauncherAPI
public AuthRequest(String login, byte[] encryptedPassword) { public AuthRequest(String login, byte[] encryptedPassword, LauncherHWIDInterface hwid) {
this(null, login, encryptedPassword); this(null, login, encryptedPassword,hwid);
} }
@LauncherAPI @LauncherAPI
public AuthRequest(String login, byte[] encryptedPassword, int auth_id) { public AuthRequest(String login, byte[] encryptedPassword, LauncherHWIDInterface hwid, int auth_id) {
this(null, login, encryptedPassword, auth_id); this(null, login, encryptedPassword, hwid, auth_id);
} }
@Override @Override
@ -72,9 +76,7 @@ protected Result requestDo(HInput input, HOutput output) throws IOException {
if (Launcher.profile != null) if (Launcher.profile != null)
output.writeString(Launcher.profile.getTitle(), SerializeLimits.MAX_CLIENT); output.writeString(Launcher.profile.getTitle(), SerializeLimits.MAX_CLIENT);
output.writeInt(auth_id); output.writeInt(auth_id);
output.writeLong(Launcher.isUsingAvanguard() ? GuardBind.avnGetHddId() : 0); output.writeString(hwid.getHWID().getSerializeString(),0);
output.writeLong(Launcher.isUsingAvanguard() ? GuardBind.avnGetCpuid() : 0);
output.writeLong(Launcher.isUsingAvanguard() ? GuardBind.avnGetSmbiosId() : 0);
output.writeByteArray(encryptedPassword, SecurityHelper.CRYPTO_MAX_LENGTH); output.writeByteArray(encryptedPassword, SecurityHelper.CRYPTO_MAX_LENGTH);
output.flush(); output.flush();

View file

@ -0,0 +1,6 @@
package ru.gravit.launcher;
public interface HWID {
String getSerializeString();
boolean isNull();
}

View file

@ -0,0 +1,5 @@
package ru.gravit.launcher;
public interface LauncherHWIDInterface {
HWID getHWID();
}

View file

@ -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;
}
}