Exemple #1
0
        public LicenseHelper()
        {
            asymmetricEncryptionProvider = new AsymmetricEncryptionProvider();
            hashingProvider = new HashingProvider();
            encodingService = new EncodingService();
            objectSerializationProvider = new ObjectSerializationProvider();
            symmetricEncryptionProvider = new SymmetricEncryptionProvider();
            clientLicenseRepository = new ClientLicenseRepository(objectSerializationProvider, symmetricEncryptionProvider);
            clientLicenseService = new ClientLicenseService(clientLicenseRepository);
            serviceStatusProvider = new ServiceStatusProvider(symmetricEncryptionProvider, objectSerializationProvider, asymmetricEncryptionProvider);
            numberDataGenerator = new NumberDataGenerator();
            packingService = new PackingService(numberDataGenerator);
            keygen = new KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider);
            licenseActiviationProvider = new LicenseActiviationProvider(asymmetricEncryptionProvider, symmetricEncryptionProvider, objectSerializationProvider);
            service = new LicenseKeyService(keygen, packingService, clientLicenseService);
            productsProvider = new ProductsProvider(symmetricEncryptionProvider, objectSerializationProvider, asymmetricEncryptionProvider);
            zipCompressionProvider = new ZipCompressionProvider();
            wcfPackagingService = new WcfPackagingService(zipCompressionProvider);

            //licenseSetsRepository = new LicenseSetsRepository();

            //licenseSetService = new LicenseSetService();
            //licenseService = new LicenseService();

            License = new License();
            License.Name = "UnitTest License";
            License.UniqueId = Guid.NewGuid();
            License.KeyPair = asymmetricEncryptionProvider.GenerateKeyPair(BitStrengths.High);

            //string path = System.Reflection.Assembly.GetAssembly(typeof(LicenseHelper)).Location;
            string path = Helper.AssemblyDirectory;

            DllHash = encodingService.Encode(hashingProvider.HashFile(path + "\\WaveTech.Scutex.Licensing.dll"));
            PublicKey = encodingService.Encode(License.KeyPair.PublicKey);
        }
Exemple #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();
        }
		public void SplitDataSouldEqualOriginal()
		{
			AsymmetricEncryptionProvider provider = new AsymmetricEncryptionProvider();
			KeyPair kp = provider.GenerateKeyPair(BitStrengths.High);

			string inKey1 = kp.PublicKey.Substring(0, (kp.PublicKey.Length/2));
			string inKey2 = kp.PublicKey.Substring(inKey1.Length, (kp.PublicKey.Length - inKey1.Length));

			string outKey1 = kp.PrivateKey.Substring(0, (kp.PrivateKey.Length / 2));
			string outKey2 = kp.PrivateKey.Substring(inKey1.Length, (kp.PrivateKey.Length - outKey1.Length));

			Assert.AreEqual(kp.PublicKey.Length, inKey1.Length + inKey2.Length);
			Assert.AreEqual(kp.PrivateKey.Length, outKey1.Length + outKey2.Length);
		}
Exemple #4
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);
            }
        }
Exemple #5
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 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("'"));
            }
        }
Exemple #7
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();
            }
        }
Exemple #8
0
        public void BrokenTrialSetup()
        {
            License.Name = "UnitTest License";

            Product p = new Product();
            p.Name = "UnitTest Product";
            p.Description = "Just a product for unit testing";

            License.LicenseId = 1;
            License.Product = p;
            License.KeyGeneratorType = KeyGeneratorTypes.StaticSmall;

            LicenseTrialSettings ts = new LicenseTrialSettings();
            ts.ExpirationOptions = TrialExpirationOptions.Days;
            ts.ExpirationData = "30";

            License.TrialSettings = ts;

            LicenseSet ls = new LicenseSet();
            ls.LicenseId = 1;
            ls.LicenseSetId = 1;
            ls.Name = "Unit Test License Set";
            ls.MaxUsers = 5;
            ls.SupportedLicenseTypes = LicenseKeyTypeFlag.Enterprise;

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

            License lic = License;
            AsymmetricEncryptionProvider asymmetricEncryptionProvider = new AsymmetricEncryptionProvider();
            lic.KeyPair = asymmetricEncryptionProvider.GenerateKeyPair(BitStrengths.High);

            ClientLicense lic2 = new ClientLicense(License);
            lic2.RunCount = 10;
            lic2.LastRun = DateTime.Now.AddMonths(-12);
            lic2.FirstRun = DateTime.Now.AddMonths(-24);

            CreateFile(lic2);
        }