public void SetupTests() { license = new ClientLicense(); license.UniqueId = Guid.NewGuid(); license.LicenseSets = new NotifyList <LicenseSet>(); LicenseSet ls = new LicenseSet(); ls.SupportedLicenseTypes = LicenseKeyTypeFlag.SingleUser; ls.Name = "Standard License Set"; ls.UniquePad = new Guid(); license.LicenseSets.Add(ls); generationOptions = new LicenseGenerationOptions(); license.Product = new Product(); license.Product.Name = "My Great Uber Cool Product, with new juice!"; license.Product.ProductId = 1; packingService = new PackingService(numberDataGenerationProvider); clientLicenseRepository = new ClientLicenseRepository(objectSerializationProvider, symmetricEncryptionProvider); clientLicenseService = new ClientLicenseService(clientLicenseRepository); string productHash = hashingProvider.Checksum32(license.GetLicenseProductIdentifier()).ToString("X"); LicenseActiviationProvider licenseActiviationProvider = new LicenseActiviationProvider(asymmetricEncryptionProvider, symmetricEncryptionProvider, objectSerializationProvider); staticKeyGenerator = new KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider); staticKeyGeneratorLarge = new Scutex.Generators.StaticKeyGeneratorLarge.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider, hardwareFingerprintService); licenseKeyService = new LicenseKeyService(staticKeyGenerator, staticKeyGeneratorLarge, packingService, clientLicenseService); }
public LicenseSetFeaturesWindow(Window parent, Product product, LicenseSet licenseSet) : this(parent) { _licenseSet = licenseSet; _product = product; gridProductFeatures.ItemsSource = new ObservableCollection <Feature>(ObjectLocator.GetInstance <IFeaturesService>().GetFeaturesForProduct(_product.ProductId)); lblTitle.Text = _product.Name + " - " + _licenseSet.Name; }
public void SaveLicenseKeysForLicenseSet(LicenseSet licenseSet, List <string> keys) { foreach (string k in keys) { LicenseKey lk = new LicenseKey(); lk.CreatedOn = DateTime.Now; lk.Key = k; lk.LicenseSetId = licenseSet.LicenseSetId; lk.HashedLicenseKey = _hashingProvider.ComputeHash(k, Properties.Resources.KeyHashingAlgo); _licenseKeyRepoistory.InsertLicenseKey(lk); } }
private void InsertServiceLicenseSet(ServiceLicenseSet licenseSet) { using (ScutexServiceEntities db1 = new ScutexServiceEntities()) { LicenseSet ls = new LicenseSet(); ls.LicenseSetId = licenseSet.LicenseSetId; ls.LicenseId = licenseSet.LicenseId; ls.Name = licenseSet.LicenseSetName; ls.LicenseType = (int)licenseSet.LicenseType; ls.MaxUsers = licenseSet.MaxUsers; db1.AddToLicenseSets(ls); db1.SaveChanges(); } }
private void btnRemoveLicenseSet_Click(object sender, RoutedEventArgs e) { if (gridLicenseSets.SelectedItem != null) { LicenseSet licSet = gridLicenseSets.SelectedItem as LicenseSet; if (MessageBox.Show(string.Format("Are you sure you want to delete the {0} license set?", licSet.Name), "Delete License Set", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { License.LicenseSets.Remove(License.LicenseSets.Where(x => x.Name == licSet.Name).First()); //SyncData(); } } else { MessageBox.Show("You must select a license set to remove."); } }
public List <string> GetServiceLicenseKeysForSet(LicenseSet licenseSet, Service service) { string mgmtToken = _packingService.PackToken(service.GetManagementToken()); GetLicenseKeysForProductData data = new GetLicenseKeysForProductData(); data.LicenseSetId = licenseSet.LicenseSetId; GetLicenseKeysForProductResult result = _productsProvider.GetLicenseKeysForLicenseSet(service.ManagementUrl, mgmtToken, GetManagementStandardEncryptionInfo(service), service.GetManagementServiceKeyPair(), data); if (IsResultValid(result)) { return(result.LicenseKeys); } return(new List <string>()); }
public bool AddLicenseKeysToService(LicenseSet licenseSet, Service service, List <string> keys) { string mgmtToken = _packingService.PackToken(service.GetManagementToken()); AddLicenseKeysForProductData data = new AddLicenseKeysForProductData(); data.LicenseSetId = licenseSet.LicenseSetId; data.Keys = keys; AddLicenseKeysForProductResult result = _productsProvider.AddLicenseKeysForLicenseSet(service.ManagementUrl, mgmtToken, GetManagementStandardEncryptionInfo(service), service.GetManagementServiceKeyPair(), data); if (IsResultValid(result)) { return(true); } return(false); }
internal ClientLicense CreateTestClientLicense(Service service) { ClientLicense cl = new ClientLicense(); cl.ServicesKeys = service.GetClientServiceKeyPair(); cl.Product = new Product(); cl.Product.Name = "Test Product"; cl.LicenseSets = new NotifyList <LicenseSet>(); LicenseSet ls = new LicenseSet(); ls.LicenseId = int.MaxValue; ls.LicenseSetId = int.MaxValue; ls.Name = "Test Product License Set"; ls.MaxUsers = 2; ls.SupportedLicenseTypes = LicenseKeyTypeFlag.MultiUser; cl.LicenseSets.Add(ls); return(cl); }
/// <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); }
public override void Unpersist(SessionBase session) { if (IsPersistent == false) { return; } foreach (LicenseRequest r in LicenseRequestSet) { r.Unpersist(session); } LicenseRequestSet.Unpersist(session); foreach (LicensePayment r in LicensePaymentSet) { r.Unpersist(session); } LicensePaymentSet.Unpersist(session); //foreach (VisitEvent r in visitEvents) // r.Unpersist(session, disableFlush); //visitEvents.Unpersist(session, disableFlush); LicenseUnpaidSet.Unpersist(session); LicenseSet.Unpersist(session); base.Unpersist(session); }
public IQueryable<Model.LicenseSet> InsertLicenseSet(Model.LicenseSet licenseSet) { int newId; //using (ScutexEntities db1 = new ScutexEntities()) //{ LicenseSet ls = new LicenseSet(); Mapper.CreateMap<Model.LicenseSet, LicenseSet>(); ls = Mapper.Map<Model.LicenseSet, LicenseSet>(licenseSet); ls.LicenseType = (int)licenseSet.SupportedLicenseTypes; db.AddToLicenseSets(ls); db.SaveChanges(); newId = ls.LicenseSetId; //} CreateLicsenSetFeatures(newId, licenseSet.Features); return GetLicenseSetById(newId); }
public IQueryable <Model.LicenseSet> InsertLicenseSet(Model.LicenseSet licenseSet) { int newId; //using (ScutexEntities db1 = new ScutexEntities()) //{ LicenseSet ls = new LicenseSet(); Mapper.CreateMap <Model.LicenseSet, LicenseSet>(); ls = Mapper.Map <Model.LicenseSet, LicenseSet>(licenseSet); ls.LicenseType = (int)licenseSet.SupportedLicenseTypes; db.AddToLicenseSets(ls); db.SaveChanges(); newId = ls.LicenseSetId; //} CreateLicsenSetFeatures(newId, licenseSet.Features); return(GetLicenseSetById(newId)); }
private void btnUploadLicenseSets_Click(object sender, RoutedEventArgs e) { if (cboServices.SelectedValue != null) { if (gridLocalServices.SelectedItem != null) { if (DoesLicenseSetExistOnService() == false) { BackgroundWorker worker = new BackgroundWorker(); loadingAnimation.Visibility = Visibility.Visible; var productDisplayData = gridLocalServices.SelectedItem as UploadProductDisplayData; worker.DoWork += delegate(object s, DoWorkEventArgs args) { object[] data = args.Argument as object[]; IServicesService servicesService = ObjectLocator.GetInstance <IServicesService>(); ILicenseSetService licenseSetService = ObjectLocator.GetInstance <ILicenseSetService>(); ILicenseService licenseService = ObjectLocator.GetInstance <ILicenseService>(); //LicenseSet licenseSet = (LicenseSet) data[0]; License license = licenseService.GetLicenseById(((UploadProductDisplayData)data[0]).LicenseId); LicenseSet licenseSet = licenseSetService.GetLiceseSetById(((UploadProductDisplayData)data[0]).LicenseSetId); List <LicenseSet> sets = new List <LicenseSet>(); sets.Add(licenseSet); servicesService.AddProductToService(license, sets, data[1] as Service); Dictionary <License, List <LicenseSet> > _servicesData = servicesService.GetServiceLicenses((Service)data[1]); args.Result = _servicesData; }; worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args) { servicesData = (Dictionary <License, List <LicenseSet> >)args.Result; gridRemoteServices.ItemsSource = DataConverters.ConvertAllLicensesSetsToDisplay(servicesData); loadingAnimation.Visibility = Visibility.Collapsed; }; worker.RunWorkerAsync(new object[] { productDisplayData, cboServices.SelectedValue }); } else { MessageBox.Show("The License Set you selected already exists in the service"); } } else { MessageBox.Show("You must select a License/LicenseSet to upload"); } } else { MessageBox.Show("You must select a service to upload to."); } }
private void btnAddLicenseSet_Click(object sender, RoutedEventArgs e) { if (IsLicenseSetFormValid()) { var licSet = from ls in License.LicenseSets where ls.Name == txtLicenseSetName.Text.Trim() select ls; if (licSet.Count() > 0) { MessageBox.Show(string.Format("LicenseSet name [{0}] is already in use in this project.", txtLicenseSetName.Text.Trim())); return; } if (((KeyGeneratorTypes)cboLicenseKeyType.SelectedItem) == KeyGeneratorTypes.StaticSmall && License.LicenseSets.Count >= 1) { MessageBox.Show("The Small Static Key Generator only supports a maximum of 1 license set."); return; } LicenseSet l = new LicenseSet(); l.Name = txtLicenseSetName.Text.Trim(); LicenseKeyTypeFlag flag = new LicenseKeyTypeFlag(); if (chkSingleUser.IsChecked.HasValue && chkSingleUser.IsChecked.Value) { flag = LicenseKeyTypeFlag.SingleUser; } if (chkMultiUser.IsChecked.HasValue && chkMultiUser.IsChecked.Value) { flag = flag | LicenseKeyTypeFlag.MultiUser; } if (chkHardwareLock.IsChecked.HasValue && chkHardwareLock.IsChecked.Value) { flag = flag | LicenseKeyTypeFlag.HardwareLock; } if (chkUnlimited.IsChecked.HasValue && chkUnlimited.IsChecked.Value) { flag = flag | LicenseKeyTypeFlag.Unlimited; } if (chkEnterprise.IsChecked.HasValue && chkEnterprise.IsChecked.Value) { flag = flag | LicenseKeyTypeFlag.Enterprise; } l.SupportedLicenseTypes = flag; if (String.IsNullOrEmpty(txtMaxUsers.Text) == false) { l.MaxUsers = int.Parse(txtMaxUsers.Text); } if (chkIsLicenseSetUpgradeOnly.IsChecked.HasValue) { l.IsUpgradeOnly = chkIsLicenseSetUpgradeOnly.IsChecked.Value; } else { l.IsUpgradeOnly = false; } License.LicenseSets.Add(l); License.RaisePropertyChanged("LicenseSets"); ResetNewLicenseSetForm(); SyncData(); } else { MessageBox.Show("Please fix the errors in the New License Set form and try again."); } }
public bool ValidateLicenseKey(string licenseKey, LicenseBase scutexLicense) { // Init all required variables for the process. Dictionary <int, LicensePlaceholder> placeholerLocations; List <LicensePlaceholder> licensePlaceholders = CreateLicensePlaceholders(scutexLicense, null); char[] licenseKeyArray; string decodedLicenseKey = licenseKey.Replace("-", ""); // Locate all the placeholder tokens in the license template placeholerLocations = FindAllPlaceholdersInTemplate(licenseKeyTemplate.Replace("-", ""), licensePlaceholders); // STEP 1: Basic length checks if (licenseKey.Length != licenseKeyTemplate.Length) { throw new ScutexLicenseException(Resources.ErrorMsg_VerifyLicenseKey); } if (decodedLicenseKey.Length != licenseKeyTemplate.Replace("-", "").Length) { throw new ScutexLicenseException(Resources.ErrorMsg_VerifyLicenseKey); } // STEP 2: Compute and verify all the checksum placeholders in the key foreach (var p in placeholerLocations) { if (p.Value.IsChecksum) { string originalHash; int originalHashValue; int verifyHashValue; try { originalHash = decodedLicenseKey.Substring(p.Key, p.Value.Length); originalHashValue = int.Parse(originalHash, System.Globalization.NumberStyles.HexNumber); verifyHashValue = hashingProvider.Checksum16(decodedLicenseKey.Substring(0, p.Key)); } catch { throw new ScutexLicenseException(Resources.ErrorMsg_VerifyLicenseKey); } if (originalHashValue != verifyHashValue) { throw new ScutexLicenseException(Resources.ErrorMsg_VerifyLicenseKey); } } } // STEP 3: DeObfuscate key license placeholders that are not checksums foreach (var p in placeholerLocations) { if (!p.Value.IsChecksum) { licenseKeyArray = decodedLicenseKey.ToCharArray(); for (int i = 0; i < p.Value.Length; i++) { char previousChar = licenseKeyArray[(p.Key) - 1]; char deObfKey = KeyIntegerValueDeObfuscator(previousChar, licenseKeyArray[p.Key + i], p.Key + i); licenseKeyArray[p.Key + i] = deObfKey; } decodedLicenseKey = new string(licenseKeyArray); } } // STEP 4: Validate each non-checksum placeholder foreach (var p in placeholerLocations) { if (!p.Value.IsChecksum) { switch (p.Value.ValidationType) { case ValidationTypes.LicenseKeyType: int licenseKeyTypeValue = 0; bool licenseKeyTypeValueCheck = int.TryParse(decodedLicenseKey.Substring(p.Key, p.Value.Length), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out licenseKeyTypeValue); // The LicenseKeyType value should be able to be converted to an int, else it is invalid if (!licenseKeyTypeValueCheck) { throw new ScutexLicenseException(Resources.ErrorMsg_VerifyLicenseKey); } LicenseKeyTypeFlag typeFlag; // It is possible that a LicenseKeyType has no supporting LicenseKeyTypeFlag (which means it was // placeholded in the LicenseKeyType enum but is not operable). If this parse (cast) fails then // there was a valid LicenseKeyType enum value but no valid LicenseKeyTypeFlag value. try { int type = licenseKeyTypeValue; if (((LicenseKeyTypes)licenseKeyTypeValue) == LicenseKeyTypes.HardwareLockLocal) { type = (int)LicenseKeyTypes.HardwareLock; } typeFlag = (LicenseKeyTypeFlag)Enum.Parse(typeof(LicenseKeyTypeFlag), ((LicenseKeyTypes)type).ToString(), true); } catch (Exception) { throw new ScutexLicenseException(Resources.ErrorMsg_VerifyLicenseKey); } LicenseSet ls = null; try { var licSetPH = placeholerLocations.Where(x => x.Value.ValidationType == ValidationTypes.LicenseSet).SingleOrDefault(); int licenseSetIdValue1 = int.Parse(decodedLicenseKey.Substring(licSetPH.Key, licSetPH.Value.Length)); Debug.WriteLine(string.Format("Decoded Key: {0}", decodedLicenseKey)); Debug.WriteLine(string.Format("LicenseSet Placeholder: {0}", licSetPH)); Debug.WriteLine(string.Format("LicenseSet Placeholder Key: {0}", licSetPH.Key)); Debug.WriteLine(string.Format("LicenseSet Placeholder Length: {0}", licSetPH.Value.Length)); Debug.WriteLine(string.Format("LicenseSetId Value: {0}", licenseSetIdValue1)); Debug.WriteLine(string.Format("LicenseSets: {0}", scutexLicense.LicenseSets.First().LicenseSetId)); ls = scutexLicense.LicenseSets.Where(x => x.LicenseSetId == licenseSetIdValue1).SingleOrDefault(); } catch { throw new ScutexLicenseException(Resources.ErrorMsg_VerifyLicenseKey); } Debug.WriteLine(string.Format("LicenseSet: {0}", ls)); if (ls == null) { throw new ScutexLicenseException(Resources.ErrorMsg_VerifyLicenseKey); } Debug.WriteLine(string.Format("LicenseSet Types: {0}", ls.SupportedLicenseTypes)); // If the LicenseSet does not support the key type supplied then throw an error if (!ls.SupportedLicenseTypes.IsSet(typeFlag)) { throw new ScutexLicenseException(Resources.ErrorMsg_VerifyLicenseKey); } break; case ValidationTypes.LicenseSet: int licenseSetIdValue = 0; bool licenseSetIdValueCheck = int.TryParse(decodedLicenseKey.Substring(p.Key, p.Value.Length), out licenseSetIdValue); // The LicenseSetId value should be able to be converted to an int, else it is invalid if (!licenseSetIdValueCheck) { throw new ScutexLicenseException(Resources.ErrorMsg_VerifyLicenseKey); } LicenseSet ls1 = null; try { ls1 = scutexLicense.LicenseSets.Where(x => x.LicenseSetId == licenseSetIdValue).SingleOrDefault(); } catch { throw new ScutexLicenseException(Resources.ErrorMsg_VerifyLicenseKey); } if (ls1 == null) { throw new ScutexLicenseException(Resources.ErrorMsg_VerifyLicenseKey); } break; case ValidationTypes.Product: int productIdValue = 0; bool productIdValueCheck = int.TryParse(decodedLicenseKey.Substring(p.Key, p.Value.Length), out productIdValue); // The ProductId value should be able to be converted to an int, else it is invalid if (!productIdValueCheck) { throw new ScutexLicenseException(Resources.ErrorMsg_VerifyLicenseKey); } if (scutexLicense.Product.ProductId != productIdValue) { throw new ScutexLicenseException(Resources.ErrorMsg_VerifyLicenseKey); } break; case ValidationTypes.Fingerprint: string fingerPrint = hashingProvider.Checksum16(_fingerprintService.GetHardwareFingerprint(FingerprintTypes.Default)).ToString("X"); if (fingerPrint != p.Value.Value) { throw new ScutexLicenseException(Resources.ErrorMsg_VerifyLicenseKey); } break; case ValidationTypes.ProductIdentifier: string prodId = hashingProvider.Checksum16(scutexLicense.GetLicenseProductIdentifier()).ToString("X"); prodId = prodId.PadLeft(4, char.Parse("0")); if (prodId != p.Value.Value) { throw new ScutexLicenseException(Resources.ErrorMsg_VerifyLicenseKey); } break; case ValidationTypes.None: string keyValue = decodedLicenseKey.Substring(p.Key, p.Value.Length); if (keyValue != p.Value.Value) { throw new ScutexLicenseException(Resources.ErrorMsg_VerifyLicenseKey); } break; default: throw new ScutexLicenseException(Resources.ErrorMsg_VerifyLicenseKey); } } } return(true); }