Ejemplo n.º 1
0
        public List<string> GenerateLicenseKeys(string rsaXmlString, LicenseBase scutexLicense, LicenseGenerationOptions generationOptions, int count)
        {
            HashSet<string> licenses = new HashSet<string>();
            int doupCount = 0;

            while (licenses.Count < count)
            {
                string key = GenerateLicenseKey(rsaXmlString, scutexLicense, generationOptions);

                if (licenses.Contains(key) == false)
                {
                    licenses.Add(key);
                    //Debug.WriteLine(string.Format("{0} of {1} keys generated", licenses.Count, count));
                }
                else
                {
                    doupCount++;
                    Debug.WriteLine(string.Format("Duplicate key was generated {0}", key));
                }
            }

            if (doupCount > 0)
                Debug.WriteLine(string.Format("{0} duplicate keys were generated at a {1}% chance", doupCount, doupCount * 100m / count));

            return licenses.ToList();
        }
			public void Before_each_test()
			{
				asymmetricEncryptionProvider = new AsymmetricEncryptionProvider();
				symmetricEncryptionProvider = new SymmetricEncryptionProvider();
				hashingProvider = new HashingProvider();

				smallKeyGenerator = new KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider);

				license = new ClientLicense();
				generationOptions = new LicenseGenerationOptions();

				license.UniqueId = Guid.NewGuid();
				license.Product = new Product();
				license.Product.Name = "My Great Uber Cool Product, with new juice!";
				license.Product.ProductId = 1;

				license.LicenseSets = new NotifyList<LicenseSet>();
				license.LicenseSets.Add(new LicenseSet());

				license.LicenseSets.First().SupportedLicenseTypes = LicenseKeyTypeFlag.SingleUser;
				license.LicenseSets.First().SupportedLicenseTypes |= LicenseKeyTypeFlag.Enterprise;
				license.LicenseSets.First().SupportedLicenseTypes |= LicenseKeyTypeFlag.Unlimited;

				generationOptions.LicenseKeyType = LicenseKeyTypes.Enterprise;

				string productHash = hashingProvider.Checksum32(license.GetLicenseProductIdentifier()).ToString("X");

				placeholders = smallKeyGenerator.CreateLicensePlaceholders(license, generationOptions);
				placeholdersInTemplate = KeyGenerator.FindAllPlaceholdersInTemplate(KeyGenerator.licenseKeyTemplate, placeholders);

				key = smallKeyGenerator.GenerateLicenseKey("TEST", license, generationOptions);
			}
Ejemplo n.º 3
0
		public string GenerateLicenseKey(string rsaXmlString, LicenseBase scutexLicense,
		                                 LicenseGenerationOptions generationOptions)
		{
			if (generationOptions.GeneratorType == KeyGeneratorTypes.StaticSmall)
				return keyGenerator.GenerateLicenseKey(rsaXmlString, scutexLicense, generationOptions);
			else
				return _largeKeyGenerator.GenerateLicenseKey(rsaXmlString, scutexLicense, generationOptions);
		}
