licensing: HWID diagnosability, matcher widening, delete-condition fix
- hwid.cpp: BitStream3 buffer 125 -> 160 bits (writes totalled 147 bits and overflowed the old allocation; encoded HWID bytes unchanged). Log component availability (uuid/cpu/mac/hdd) once per distinct HWID, and warn when WMI yields no components at all. - Matcher widened only, generation untouched: exact-string match short-circuits, UUID match accepts any WMI list entry (generator hashes the last valid one), fuzzy-match point breakdown is logged so field status-12 rejections are diagnosable. - ANSLicense.cpp: fix inverted delete condition (!p != NULL) at 6 sites; detect the shared "empty fingerprint" HWID of WMI-broken PCs and warn with repair steps; mask activation keys in error strings. - licensingclient.h: explain SetKey/validation/NTP failures on stderr. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <cstdio>
|
||||
|
||||
#include "except.h"
|
||||
#include "template.h"
|
||||
@@ -172,13 +173,15 @@ public:
|
||||
if (!licenseKeyValidationData.empty())
|
||||
validator.SetValidationData("LicenseKeyValidationData", licenseKeyValidationData.data(), (activationTemplate->GetValidationDataSize() + 7) >> 3);
|
||||
|
||||
try
|
||||
try
|
||||
{
|
||||
validator.SetKey(activationKey.c_str());
|
||||
}
|
||||
catch (Exception * ex)
|
||||
{
|
||||
ex->Destroy();
|
||||
fprintf(stderr, "[anslicensing] activation key is %s (SetKey failed) - product needs (re)activation\n",
|
||||
activationKey.empty() ? "empty" : "malformed");
|
||||
activationStatus = STATUS_INVALID_ACTIVATION_KEY;
|
||||
if (ownActivationTemplate) delete activationTemplate;
|
||||
return false;
|
||||
@@ -186,6 +189,7 @@ public:
|
||||
|
||||
if (!validator.IsKeyValid())
|
||||
{
|
||||
fprintf(stderr, "[anslicensing] activation key does not validate against this license key + hardware id\n");
|
||||
activationStatus = STATUS_INVALID_ACTIVATION_KEY;
|
||||
if (ownActivationTemplate) delete activationTemplate;
|
||||
return false;
|
||||
@@ -222,6 +226,7 @@ public:
|
||||
{
|
||||
if (timeValidationMethod == USE_INTERNET_TIME) // internet time was mandatory
|
||||
{
|
||||
fprintf(stderr, "[anslicensing] could not obtain internet time (NTP) and internet time is mandatory - check network/firewall\n");
|
||||
activationStatus = STATUS_NET_ERROR;
|
||||
if (ownActivationTemplate) delete activationTemplate;
|
||||
return false;
|
||||
@@ -239,14 +244,18 @@ public:
|
||||
if (diffSeconds < 0)
|
||||
{
|
||||
m_licenseValidityDays = licenseTemplate->GetLicenseGracePeriod() - (int)(((time_t)(-diffSeconds) + 86400 - 1) / 86400);
|
||||
|
||||
|
||||
if (m_licenseValidityDays < 0)
|
||||
m_licenseValidityDays = 0;
|
||||
|
||||
|
||||
fprintf(stderr, "[anslicensing] license expired on %04d-%02d-%02d (grace days remaining: %d)\n",
|
||||
1900 + licenseExpirationTime.tm_year, 1 + licenseExpirationTime.tm_mon, licenseExpirationTime.tm_mday,
|
||||
m_licenseValidityDays);
|
||||
|
||||
activationStatus = STATUS_LICENSE_EXPIRED;
|
||||
|
||||
|
||||
if (ownActivationTemplate) delete activationTemplate;
|
||||
|
||||
|
||||
return false;
|
||||
} else
|
||||
m_licenseValidityDays = licenseTemplate->GetLicenseGracePeriod() + (int)(((time_t)diffSeconds + 86400 - 1) / 86400);
|
||||
@@ -465,6 +474,9 @@ public:
|
||||
generator.SetValidationData("LicenseKeyValidationData", licenseKeyValidationData.data(), licenseKeyValidationDataLen * 8);
|
||||
}
|
||||
|
||||
fprintf(stderr, "[anslicensing] requesting activation key from licensing service: %s (hwid %s)\n",
|
||||
activationTemplate->GetLicensingServiceUrl(), hardwareId.c_str());
|
||||
|
||||
try {
|
||||
activationKey = generator.GenerateKey();
|
||||
}
|
||||
@@ -472,19 +484,29 @@ public:
|
||||
{
|
||||
if ((ex->GetCode() == STATUS_NET_ERROR) && (generator.GetSigningServiceStatusCode() == 406))
|
||||
{
|
||||
fprintf(stderr, "[anslicensing] licensing service returned HTTP 406 - payment required\n");
|
||||
m_licenseValidationResult.SetPaymentRequired(true);
|
||||
ex->Destroy();
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "[anslicensing] activation request failed (service HTTP status %d) - check network access to the licensing service\n",
|
||||
generator.GetSigningServiceStatusCode());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
if (ValidateActivationKey(activationTemplate.get(), false))
|
||||
{
|
||||
fprintf(stderr, "[anslicensing] activation key acquired and validated (service HTTP status %d)\n",
|
||||
generator.GetSigningServiceStatusCode());
|
||||
activationStatus = STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "[anslicensing] licensing service returned an activation key that does not validate for this hardware id\n");
|
||||
throw new LicensingException(STATUS_GENERIC_ERROR, "internal error - invalid returned activation key");
|
||||
}
|
||||
|
||||
m_licenseValidationResult.m_license = std::make_unique<LicenseImpl>();
|
||||
|
||||
@@ -531,10 +553,12 @@ public:
|
||||
|
||||
const char * GetCurrentHardwareIdCallback()
|
||||
{
|
||||
if (parentUsesWideChar)
|
||||
if (parentUsesWideChar)
|
||||
{
|
||||
static string hwid = w2s(GetCurrentHardwareIdW(parentLicensingClient));
|
||||
return hwid.c_str();
|
||||
// per-instance storage: a function-local static would freeze the
|
||||
// first client's HWID for the lifetime of the process
|
||||
currentHwidCache = w2s(GetCurrentHardwareIdW(parentLicensingClient));
|
||||
return currentHwidCache.c_str();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -587,6 +611,7 @@ private:
|
||||
string licenseKey;
|
||||
string activationKey;
|
||||
string hardwareId;
|
||||
string currentHwidCache;
|
||||
string licensingServiceUrl;
|
||||
|
||||
vector<unsigned char> licenseKeyValidationData;
|
||||
|
||||
Reference in New Issue
Block a user