Пример #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);
        }
Пример #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();
        }
Пример #3
0
 public static void WriteLicensingDllHash()
 {
     IHashingProvider hashingProvider = new HashingProvider();
     Console.WriteLine(hashingProvider.HashFile(Directory.GetCurrentDirectory() + "\\WaveTech.Scutex.Licensing.dll"));
 }
Пример #4
0
        public static void WriteEncodedLicensingDllHash()
        {
            IHashingProvider hashingProvider = new HashingProvider();
            IEncodingService encodingService = new EncodingService();

            string hash = hashingProvider.HashFile(Directory.GetCurrentDirectory() + "\\WaveTech.Scutex.Licensing.dll");
            Console.WriteLine(encodingService.Encode(hash));
        }
Пример #5
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);
            }
        }
Пример #6
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);
        }
Пример #7
0
        public static void HashTokenWithSalt()
        {
            HashingProvider provider = new HashingProvider();
            Console.WriteLine(provider.ComputeHashWithSalt("b$7SDt%43J*a!9", "SHA256", null));

            PackingService service = new PackingService(new NumberDataGenerator());
            Token t = new Token();
            t.Data = "MXLBEcLe6/i1CjdyomC7T0vTlACTXpdRmnxcDXDE8yDuCal0xA==";
            t.Timestamp = DateTime.Now;

            Console.WriteLine(service.PackToken(t));

            SymmetricEncryptionProvider encryption = new SymmetricEncryptionProvider();
            EncryptionInfo ei = new EncryptionInfo();
            ei.HashAlgorithm = "SHA1";
            ei.InitVector = "a01JQ3481Ahnqwe9";
            ei.Iterations = 2;
            ei.KeySize = 256;
            ei.PassPhrase = "Da*eW6_EzU4_swuk8*hU";
            ei.SaltValue = "VuW9uDrE";

            Console.WriteLine(encryption.Encrypt("861641072009MXLBEcLe6/i1CjdyomC7T0vTlACTXpdRmnxcDXDE8yDuCal0xA==41410860", ei));

            Console.WriteLine();
            Console.WriteLine("Press enter to exit.");
            Console.ReadLine();
        }
Пример #8
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("'"));
            }
        }
Пример #9
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();
            }
        }