Ejemplo n.º 4
0
        private void btnGenerateKeys_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (IsGenerationFormValid())
            {
                loadingAnimation.Visibility = Visibility.Visible;

                BackgroundWorker worker = new BackgroundWorker();
                LicenseGenerationOptions licenseGenerationOptions = new LicenseGenerationOptions();

                if (cboSingleUser.IsChecked.HasValue && cboSingleUser.IsChecked.Value)
                    licenseGenerationOptions.LicenseKeyType = LicenseKeyTypes.SingleUser;
                else if (cboMultiUser.IsChecked.HasValue && cboMultiUser.IsChecked.Value)
                    licenseGenerationOptions.LicenseKeyType = LicenseKeyTypes.MultiUser;
                else if (cboHardwareLock.IsChecked.HasValue && cboHardwareLock.IsChecked.Value)
                    licenseGenerationOptions.LicenseKeyType = LicenseKeyTypes.HardwareLock;
                else if (cboUnlimited.IsChecked.HasValue && cboUnlimited.IsChecked.Value)
                    licenseGenerationOptions.LicenseKeyType = LicenseKeyTypes.Unlimited;
                else if (cboEnterprise.IsChecked.HasValue && cboEnterprise.IsChecked.Value)
                    licenseGenerationOptions.LicenseKeyType = LicenseKeyTypes.Enterprise;

                worker.DoWork += delegate(object s, DoWorkEventArgs args)
                                                    {
                                                        object[] data = args.Argument as object[];

                                                        IKeyGenerator keygen = ObjectLocator.GetInstance<IKeyGenerator>((string)data[2]);
                                                        ILicenseActiviationProvider licenseActiviationProvider = ObjectLocator.GetInstance<ILicenseActiviationProvider>();
                                                        IPackingService packingService = ObjectLocator.GetInstance<IPackingService>();
                                                        IClientLicenseService clientLicenseService = ObjectLocator.GetInstance<IClientLicenseService>();

                                                        LicenseKeyService service = new LicenseKeyService(keygen, packingService, clientLicenseService);
                                                        List<string> keys = service.GenerateLicenseKeys(UIContext.License.KeyPair.PrivateKey,
                                                                                                                                                        UIContext.License,
                                                                                                                                                        (LicenseGenerationOptions)data[0],
                                                                                                                                                        int.Parse(data[1].ToString()));

                                                        args.Result = keys;
                                                    };

                worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
                                                                            {
                                                                                LicenseKeys = new BindingList<string>((List<string>)args.Result);
                                                                                lstLicenseKeys.ItemsSource = LicenseKeys;
                                                                                loadingAnimation.Visibility = Visibility.Collapsed;
                                                                            };

                worker.RunWorkerAsync(new object[]
                                      	{
                                      		licenseGenerationOptions,
                                      		txtKeysToGenerate.Text,
                                      		GetGeneratorName()
                                      	});
            }
            else
            {
                MessageBox.Show("Please select a license set, license type to generate and a amount.");
            }
        }
