public Guid? ActivateLicenseKey(string licenseKey, Guid? originalToken, ServiceLicense licenseBase) { SecureString hashedLicenseKey = SecureStringHelper.StringToSecureString(_hashingProvider.ComputeHash(licenseKey, Resources.KeyHashAlgo)); hashedLicenseKey.MakeReadOnly(); int licenseSetId = licenseBase.LicenseSets.First().LicenseSetId;// TODO: Only works for SSLK LicenseSet ls = _clientRepository.GetLicenseSetById(licenseSetId); LicenseActivation la = _clientRepository.GetLicenseActivationByKeyAndSetId(SecureStringHelper.SecureStringToString(hashedLicenseKey), licenseSetId); if (AuthorizeLicenseForActivation(licenseKey, licenseBase)) { ServiceLicenseKey lk = _serviceProductsRepository.GetServiceLicenseKeyByKeyLicenseSet(SecureStringHelper.SecureStringToString(hashedLicenseKey), licenseSetId); la = new LicenseActivation(); la.LicenseKeyId = lk.LicenseKeyId; la.ActivatedOn = DateTime.Now; la.ActivationToken = Guid.NewGuid(); la.OriginalToken = originalToken; la.HardwareHash = licenseBase.HardwareHash; la.ActivationStatus = ActivationStatus.Normal; la.ActivationStatusUpdatedOn = DateTime.Now; _clientRepository.InsertLicenseActivation(la); lk.ActivationCount++; _serviceProductsRepository.SaveServiceLicenseKey(lk); return la.ActivationToken; } return null; }
/// <summary> /// Attempts to activate the license key /// </summary> /// <param name="licenseKey"></param> /// <param name="originalToken"></param> /// <param name="licenseBase"></param> /// <param name="hardwareFingerprint"></param> /// <returns></returns> public Guid? ActivateLicenseKey(string licenseKey, Guid? originalToken, ServiceLicense licenseBase, string hardwareFingerprint) { KeyData keyData = _licenseKeyService.GetLicenseKeyData(licenseKey, licenseBase, true); SecureString hashedLicenseKey = SecureStringHelper.StringToSecureString(_hashingProvider.ComputeHash(licenseKey, Resources.KeyHashAlgo)); hashedLicenseKey.MakeReadOnly(); int licenseSetId = keyData.LicenseSetId;// TODO: Only works for SSLK LicenseSet ls = _clientRepository.GetLicenseSetById(licenseSetId); LicenseActivation la = _clientRepository.GetLicenseActivationByKeyAndSetId(SecureStringHelper.SecureStringToString(hashedLicenseKey), licenseSetId); if (AuthorizeLicenseForActivation(licenseKey, licenseBase, hardwareFingerprint)) // TODO: Possible double call with two log entries here, as this is called in the parent as well. -SJ { ServiceLicenseKey lk = _serviceProductsRepository.GetServiceLicenseKeyByKeyLicenseSet(SecureStringHelper.SecureStringToString(hashedLicenseKey), licenseSetId); la = new LicenseActivation(); la.LicenseKeyId = lk.LicenseKeyId; la.ActivatedOn = DateTime.Now; la.ActivationToken = Guid.NewGuid(); la.OriginalToken = originalToken; la.ActivationStatus = ActivationStatus.Normal; la.ActivationStatusUpdatedOn = DateTime.Now; if (!String.IsNullOrEmpty(hardwareFingerprint)) la.HardwareHash = hardwareFingerprint; _clientRepository.InsertLicenseActivation(la); lk.ActivationCount++; _serviceProductsRepository.SaveServiceLicenseKey(lk); return la.ActivationToken; } return null; }
/// <summary> /// Authorizes a license key to check to see if it can be activated. If not, logs the failure reason and /// returns false. /// </summary> /// <param name="licenseKey"></param> /// <param name="licenseBase"></param> /// <param name="hardwareFingerprint"></param> /// <returns></returns> public bool AuthorizeLicenseForActivation(string licenseKey, ServiceLicense licenseBase, string hardwareFingerprint) { KeyData keyData = _licenseKeyService.GetLicenseKeyData(licenseKey, licenseBase, true); // Step 1: Validate the physical key bool keyValid = _licenseKeyService.ValidateLicenseKey(licenseKey, licenseBase, true); if (!keyValid) { _activationLogService.LogActiviation(licenseKey, ActivationResults.ValidationFailure, null); return false; } SecureString hashedLicenseKey = SecureStringHelper.StringToSecureString(_hashingProvider.ComputeHash(licenseKey, Resources.KeyHashAlgo)); hashedLicenseKey.MakeReadOnly(); // Step 2: Validate the key against the service if (!DoesKeyExistForLicenseSet(SecureStringHelper.SecureStringToString(hashedLicenseKey), keyData.LicenseSetId)) { _activationLogService.LogActiviation(licenseKey, ActivationResults.UnknownKeyFailure, null); return false; } // Step 3: Is this key used already if (!IsKeyAvialable(SecureStringHelper.SecureStringToString(hashedLicenseKey), keyData.LicenseSetId, hardwareFingerprint)) { _activationLogService.LogActiviation(licenseKey, ActivationResults.TooManyFailure, null); return false; } return true; }
public bool AuthorizeLicenseForActivation(string licenseKey, ServiceLicense licenseBase) { // Step 1: Validate the physical license bool keyValid = _licenseKeyService.ValidateLicenseKey(licenseKey, licenseBase, true); if (!keyValid) { _activationLogService.LogActiviation(licenseKey, ActivationResults.ValidationFailure, null); return false; } SecureString hashedLicenseKey = SecureStringHelper.StringToSecureString(_hashingProvider.ComputeHash(licenseKey, Resources.KeyHashAlgo)); hashedLicenseKey.MakeReadOnly(); // Step 2: Validate the key itself if (!DoesKeyExistForLicenseSet(SecureStringHelper.SecureStringToString(hashedLicenseKey), licenseBase.LicenseSets.First().LicenseSetId)) // TODO: Only works for SSLK { _activationLogService.LogActiviation(licenseKey, ActivationResults.UnknownKeyFailure, null); return false; } if (!IsKeyAvialable(SecureStringHelper.SecureStringToString(hashedLicenseKey), licenseBase.LicenseSets.First().LicenseSetId)) // TODO: Only works for SSLK { _activationLogService.LogActiviation(licenseKey, ActivationResults.TooManyFailure, null); return false; } return true; }