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);
			}
Esempio n. 2
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();
        }
Esempio n. 3
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);
        }
        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);
        }
Esempio n. 5
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("'"));
            }
        }
Esempio n. 6
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();
            }
        }
			public void Before_each_test()
			{
				asymmetricEncryptionProvider = new AsymmetricEncryptionProvider();
				symmetricEncryptionProvider = new SymmetricEncryptionProvider();
				hashingProvider = new HashingProvider();

				var mock = new Mock<IHardwareFingerprintService>();
				mock.Setup(foo => foo.GetHardwareFingerprint(FingerprintTypes.Default)).Returns("JustATestFingerprint1050");

				_hardwareFingerprintService = new HardwareFingerprintService(new WmiDataProvider(), hashingProvider);

				largeKeyGenerator = new KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider, mock.Object);

				license = new ClientLicense();
				generationOptions = new List<LicenseGenerationOptions>();
				generationOptions.Add(new LicenseGenerationOptions());
				generationOptions.Add(new LicenseGenerationOptions());
				generationOptions.Add(new LicenseGenerationOptions());
				generationOptions.Add(new LicenseGenerationOptions());
				generationOptions.Add(new LicenseGenerationOptions());
				generationOptions.Add(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.Add(new LicenseSet());
				license.LicenseSets.Add(new LicenseSet());
				license.LicenseSets.Add(new LicenseSet());
				license.LicenseSets.Add(new LicenseSet());

				license.LicenseSets[0].LicenseSetId = 1;
				license.LicenseSets[0].Name = "Standard Edition";
				license.LicenseSets[0].MaxUsers = 5;
				license.LicenseSets[0].SupportedLicenseTypes = LicenseKeyTypeFlag.SingleUser;
				license.LicenseSets[0].SupportedLicenseTypes |= LicenseKeyTypeFlag.MultiUser;
				license.LicenseSets[0].SupportedLicenseTypes |= LicenseKeyTypeFlag.Unlimited;

				license.LicenseSets[1].LicenseSetId = 2;
				license.LicenseSets[1].Name = "Professional Edition";
				license.LicenseSets[1].MaxUsers = 5;
				license.LicenseSets[1].SupportedLicenseTypes = LicenseKeyTypeFlag.SingleUser;
				license.LicenseSets[1].SupportedLicenseTypes |= LicenseKeyTypeFlag.MultiUser;
				license.LicenseSets[1].SupportedLicenseTypes |= LicenseKeyTypeFlag.Unlimited;

				license.LicenseSets[2].LicenseSetId = 3;
				license.LicenseSets[2].Name = "Enterprise Edition";
				license.LicenseSets[2].MaxUsers = 5;
				license.LicenseSets[2].SupportedLicenseTypes = LicenseKeyTypeFlag.SingleUser;
				license.LicenseSets[2].SupportedLicenseTypes |= LicenseKeyTypeFlag.MultiUser;
				license.LicenseSets[2].SupportedLicenseTypes |= LicenseKeyTypeFlag.Unlimited;
				license.LicenseSets[2].SupportedLicenseTypes |= LicenseKeyTypeFlag.Enterprise;

				license.LicenseSets[3].LicenseSetId = 4;
				license.LicenseSets[3].Name = "Upgrade Edition";
				license.LicenseSets[3].MaxUsers = 0;
				license.LicenseSets[3].IsUpgradeOnly = true;
				license.LicenseSets[3].SupportedLicenseTypes = LicenseKeyTypeFlag.SingleUser;

				license.LicenseSets[4].LicenseSetId = 5;
				license.LicenseSets[4].Name = "Hardware Edition";
				license.LicenseSets[4].MaxUsers = 0;
				license.LicenseSets[4].IsUpgradeOnly = false;
				license.LicenseSets[4].SupportedLicenseTypes = LicenseKeyTypeFlag.HardwareLock;

				generationOptions[0].LicenseKeyType = LicenseKeyTypes.SingleUser;
				generationOptions[0].LicenseSetId = 1;

				generationOptions[1].LicenseKeyType = LicenseKeyTypes.Enterprise;
				generationOptions[1].LicenseSetId = 2;

				generationOptions[2].LicenseKeyType = LicenseKeyTypes.Enterprise;
				generationOptions[2].LicenseSetId = 3;

				generationOptions[3].LicenseKeyType = LicenseKeyTypes.Enterprise;
				generationOptions[3].LicenseSetId = 4;

				generationOptions[4].LicenseKeyType = LicenseKeyTypes.HardwareLock;
				generationOptions[4].HardwareFingerprint = "JustATestFingerprint1050";
				generationOptions[4].LicenseSetId = 5;

				generationOptions[5].LicenseKeyType = LicenseKeyTypes.HardwareLockLocal;
				generationOptions[5].HardwareFingerprint = "JustATestFingerprint1050";
				generationOptions[5].LicenseSetId = 5;

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

				placeholders = largeKeyGenerator.CreateLicensePlaceholders(license, generationOptions[0]);
				placeholdersInTemplate = KeyGenerator.FindAllPlaceholdersInTemplate(KeyGenerator.licenseKeyTemplate, placeholders);

				key = largeKeyGenerator.GenerateLicenseKey("TEST", license, generationOptions[0]);
			}