Ejemplo n.º 5
0
		internal List<LicensePlaceholder> CreateLicensePlaceholders(LicenseBase scutexLicense, LicenseGenerationOptions generationOptions)
		{
			List<LicensePlaceholder> placeholders = new List<LicensePlaceholder>();
			string payload = null;

			if (generationOptions != null)
			{
				placeholders.Add(new LicensePlaceholder
				                 	{
				                 		Length = 1,
				                 		Token = Char.Parse("k"),
				                 		Type = PlaceholderTypes.Number,
				                 		Value = ((int) generationOptions.LicenseKeyType).ToString("X"),
				                 		IsChecksum = false,
				                 		ValidationType = ValidationTypes.LicenseKeyType
				                 	});

				placeholders.Add(new LicensePlaceholder
				                 	{
				                 		Length = 1,
				                 		Token = Char.Parse("s"),
				                 		Type = PlaceholderTypes.Number,
				                 		Value = generationOptions.LicenseSetId.ToString(),
				                 		IsChecksum = false,
				                 		ValidationType = ValidationTypes.LicenseSet
				                 	});

				if (generationOptions.LicenseKeyType == LicenseKeyTypes.HardwareLockLocal)
				{
					placeholders.Add(new LicensePlaceholder
					                 	{
					                 		Length = 4,
					                 		Token = Char.Parse("p"),
					                 		Type = PlaceholderTypes.String,
															Value = hashingProvider.Checksum16(generationOptions.HardwareFingerprint).ToString("X"),
					                 		IsChecksum = false,
					                 		ValidationType = ValidationTypes.Fingerprint
					                 	});
				}
				else
				{
					payload = hashingProvider.Checksum16(scutexLicense.GetLicenseProductIdentifier()).ToString("X");
					payload = payload.PadLeft(4, char.Parse("0"));

					placeholders.Add(new LicensePlaceholder
					{
						Length = 4,
						Token = Char.Parse("p"),
						Type = PlaceholderTypes.String,
						Value = payload,
						IsChecksum = false,
						ValidationType = ValidationTypes.ProductIdentifier
					});
				}
			}
			else
			{
				placeholders.Add(new LicensePlaceholder
				{
					Length = 1,
					Token = Char.Parse("k"),
					Type = PlaceholderTypes.Number,
					Value = "0",
					IsChecksum = false,
					ValidationType = ValidationTypes.LicenseKeyType
				});

				placeholders.Add(new LicensePlaceholder
				{
					Length = 1,
					Token = Char.Parse("s"),
					Type = PlaceholderTypes.Number,
					Value = "0",
					IsChecksum = false,
					ValidationType = ValidationTypes.LicenseSet
				});

				payload = hashingProvider.Checksum16(scutexLicense.GetLicenseProductIdentifier()).ToString("X");
				payload = payload.PadLeft(4, char.Parse("0"));

				placeholders.Add(new LicensePlaceholder
				{
					Length = 4,
					Token = Char.Parse("p"),
					Type = PlaceholderTypes.String,
					Value = payload,
					IsChecksum = false,
					ValidationType = ValidationTypes.ProductIdentifier
				});
			}

			placeholders.Add(new LicensePlaceholder
			{
				Length = 1,
				Token = Char.Parse("v"),
				Type = PlaceholderTypes.Number,
				Value = ((int)LicenseDataCheckTypes.Standard).ToString(),
				IsChecksum = false
			});

			placeholders.Add(new LicensePlaceholder
			{
				Length = 2,
				Token = Char.Parse("a"),
				Type = PlaceholderTypes.Number,
				Value = scutexLicense.Product.GetFormattedProductId(2),
				IsChecksum = false,
				ValidationType = ValidationTypes.Product
			});

			placeholders.Add(new LicensePlaceholder
			{
				Length = 4,
				Token = Char.Parse("c"),
				Type = PlaceholderTypes.Number,
				Value = "",
				IsChecksum = true,
				ValidationType = ValidationTypes.None
			});

			placeholders.Add(new LicensePlaceholder
			{
				Length = 1,
				Token = Char.Parse("l"),
				Type = PlaceholderTypes.String,
				Value = "F",
				IsChecksum = false
			});

			//placeholders.Add(new LicensePlaceholder
			//{
			//  Length = 1,
			//  Token = Char.Parse("s"),
			//  Type = PlaceholderTypes.String,
			//  Value = "0",
			//  IsChecksum = false
			//});

			return placeholders;
		}
