private bool CheckIfActivated() { try { if (!KeyHelper.MatchCurrentHardwareId(HWID_)) { log.Error("HWID changed"); return(false); } KeyValidator keyVal = new KeyValidator(Tmpl_); keyVal.SetKey(LicenseKey_); keyVal.SetValidationData("Email", Email_); // the key will not be valid if you set a different user name than the one you have set at key generation LicensingClient licensingClient = new LicensingClient(Tmpl_, LicenseKey_, keyVal.QueryValidationData(null), HWID_, ActivationKey_); if (licensingClient.IsLicenseValid()) { byte[] featureSet = keyVal.QueryKeyData("FeatureSet"); featureSet.ToString(); return(true); } else { return(false); } } catch (Exception E) { log.Error("Program is not activated", E); return(false); } }
private async Task <Tuple <bool, int> > CheckLicensesByServiceAsync(LicenseInfo lic) { log.Debug("CheckLicensesByServiceAsync;"); LicensingClient client = new LicensingClient( LicensingClient.EndpointConfiguration.BasicHttpBinding_ILicensing, ServiceEndpoint) { RsaPublicKey = RsaPublicKey, Password = Password, }; foreach (var key in lic.License.Where(l => !l.Retired) .OrderByDescending(l => l.ExpireDate)) { var response = await client.CheckLicenseAsync( new LicenseCheckRequest { Hardware = hardware, Key = key.Key, Product = Product }); if (response.State == LicenseCheckResponse.LicenseState.OK) { key.Amount = response.Amount; return(Tuple.Create(true, response.TotalAmount)); } else { key.Retired = true; // retire keys expired, invalid, etc. key.RetireReason = response.State.ToString() + ": " + response.Message; } } return(Tuple.Create(false, 0)); }
static async Task Main(string[] args) { var config = new ConfigurationBuilder().AddUserSecrets("5a664fcb-5e4e-479d-872f-f47dbbb60ade").Build(); var client = new LicensingClient("https://aolicensing.azurewebsites.net", config["Codes:Master"]); Console.WriteLine("AOLicensing KeyManager"); Dictionary <string, (string, Func <string, string, Task>)> actions = new Dictionary <string, (string, Func <string, string, Task>)>() {
public void ValidateKey() { var client = new LicensingClient(HostUrl); var result = client.ValidateAsync(new LicenseKey() { Email = "*****@*****.**", Product = "SampleProduct", Key = "TUJQ-89Q8-IZA3" }).Result; Assert.IsTrue(result.Success); }
public void QueryKey() { var config = GetConfig(); var client = new LicensingClient(HostUrl, config["Codes:Master"]); var result = client.QueryAsync(new CreateKey() { Email = "*****@*****.**", Product = "SampleProduct" }).Result; Assert.IsTrue(result.Count > 0); }
public void CreateKey() { var config = GetConfig(); var client = new LicensingClient(HostUrl, config["Codes:Master"]); var result = client.CreateKeyAsync(new CreateKey() { Email = "*****@*****.**", Product = "SampleProduct" }).Result; Assert.IsTrue(!string.IsNullOrEmpty(result.Key)); }
public Gatekeeper(string url) { _client = new LicensingClient(url); }
public async Task <LicenseRegisterResult> RegisterLicenseAsync(string licenseKey) { LicensingClient client = new LicensingClient( LicensingClient.EndpointConfiguration.BasicHttpBinding_ILicensing, ServiceEndpoint) { Password = Password, RsaPublicKey = RsaPublicKey, }; var response = await client.RegisterLicenseAsync( new RegisterRequest { Hardware = hardware, Key = licenseKey, Product = Product }); if (response.State == RegisterResponse.RegisterState.OK || response.State == RegisterResponse.RegisterState.OKExisted) { LicenseInfo lic = GetStoredLicenseInfo() ?? new LicenseInfo { Counter = this.MaxCheckPostponeCount, Hardware = hardware, License = new License[] { }, }; var lickey = new License { Key = licenseKey, Retired = false, Type = 1, // dummy Amount = response.Amount, IssueDate = response.IssueDate.Value, ExpireDate = response.ExpireDate.Value, }; log.Debug(string.Format("RegisterLicenseAsync;IssueDate:{0},ExpireDate:{1}", response.IssueDate.Value, response.ExpireDate.Value)); lic.License = new[] { lickey }.Concat( lic.License.Where(k => string.Compare(k.Key, licenseKey, StringComparison.OrdinalIgnoreCase) != 0) ).ToArray(); lic.Counter = this.MaxCheckPostponeCount; StoreLicenseInfo(lic); return(new LicenseRegisterResult { State = response.State == RegisterResponse.RegisterState.OK ? LicenseRegisterState.OK : LicenseRegisterState.AlreadyLicensed, Amount = response.TotalAmount, Message = response.Message, }); } return(new LicenseRegisterResult { State = response.State == RegisterResponse.RegisterState.AlreadyUsed ? LicenseRegisterState.AlreadyUsed : response.State == RegisterResponse.RegisterState.Invalid ? LicenseRegisterState.InvalidKey : response.State == RegisterResponse.RegisterState.Expired ? LicenseRegisterState.Expired : LicenseRegisterState.StateError, Message = response.Message, }); }
public void ActivationTask(String email, String key) { string activationStatusStr = ""; KeyValidator keyVal = null; try { // validate the generated key. This sequence of code is also used in the actual product to validate the entered license key keyVal = new KeyValidator(Tmpl_); keyVal.SetKey(key); } catch (Exception ex) { OnActivation(false, "Key is incorrect"); log.Error("Key validation failed " + ex.Message); return; } try { keyVal.SetValidationData("Email", email); // the key will not be valid if you set a different user name than the one you have set at key generation LicensingClient licensingClient = new LicensingClient("https://activation.identamaster.com:444", Tmpl_, key, keyVal.QueryValidationData(null), CurrentHWID_, PRODUCT_ID); licensingClient.AcquireLicense(); LicenseKey_ = key; Email_ = email; ActivationKey_ = licensingClient.ActivationKey; HWID_ = CurrentHWID_; // save keys SaveKeys(); if (!licensingClient.IsLicenseValid()) { switch (licensingClient.LicenseStatus) { case LICENSE_STATUS.InvalidActivationKey: activationStatusStr = "invalid activation key"; break; case LICENSE_STATUS.InvalidHardwareId: activationStatusStr = "invalid hardware id"; break; case LICENSE_STATUS.Expired: { // the license expiration date returned by LicenseExpirationDate property is only valid if IsLicenseValid() returns true, // or if IsLicenseValid() returns false and LicenseStatus returns LicenseStatus.Expired DateTime expDate = licensingClient.LicenseExpirationDate; activationStatusStr = "license expired (expiration date: " + expDate.Month + "/" + expDate.Day + "/" + expDate.Year + ")"; } break; default: activationStatusStr = "unknown"; break; } OnActivation(false, activationStatusStr); } else { State = STATE.ACTIVATED; OnActivation(true, ""); return; } } catch (System.Net.WebException ex) { switch (ex.Status) { case System.Net.WebExceptionStatus.ConnectFailure: OnActivation(false, "Couldn't access activation server"); log.Error("Could not connect to server " + ex.Message); break; case System.Net.WebExceptionStatus.ProtocolError: OnActivation(false, "Server didn't validate this key"); log.Error("Key validation failed " + ex.Message); break; default: OnActivation(false, "Network error"); log.Error("Unknown network error " + ex.Message); break; } return; } catch (Exception ex) { OnActivation(false, "Failed"); log.Error("Key validation failed " + ex.Message); return; } }