diff --git a/src/main/java/stirling/software/SPDF/EE/KeygenLicenseVerifier.java b/src/main/java/stirling/software/SPDF/EE/KeygenLicenseVerifier.java index d82629d5c..f3f682578 100644 --- a/src/main/java/stirling/software/SPDF/EE/KeygenLicenseVerifier.java +++ b/src/main/java/stirling/software/SPDF/EE/KeygenLicenseVerifier.java @@ -12,6 +12,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.posthog.java.shaded.org.json.JSONObject; import lombok.extern.slf4j.Slf4j; +import stirling.software.SPDF.utils.GeneralUtils; @Service @Slf4j @@ -32,7 +33,6 @@ public class KeygenLicenseVerifier { // First, try to validate the license JsonNode validationResponse = validateLicense(licenseKey, machineFingerprint); - log.info(validationResponse.asText()); if (validationResponse != null) { boolean isValid = validationResponse.path("meta").path("valid").asBoolean(); String licenseId = validationResponse.path("data").path("id").asText(); @@ -185,8 +185,6 @@ public class KeygenLicenseVerifier { } private static String generateMachineFingerprint() { - // This is a simplified example. In a real-world scenario, you'd want to generate - // a more robust and unique fingerprint based on hardware characteristics. - return "example-fingerprint"; + return GeneralUtils.generateMachineFingerprint(); } } diff --git a/src/main/java/stirling/software/SPDF/EE/LicenseKeyChecker.java b/src/main/java/stirling/software/SPDF/EE/LicenseKeyChecker.java index 92b41009b..1b1e8cf6b 100644 --- a/src/main/java/stirling/software/SPDF/EE/LicenseKeyChecker.java +++ b/src/main/java/stirling/software/SPDF/EE/LicenseKeyChecker.java @@ -34,15 +34,19 @@ public class LicenseKeyChecker { } private void checkLicense() { - log.info(applicationProperties.toString()); - log.info(applicationProperties.getEnterpriseEdition().toString()); if (!applicationProperties.getEnterpriseEdition().isEnabled()) { enterpriseEnbaledResult = false; } else { enterpriseEnbaledResult = licenseService.verifyLicense( applicationProperties.getEnterpriseEdition().getKey()); + if (enterpriseEnbaledResult) { + log.info("License key is valid."); + } else { + log.info("License key is invalid."); + } } + } public void updateLicenseKey(String newKey) throws IOException { diff --git a/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java b/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java index be07780bc..85e1bb79c 100644 --- a/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java +++ b/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java @@ -30,6 +30,11 @@ import com.fathzer.soft.javaluator.DoubleEvaluator; import io.github.pixee.security.HostValidator; import io.github.pixee.security.Urls; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.util.Enumeration; public class GeneralUtils { @@ -301,4 +306,47 @@ public class GeneralUtils { } settingsYml.save(); } + + public static String generateMachineFingerprint() { + try { + // Get the MAC address + StringBuilder sb = new StringBuilder(); + InetAddress ip = InetAddress.getLocalHost(); + NetworkInterface network = NetworkInterface.getByInetAddress(ip); + + if (network == null) { + Enumeration networks = NetworkInterface.getNetworkInterfaces(); + while (networks.hasMoreElements()) { + NetworkInterface net = networks.nextElement(); + byte[] mac = net.getHardwareAddress(); + if (mac != null) { + for (int i = 0; i < mac.length; i++) { + sb.append(String.format("%02X", mac[i])); + } + break; // Use the first network interface with a MAC address + } + } + } else { + byte[] mac = network.getHardwareAddress(); + if (mac != null) { + for (int i = 0; i < mac.length; i++) { + sb.append(String.format("%02X", mac[i])); + } + } + } + + // Hash the MAC address for privacy and consistency + MessageDigest md = MessageDigest.getInstance("SHA-256"); + byte[] hash = md.digest(sb.toString().getBytes(StandardCharsets.UTF_8)); + StringBuilder fingerprint = new StringBuilder(); + for (byte b : hash) { + fingerprint.append(String.format("%02x", b)); + } + + return fingerprint.toString(); + + } catch (Exception e) { + return "GenericID"; + } + } }