Ejemplo n.º 6
0
		public string GenerateLicenseKey(string rsaXmlString, LicenseBase scutexLicense, LicenseGenerationOptions generationOptions)
		{
			// Init all required variables for the process.
			Dictionary<int, LicensePlaceholder> placeholerLocations;
			List<LicensePlaceholder> licensePlaceholders = CreateLicensePlaceholders(scutexLicense, generationOptions);
			string licenseKey;
			char[] licenseKeyArray;

			// Setup the license key to work on
			licenseKey = licenseKeyTemplate.Replace("-", "");

			// Locate all the placeholder tokens in the license template
			placeholerLocations = FindAllPlaceholdersInTemplate(licenseKey, licensePlaceholders);

			// Verify that all the registered placeholders were located in the template.
			if (placeholerLocations.Count != licensePlaceholders.Count)
				throw new Exception(string.Format(Resources.ErrorMsg_PlaceholderCount,
																					licensePlaceholders.Count, placeholerLocations.Count));

			// Change all non-checksum placeholders to their actual values in the key
			foreach (var p in placeholerLocations)
			{
				if (!p.Value.IsChecksum)
				{
					string token = "";
					for (int i = 0; i < p.Value.Length; i++)
					{
						token = token + p.Value.Token;
					}

					
					licenseKey = licenseKey.Replace(token, p.Value.Value);
				}
			}

			// Compute and change the random license key placeholders
			licenseKeyArray = licenseKey.ToCharArray();
			for (int i = 0; i < licenseKeyArray.Length; i++)
			{
				if (licenseKeyArray[i] == char.Parse("x"))
				{
					licenseKeyArray[i] = GetRandomCharacter();
				}
			}
			licenseKey = new string(licenseKeyArray);

			// Obfuscate key license placeholders that are not checksums
			foreach (var p in placeholerLocations)
			{
				if (!p.Value.IsChecksum)
				{
					if (p.Value.Type == PlaceholderTypes.Number)
					{
						//Console.WriteLine(p.Value.Token);
						//Console.WriteLine("-----------------");

						licenseKeyArray = licenseKey.ToCharArray();
						
						for (int i = 0; i < p.Value.Length; i++)
						{
							char previousChar = licenseKeyArray[(p.Key) - 1];
							int data = int.Parse(licenseKeyArray[p.Key + i].ToString(), NumberStyles.HexNumber);
							char obfKey = KeyIntegerValueObfuscator(previousChar, data, p.Key + i);

							licenseKeyArray[p.Key + i] = obfKey;
						}

						licenseKey = new string(licenseKeyArray);
					}
					else if (p.Value.Type == PlaceholderTypes.String)
					{
						licenseKeyArray = licenseKey.ToCharArray();

						for (int i = 0; i < p.Value.Length; i++)
						{
							char previousChar = licenseKeyArray[(p.Key) - 1];

							int modData = CharacterMap.ReverseMap[licenseKeyArray[p.Key + i]];
							//Console.WriteLine(string.Format("Char: {0}", licenseKeyArray[p.Key + i]));
								
							char obfKey = KeyIntegerValueObfuscator(previousChar, modData, p.Key + i);

							licenseKeyArray[p.Key + i] = obfKey;
						}

						licenseKey = new string(licenseKeyArray);
					}
				}
			}

			// Now compute and change all the checksum placeholders in the key
			foreach (var p in placeholerLocations)
			{
				if (p.Value.IsChecksum)
				{
					string token = "";
					for (int i = 0; i < p.Value.Length; i++)
					{
						token = token + p.Value.Token;
					}

					string hash = hashingProvider.Checksum16(licenseKey.Substring(0, p.Key)).ToString("X");
					hash = hash.PadLeft(4, char.Parse("0"));

					licenseKey = licenseKey.Replace(token, hash);
				}
			}

			// Insert the seperators 
			List<int> seperatorLocations = FindAllSeperatorsInTemplate(licenseKeyTemplate);
			string finalKey = licenseKey;
			if (seperatorLocations.Count > 0)
			{
				int remaining = seperatorLocations.Count - 1;
				for (int i = 0; i < seperatorLocations.Count; i++)
				{
					finalKey = finalKey.Insert(seperatorLocations[i] - remaining, "-");
					remaining--;
				}
			}

			return finalKey;
		}
Ejemplo n.º 7
0
        public static void BatchSmallLicenseKeyGenrationTest()
        {
            IAsymmetricEncryptionProvider asymmetricEncryptionProvider = new AsymmetricEncryptionProvider();
            ISymmetricEncryptionProvider symmetricEncryptionProvider = new SymmetricEncryptionProvider();
            IHashingProvider hashingProvider = new HashingProvider();
            IObjectSerializationProvider objectSerializationProvider = new ObjectSerializationProvider();
            ILicenseActiviationProvider licenseActiviationProvider = new LicenseActiviationProvider(
                asymmetricEncryptionProvider, symmetricEncryptionProvider, objectSerializationProvider);
            INumberDataGeneratorProvider numberDataGeneratorProvider = new NumberDataGenerator();
            IPackingService packingService = new PackingService(numberDataGeneratorProvider);
            IHardwareFingerprintService hardwareFingerprintService = new HardwareFingerprintService(new WmiDataProvider(), hashingProvider);

            IClientLicenseRepository clientLicenseRepository = new ClientLicenseRepository(objectSerializationProvider,
                                                                                                                                                                         symmetricEncryptionProvider);
            IClientLicenseService clientLicenseService = new ClientLicenseService(clientLicenseRepository);

            ISmallKeyGenerator smallKeyGenerator = new WaveTech.Scutex.Generators.StaticKeyGeneratorSmall.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider);
            ILargeKeyGenerator staticKeyGeneratorLarge = new WaveTech.Scutex.Generators.StaticKeyGeneratorLarge.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider, hardwareFingerprintService);
            LicenseKeyService licenseKeyService = new LicenseKeyService(smallKeyGenerator, staticKeyGeneratorLarge, packingService, clientLicenseService);

            ClientLicense license = new ClientLicense();
            LicenseGenerationOptions generationOptions = new LicenseGenerationOptions();

            license.UniqueId = Guid.NewGuid();
            license.Product = new Product();
            license.Product.Name = "My Great Uber Cool Product, with new juice!";
            license.Product.ProductId = 1;
            string productHash = hashingProvider.Checksum32(license.GetLicenseProductIdentifier()).ToString("X");

            DateTime start = DateTime.Now;

            List<string> licenseKeys = licenseKeyService.GenerateLicenseKeys("TEST", license, generationOptions, 100000);
            Dictionary<string, string> doubleCheck = new Dictionary<string, string>();

            DateTime end = DateTime.Now;

            foreach (string s in licenseKeys)
            {
                doubleCheck.Add(s, "");
                Console.WriteLine(s);
            }

            Console.WriteLine();
            Console.WriteLine("=================================");

            Console.WriteLine(string.Format("Key Generation took {0}", end - start));
            Console.WriteLine(string.Format("Generated {0} unique license keys", licenseKeys.Count));

            Console.WriteLine();
            Console.WriteLine("Press enter to exit.");
            Console.ReadLine();
        }
