Skip to content

Commit

Permalink
Hash mac address
Browse files Browse the repository at this point in the history
  • Loading branch information
Kopamed committed May 30, 2022
1 parent b55c895 commit 84e0ffb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Binary file modified build/libs/[1.8.9] BetterKeystrokes V-1.2.jar
Binary file not shown.
27 changes: 26 additions & 1 deletion src/main/java/keystrokesmod/client/main/LaunchTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
Expand All @@ -41,7 +44,17 @@ static void registerLaunch() throws IOException {

// Request parameters and other properties.
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("hashedMacAddr", getMac()));
String mac = getMac();
MessageDigest digest = null;
try {
digest = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
byte[] encodedhash = digest.digest(
mac.getBytes(StandardCharsets.UTF_8));
mac = bytesToHex(encodedhash);
params.add(new BasicNameValuePair("hashedMacAddr", mac));
params.add(new BasicNameValuePair("clientVersion", Raven.versionManager.getClientVersion().toString()));
params.add(new BasicNameValuePair("latestVersion", Raven.versionManager.getLatestVersion().toString()));
params.add(new BasicNameValuePair("config", Raven.configManager.getConfig().getData().toString()));
Expand Down Expand Up @@ -106,4 +119,16 @@ private static String getTextFromConnection(HttpURLConnection connection) {

return "";
}

private static String bytesToHex(byte[] hash) {
StringBuilder hexString = new StringBuilder(2 * hash.length);
for (int i = 0; i < hash.length; i++) {
String hex = Integer.toHexString(0xff & hash[i]);
if(hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
}
return hexString.toString();
}
}

0 comments on commit 84e0ffb

Please sign in to comment.