Ejemplo n.º 8
0
        public static void SmallLicenseKeyWithLessThen15CharsTest()
        {
            IAsymmetricEncryptionProvider asymmetricEncryptionProvider;
            ISymmetricEncryptionProvider symmetricEncryptionProvider;
            IHashingProvider hashingProvider;

            WaveTech.Scutex.Generators.StaticKeyGeneratorSmall.KeyGenerator smallKeyGenerator;
            ClientLicense license;
            LicenseGenerationOptions generationOptions;

            //List<LicensePlaceholder> placeholders;
            //Dictionary<int, LicensePlaceholder> placeholdersInTemplate;

            for (int i = 0; i < 100000; i++)
            {
                asymmetricEncryptionProvider = new AsymmetricEncryptionProvider();
                symmetricEncryptionProvider = new SymmetricEncryptionProvider();
                hashingProvider = new HashingProvider();

                smallKeyGenerator = new WaveTech.Scutex.Generators.StaticKeyGeneratorSmall.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider);

                license = new ClientLicense();
                generationOptions = new LicenseGenerationOptions();

                license.UniqueId = Guid.NewGuid();
                license.Product = new Product();
                license.Product.Name = "My Great Uber Cool Product, with new juice!";
                license.Product.ProductId = 1;

                license.LicenseSets = new NotifyList<LicenseSet>();
                license.LicenseSets.Add(new LicenseSet());

                license.LicenseSets.First().SupportedLicenseTypes = LicenseKeyTypeFlag.SingleUser;
                license.LicenseSets.First().SupportedLicenseTypes |= LicenseKeyTypeFlag.Enterprise;
                license.LicenseSets.First().SupportedLicenseTypes |= LicenseKeyTypeFlag.Unlimited;

                generationOptions.LicenseKeyType = LicenseKeyTypes.Enterprise;

                string key = smallKeyGenerator.GenerateLicenseKey("TEST", license, generationOptions);

                if (key.Length < 15)
                {
                    string error = key;
                    Console.WriteLine("ERROR: " + error);
                }

                Console.WriteLine(key);
            }
        }
Ejemplo n.º 9
0
        public static void LicenseKeyGenerationTest()
        {
            IAsymmetricEncryptionProvider asymmetricEncryptionProvider = new AsymmetricEncryptionProvider();
            ISymmetricEncryptionProvider symmetricEncryptionProvider = new SymmetricEncryptionProvider();
            IHashingProvider hashingProvider = new HashingProvider();
            IObjectSerializationProvider objectSerializationProvider = new ObjectSerializationProvider();
            ILicenseActiviationProvider licenseActiviationProvider = new LicenseActiviationProvider(
                asymmetricEncryptionProvider, symmetricEncryptionProvider, objectSerializationProvider);
            INumberDataGeneratorProvider numberDataGeneratorProvider = new NumberDataGenerator();
            IPackingService packingService = new PackingService(numberDataGeneratorProvider);
            IHardwareFingerprintService hardwareFingerprintService = new HardwareFingerprintService(new WmiDataProvider(), hashingProvider);

            IClientLicenseRepository clientLicenseRepository = new ClientLicenseRepository(objectSerializationProvider,
                                                                                                                                                                         symmetricEncryptionProvider);
            IClientLicenseService clientLicenseService = new ClientLicenseService(clientLicenseRepository);

            KeyGenerator staticKeyGenerator = new KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider);
            ILargeKeyGenerator staticKeyGeneratorLarge = new WaveTech.Scutex.Generators.StaticKeyGeneratorLarge.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider, hardwareFingerprintService);
            LicenseKeyService licenseKeyService = new LicenseKeyService(staticKeyGenerator, staticKeyGeneratorLarge, packingService, clientLicenseService);

            ClientLicense license = new ClientLicense();
            LicenseGenerationOptions generationOptions = new LicenseGenerationOptions();

            license.UniqueId = Guid.NewGuid();

            license.Product = new Product();
            license.Product.Name = "My Great Uber Cool Product, with new juice!";
            license.Product.ProductId = 1;

            string productHash = hashingProvider.Checksum32(license.GetLicenseProductIdentifier()).ToString("X");

            Dictionary<string, string> licenseKeys = new Dictionary<string, string>();

            DateTime start = DateTime.Now;
            for (int i = 0; i < 100000; i++)
            {
                string key = licenseKeyService.GenerateLicenseKey("TEST", license, generationOptions);
                licenseKeys.Add(key, key.GetHashCode().ToString());
                Console.WriteLine(key);
            }
            DateTime end = DateTime.Now;

            Console.WriteLine(start - end);
        }
Ejemplo n.º 10
0
        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);
            licenseKeyService = new LicenseKeyService(staticKeyGenerator, packingService, clientLicenseService);
        }
Ejemplo n.º 11
0
        public void TestLicenseKeyHashing()
        {
            IAsymmetricEncryptionProvider asymmetricEncryptionProvider = new AsymmetricEncryptionProvider();
            ISymmetricEncryptionProvider symmetricEncryptionProvider = new SymmetricEncryptionProvider();
            IHashingProvider hashingProvider = new HashingProvider();
            IObjectSerializationProvider objectSerializationProvider = new ObjectSerializationProvider();
            ILicenseActiviationProvider licenseActiviationProvider = new LicenseActiviationProvider(
                asymmetricEncryptionProvider, symmetricEncryptionProvider, objectSerializationProvider);
            INumberDataGeneratorProvider numberDataGeneratorProvider = new NumberDataGenerator();
            IPackingService packingService = new PackingService(numberDataGeneratorProvider);
            IClientLicenseRepository clientLicenseRepository = new ClientLicenseRepository(objectSerializationProvider,
                                                                                                                                                                         symmetricEncryptionProvider);
            IClientLicenseService clientLicenseService = new ClientLicenseService(clientLicenseRepository);

            IKeyGenerator smallKeyGenerator = new WaveTech.Scutex.Generators.StaticKeyGeneratorSmall.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider);
            LicenseKeyService licenseKeyService = new LicenseKeyService(smallKeyGenerator, packingService, clientLicenseService);

            ClientLicense license = new ClientLicense();
            LicenseGenerationOptions generationOptions = new LicenseGenerationOptions();

            license.UniqueId = Guid.NewGuid();
            license.Product = new Product();
            license.Product.Name = "My Great Uber Cool Product, with new juice!";
            license.Product.ProductId = 1;
            string productHash = hashingProvider.Checksum32(license.GetLicenseProductIdentifier()).ToString("X");

            Dictionary<string, string> licenseKeys = new Dictionary<string, string>();
            List<string> keys = licenseKeyService.GenerateLicenseKeys("TEST", license, generationOptions, 100000);

            foreach (string key in keys)
            {
                string hash = hashingProvider.ComputeHash(key, "SHA256");
                licenseKeys.Add(hash, key);
                Console.WriteLine(key + "\t" + hash);

                Assert.IsTrue(hash.Equals(hashingProvider.ComputeHash(key, "SHA256")));
                Assert.IsFalse(hash.Contains("'"));
            }
        }
Ejemplo n.º 12
0
        public static void SmallLicenseKeyGenrationTest()
        {
            IAsymmetricEncryptionProvider asymmetricEncryptionProvider = new AsymmetricEncryptionProvider();
            ISymmetricEncryptionProvider symmetricEncryptionProvider = new SymmetricEncryptionProvider();
            IHashingProvider hashingProvider = new HashingProvider();
            IObjectSerializationProvider objectSerializationProvider = new ObjectSerializationProvider();
            ILicenseActiviationProvider licenseActiviationProvider = new LicenseActiviationProvider(
                asymmetricEncryptionProvider, symmetricEncryptionProvider, objectSerializationProvider);
            INumberDataGeneratorProvider numberDataGeneratorProvider = new NumberDataGenerator();
            IPackingService packingService = new PackingService(numberDataGeneratorProvider);

            IClientLicenseRepository clientLicenseRepository = new ClientLicenseRepository(objectSerializationProvider,
                                                                                                                                                                         symmetricEncryptionProvider);
            IClientLicenseService clientLicenseService = new ClientLicenseService(clientLicenseRepository);

            IKeyGenerator smallKeyGenerator = new WaveTech.Scutex.Generators.StaticKeyGeneratorSmall.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider);
            LicenseKeyService licenseKeyService = new LicenseKeyService(smallKeyGenerator, packingService, clientLicenseService);

            ClientLicense license = new ClientLicense();
            LicenseGenerationOptions generationOptions = new LicenseGenerationOptions();

            license.UniqueId = Guid.NewGuid();
            license.Product = new Product();
            license.Product.Name = "My Great Uber Cool Product, with new juice!";
            license.Product.ProductId = 1;
            string productHash = hashingProvider.Checksum32(license.GetLicenseProductIdentifier()).ToString("X");

            Dictionary<string, string> licenseKeys = new Dictionary<string, string>();

            DateTime start = DateTime.Now;
            try
            {
                List<string> keys = licenseKeyService.GenerateLicenseKeys("TEST", license, generationOptions, 100000);

                foreach (string key in keys)
                {
                    string hash = hashingProvider.ComputeHash(key, "SHA256");
                    licenseKeys.Add(hash, key);
                    Console.WriteLine(key);

                    Console.WriteLine(hash + " " + hash.Equals(hashingProvider.ComputeHash(key, "SHA256")));
                }
            }
            catch (Exception ex)
            { Console.WriteLine(ex.Message); }
            finally
            {

                Console.WriteLine();
                Console.WriteLine("=================================");

                DateTime end = DateTime.Now;
                Console.WriteLine(string.Format("Key Generation took {0}", end - start));

                Console.WriteLine(string.Format("Generated {0} unique license keys", licenseKeys.Count));

                Console.WriteLine();
                Console.WriteLine("Press enter to exit.");
                Console.ReadLine();
            }
        }
Ejemplo n.º 13
0
        public string GenerateLicenseKey(LicenseKeyTypes keyTypes)
        {
            LicenseGenerationOptions options = new LicenseGenerationOptions();
            options.LicenseKeyType = keyTypes;

            List<string> keys = service.GenerateLicenseKeys(License.KeyPair.PrivateKey,
                                                                                                            License,
                                                                                                            options,
                                                                                                            1);

            return keys.First();
        }
Ejemplo n.º 14
0
		internal List<LicensePlaceholder> CreateLicensePlaceholders(LicenseBase scutexLicense, LicenseGenerationOptions generationOptions)
		{
			List<LicensePlaceholder> Placeholders = new List<LicensePlaceholder>();

			if (generationOptions != null)
			{
				Placeholders.Add(new LicensePlaceholder
													{
														Length = 1,
														Token = Char.Parse("k"),
														Type = PlaceholderTypes.Number,
														Value = ((int)generationOptions.LicenseKeyType).ToString(),
														IsChecksum = false,
														ValidationType = ValidationTypes.LicenseKeyType
													});
			}
			else
			{
				Placeholders.Add(new LicensePlaceholder
													{
														Length = 1,
														Token = Char.Parse("k"),
														Type = PlaceholderTypes.Number,
														Value = "0",
														IsChecksum = false,
														ValidationType = ValidationTypes.LicenseKeyType
													});
			}

			Placeholders.Add(new LicensePlaceholder
			{
				Length = 2,
				Token = Char.Parse("a"),
				Type = PlaceholderTypes.Number,
				Value = scutexLicense.Product.GetFormattedProductId(2),
				IsChecksum = false,
				ValidationType = ValidationTypes.None
			});

			Placeholders.Add(new LicensePlaceholder
			{
				Length = 1,
				Token = Char.Parse("c"),
				Type = PlaceholderTypes.Number,
				Value = "",
				IsChecksum = true,
				ValidationType = ValidationTypes.None
			});

			string licProdChecksum = hashingProvider.Checksum16(scutexLicense.GetLicenseProductIdentifier()).ToString("X");

			if (licProdChecksum.Length < 4)
				licProdChecksum = licProdChecksum.PadLeft(4, char.Parse("0"));

			Placeholders.Add(new LicensePlaceholder
			{
				Length = 4,
				Token = Char.Parse("p"),
				Type = PlaceholderTypes.Number,
				Value = licProdChecksum,
				IsChecksum = false,
				ValidationType = ValidationTypes.None
			});

			return Placeholders;
		}
Ejemplo n.º 15
0
        public bool TestService(Service service)
        {
            string clientToken = _packingService.PackToken(service.GetClientToken());
            string mgmtToken = _packingService.PackToken(service.GetManagementToken());

            LicenseActivationPayload payload = new LicenseActivationPayload();
            payload.ServiceLicense = new ServiceLicense(CreateTestClientLicense(service));

            LicenseGenerationOptions options = new LicenseGenerationOptions();
            options.LicenseKeyType = LicenseKeyTypes.MultiUser;

            payload.LicenseKey = _licenseKeyService.GenerateLicenseKey(null, payload.ServiceLicense, options);

            SetupTestProductResult result = _serviceStatusProvider.SetupTestProduct(service.ManagementUrl, mgmtToken, payload.LicenseKey, GetManagementStandardEncryptionInfo(service));

            if (result.WasRequestValid == false)
                return false;

            if (result.WasOperationSuccessful == false)
                return false;

            ActivationResult activationResult1 = _licenseActiviationProvider.ActivateLicense(service.ClientUrl, clientToken, GetClientStandardEncryptionInfo(service),
                payload, CreateTestClientLicense(service));

            ActivationResult activationResult2 = _licenseActiviationProvider.ActivateLicense(service.ClientUrl, clientToken, GetClientStandardEncryptionInfo(service),
                payload, CreateTestClientLicense(service));

            ActivationResult activationResult3 = _licenseActiviationProvider.ActivateLicense(service.ClientUrl, clientToken, GetClientStandardEncryptionInfo(service),
                payload, CreateTestClientLicense(service));

            if (activationResult1.WasRequestValid == false || activationResult1.ActivationSuccessful == false)
                return false;

            if (activationResult2.WasRequestValid == false || activationResult2.ActivationSuccessful == false)
                return false;

            if (activationResult3.WasRequestValid == false || activationResult3.ActivationSuccessful == true)
                return false;

            SetupTestProductResult cleanUpResult = _serviceStatusProvider.CleanUpTestProductData(service.ManagementUrl, mgmtToken,
                                                                                                                                                                                     GetManagementStandardEncryptionInfo
                                                                                                                                                                                        (service));

            if (cleanUpResult.WasOperationSuccessful == false)
                return false;

            return true;
        }
Ejemplo n.º 16
0
 public string GenerateLicenseKey(string rsaXmlString, LicenseBase scutexLicense, LicenseGenerationOptions generationOptions)
 {
     return keyGenerator.GenerateLicenseKey(rsaXmlString, scutexLicense, generationOptions);
 }