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);
            }
        static void Main(string[] args)
        {
            //-----------
            const string DemoLicenseKey = "D2287CCA-2A3A-48C2-BCCB-BF12B3E481B0";
            var server = new LicenseServer();

            var rawLicense = server.IssueLicense(DateTime.Now.AddDays(10),
                                                  DemoLicenseKey);
            var license = new ClientLicense(rawLicense);
            Console.WriteLine("License is valid? - {0}", license.Verify());
            Console.WriteLine("Message - {0}", license.Message);
            Console.WriteLine();

            Console.ReadKey();

            //-----------Expires
            rawLicense = server.IssueLicense(DateTime.Now.AddDays(10),
                                  DemoLicenseKey);
            var tamper = new XmlDocument();
            tamper.LoadXml(rawLicense);
            tamper.SelectSingleNode("//Expires").InnerText =
                DateTime.Now.AddYears(5).ToString("dd/MM/yyyy HH:mm:ss");

            var tamperedXml = new StringBuilder();
            using (var swOut = new StringWriter(tamperedXml))
            {
                tamper.Save(swOut);
            }
            license = new ClientLicense(tamperedXml.ToString());

            Console.WriteLine("License is valid? - {0}", license.Verify());
            Console.WriteLine("Message - {0}", license.Message);
            Console.WriteLine();

            Console.ReadKey();


            //-----------
            rawLicense = server.IssueLicense(DateTime.Now.AddDays(-10),
                                  DemoLicenseKey);
            license = new ClientLicense(rawLicense);
            Console.WriteLine("License is valid? - {0}", license.Verify());
            Console.WriteLine("Message - {0}", license.Message);


            Console.ReadKey();


        }
示例#3
0
        private static void GetKey(string licensePath, string elementKey = null)
        {
            var clientLicense = ClientLicense.Create(File.ReadAllText(licensePath));

            var mylcP           = new LicenseCriteriaParser();
            var licenseCriteria = mylcP.Parse(clientLicense, elementKey);

            if (licenseCriteria.MetaData.ContainsKey("LicensedCores"))
            {
                Console.WriteLine(licenseCriteria.MetaData["LicensedCores"]);
            }
            else
            {
                Console.WriteLine("no key found");
            }
        }
        public ActivationResult ActivateLicense(string url, string token, EncryptionInfo encryptionInfo,
                                                LicenseActivationPayload payload, ClientLicense clientLicense)
        {
            ActivationServiceClient client = ActivationServiceClientCreator(url);

            string encryptedToken    = _symmetricEncryptionProvider.Encrypt(token, encryptionInfo);
            string serializedPayload = _objectSerializationProvider.Serialize(payload);
            string encryptedData     = _asymmetricEncryptionProvider.EncryptPrivate(serializedPayload, clientLicense.ServicesKeys);


            string serviceResult = client.ActivateLicense(encryptedToken, encryptedData);
            string result        = _asymmetricEncryptionProvider.DecryptPublic(serviceResult, clientLicense.ServicesKeys);

            ActivationResult activationResult = _objectSerializationProvider.Deserialize <ActivationResult>(result);

            return(activationResult);
        }
示例#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);
        }
示例#6
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);
        }
示例#7
0
        public ActionResult <License> Post([FromBody] ClientLicense license)
        {
            _logger.LogInformation("POST {guid}, url: {url}, revision: {rev}", license.Guid.ToString(), license.Url, license.Revision);

            switch (license.Url.ToUpper())
            {
            case "BAD-WAREHOUSE":
                //throw LicenseException.BadLicense(new Exception("Unknown error from warehouse"));
                return(NotFound("Unknown warehouse"));

            default:
                License l = InstallAndGetClientLicenseDetail(license);
                if (license == null)
                {
                    return(NotFound());
                }
                return(l);
            }
        }
示例#8
0
        public RegisterContent(ClientLicense clientLicense, ScutexLicense scutexLicense)
            : this()
        {
            _clientLicense = clientLicense;
            _scutexLicense = scutexLicense;

            if (_clientLicense != null)
            {
                switch (_clientLicense.KeyGeneratorType)
                {
                case KeyGeneratorTypes.StaticSmall:
                    txtLicenseKey.InputMask = @"www-wwwwww-wwww";
                    break;

                case KeyGeneratorTypes.StaticLarge:
                    txtLicenseKey.InputMask = @"WWWWW-WWWWW-WWWWW-WWWWW-WWWWW";
                    break;
                }
            }
        }
示例#9
0
 private License InstallAndGetClientLicenseDetail(ClientLicense license)
 {
     if (license.Guid.Equals(new Guid("{666140C4-DFC8-435E-9243-E8A54042F918}")))
     {
         return(new License {
             Guid = new Guid("{666140C4-DFC8-435E-9243-E8A54042F918}"),
             Company = "MeadCo",
             CompanyHomePage = new Uri("http://www.meadroid.com"),
             From = DateTime.Today,
             To = DateTime.Today.AddMonths(3),
             Options = new LicenseOptions
             {
                 BasicHtmlPrinting = true,
                 AdvancedPrinting = true
             },
             Domains = new string[] { "meadroid.com", "meadco.com" }
         });
     }
     return(null);
 }
示例#10
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();
            IHardwareFingerprintService  hardwareFingerprintService  = new HardwareFingerprintService(new WmiDataProvider(), new HashingProvider());
            IPackingService          packingService          = new PackingService(numberDataGeneratorProvider);
            IClientLicenseRepository clientLicenseRepository = new ClientLicenseRepository(objectSerializationProvider,
                                                                                           symmetricEncryptionProvider);
            IClientLicenseService clientLicenseService = new ClientLicenseService(clientLicenseRepository);

            ILargeKeyGenerator largeKeyGenerator = new KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider, hardwareFingerprintService);
            ISmallKeyGenerator smallKeyGenerator = new WaveTech.Scutex.Generators.StaticKeyGeneratorSmall.KeyGenerator(symmetricEncryptionProvider, asymmetricEncryptionProvider, hashingProvider);
            LicenseKeyService  licenseKeyService = new LicenseKeyService(smallKeyGenerator, largeKeyGenerator, 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("'"));
            }
        }
示例#11
0
        internal ClientLicense CreateTestClientLicense(Service service)
        {
            ClientLicense cl = new ClientLicense();

            cl.ServicesKeys = service.GetClientServiceKeyPair();
            cl.Product      = new Product();
            cl.Product.Name = "Test Product";

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

            ls.LicenseId             = int.MaxValue;
            ls.LicenseSetId          = int.MaxValue;
            ls.Name                  = "Test Product License Set";
            ls.MaxUsers              = 2;
            ls.SupportedLicenseTypes = LicenseKeyTypeFlag.MultiUser;

            cl.LicenseSets.Add(ls);

            return(cl);
        }
        public ClientLicense SaveClientLicense(ClientLicense clientLicense, string filePath)
        {
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            string plainTextObjectData;

            plainTextObjectData = objectSerializationProvider.Serialize(clientLicense);

            string encryptedObjectData;

            encryptedObjectData = encryptionProvider.Encrypt(plainTextObjectData, encryptionInfo);

            using (StreamWriter writer = new StreamWriter(filePath))
            {
                writer.Write(encryptedObjectData);
            }

            return(GetClientLicense(filePath));
        }
        public ClientLicense GetClientLicense(string filePath)
        {
            if (File.Exists(filePath) == false)
            {
                return(null);
            }

            string rawFileData;

            using (StreamReader reader = new StreamReader(filePath))
            {
                rawFileData = reader.ReadToEnd();
            }

            string plainTextObjectData;

            plainTextObjectData = encryptionProvider.Decrypt(rawFileData, encryptionInfo);

            ClientLicense sl = objectSerializationProvider.Deserialize <ClientLicense>(plainTextObjectData);

            return(sl);
        }
示例#14
0
        internal EncryptionInfo GetClientStandardEncryptionInfo(ClientLicense clientLicense)
        {
            EncryptionInfo ei = new EncryptionInfo();

            ei.HashAlgorithm = "SHA1";
            ei.InitVector    = Resources.ServicesIV;
            ei.Iterations    = 2;
            ei.KeySize       = 192;

            // Outbound Key
            string outKey1 = clientLicense.ServicesKeys.PrivateKey.Substring(0, (clientLicense.ServicesKeys.PrivateKey.Length / 2));
            string outKey2 = clientLicense.ServicesKeys.PrivateKey.Substring(outKey1.Length, (clientLicense.ServicesKeys.PrivateKey.Length - outKey1.Length));

            // Inbound Key
            string inKey1 = clientLicense.ServicesKeys.PublicKey.Substring(0, (clientLicense.ServicesKeys.PublicKey.Length / 2));
            string inKey2 = clientLicense.ServicesKeys.PublicKey.Substring(inKey1.Length, (clientLicense.ServicesKeys.PublicKey.Length - inKey1.Length));

            ei.PassPhrase = outKey2;
            ei.SaltValue  = inKey2;

            return(ei);
        }
示例#15
0
        private static void Demo(object sender, ExecutedRoutedEventArgs e)
        {
            if (UIContext.License != null)
            {
                DemoHostHelper helper = new DemoHostHelper();
                helper.CleanPreviousHost();

                string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
                path = path.Replace("file:\\", "");

                ClientLicense cl = new ClientLicense(UIContext.License);

                IClientLicenseService clientLicenseService = ObjectLocator.GetInstance <IClientLicenseService>();
                clientLicenseService.SaveClientLicense(cl, path + @"\sxu.dll");

                IHashingProvider hashingProvider = ObjectLocator.GetInstance <IHashingProvider>();
                IEncodingService encodingService = ObjectLocator.GetInstance <IEncodingService>();

                string dllCheckHash = encodingService.Encode(hashingProvider.HashFile(Directory.GetCurrentDirectory() + "\\lib\\WaveTech.Scutex.Licensing.dll"));
                string publicKey    = encodingService.Encode(UIContext.License.KeyPair.PublicKey);

                try
                {
                    File.Copy(Directory.GetCurrentDirectory() + "\\lib\\WaveTech.Scutex.Licensing.dll", Directory.GetCurrentDirectory() + "\\WaveTech.Scutex.Licensing.dll");
                }
                catch { }

                helper.CreateAssembly(publicKey, dllCheckHash);

                helper.ExecuteAssembly();
                helper = null;
            }
            else
            {
                MessageBox.Show("You must have an open licensing project to view the demo trial form.");
            }
        }
示例#16
0
        public ScutexLicense GetScutexLicense(ClientLicense clientLicense)
        {
            ScutexLicense scutexLicense = new ScutexLicense();

            scutexLicense.TrialFaultReason          = TrialFaultReasons.None;
            scutexLicense.IsTrialValid              = true;
            scutexLicense.LastRun                   = clientLicense.LastRun;
            scutexLicense.TrialSettings             = clientLicense.TrialSettings;
            scutexLicense.TrailNotificationSettings = clientLicense.TrailNotificationSettings;
            scutexLicense.IsCommunityEdition        = ApplicationConstants.IsCommunityEdition;

            if (!clientLicense.FirstRun.HasValue)
            {
                Logging.LogDebug(string.Format("Is First Run!"));
                clientLicense.FirstRun         = _networkTimeProvider.GetNetworkTime();
                scutexLicense.WasTrialFristRun = true;

                Logging.LogDebug(string.Format("FirstRun SetTo: {0}", clientLicense.FirstRun.Value));
            }
            else
            {
                Logging.LogDebug(string.Format("Is Existing Run!"));
                Logging.LogDebug(string.Format("FirstRun Date: {0}", clientLicense.FirstRun.Value));
                Logging.LogDebug(string.Format("NetTime Date: {0}", _networkTimeProvider.GetNetworkTime()));
            }

            if (clientLicense.LastRun.HasValue && _networkTimeProvider.GetNetworkTime() < clientLicense.LastRun)
            {
                Logging.LogDebug(string.Format("TIME FAULT"));
                Logging.LogDebug(string.Format("LastRun Date: {0}", clientLicense.LastRun.Value));
                Logging.LogDebug(string.Format("NetRun Date: {0}", _networkTimeProvider.GetNetworkTime()));
                Logging.LogDebug(string.Format("Delta: {0}", (_networkTimeProvider.GetNetworkTime() - clientLicense.LastRun.Value)));

                scutexLicense.IsTrialValid     = false;
                scutexLicense.TrialFaultReason = TrialFaultReasons.TimeFault;
            }

            clientLicense.LastRun = _networkTimeProvider.GetNetworkTime();

            Logging.LogDebug(string.Format("Old Run Count: {0}", clientLicense.RunCount));
            clientLicense.RunCount++;
            Logging.LogDebug(string.Format("New Run Count: {0}", clientLicense.RunCount));

            scutexLicense.FirstRun = clientLicense.FirstRun;

            switch (clientLicense.TrialSettings.ExpirationOptions)
            {
            case TrialExpirationOptions.Days:
                TimeSpan ts = clientLicense.FirstRun.Value -
                              _networkTimeProvider.GetNetworkTime().AddDays(-int.Parse(clientLicense.TrialSettings.ExpirationData));

                scutexLicense.TrialRemaining = ts.Days;

                if (ts.Days <= 0)
                {
                    scutexLicense.IsTrialExpired = true;
                    Logging.LogDebug(string.Format("Trial Expired"));
                }
                else
                {
                    scutexLicense.IsTrialExpired = false;
                    Logging.LogDebug(string.Format("Trial Not Expired"));
                }

                break;
            }

            // TODO: Need to set a fair amount of data here, like licensed edition, level, etc
            if (clientLicense.IsLicensed)
            {
                scutexLicense.IsLicensed = clientLicense.IsLicensed;
                Logging.LogDebug(string.Format("Product is licensed"));
            }
            else
            {
                Logging.LogDebug(string.Format("Product is not licensed"));
            }

            Logging.LogDebug(string.Format("Saving client license"));
            _clientLicenseService.SaveClientLicense(clientLicense);

            return(scutexLicense);
        }
示例#17
0
 public ScutexLicense Validate(string licenseKey, ScutexLicense scutexLicense, ClientLicense clientLicense)
 {
     return(scutexLicense);
 }
示例#18
0
        public RegisterResult Register(string licenseKey, LicenseBase scutexLicense, ScutexLicense license)
        {
            RegisterResult registerResult = new RegisterResult();

            registerResult.ScutexLicense = license;

            bool          result = _licenseKeyService.ValidateLicenseKey(licenseKey, scutexLicense, true);
            ClientLicense cl     = null;

            if (result)
            {
                KeyData keyData = _licenseKeyService.GetLicenseKeyData(licenseKey, scutexLicense, false);

                if (keyData.LicenseKeyType != LicenseKeyTypes.Enterprise && keyData.LicenseKeyType != LicenseKeyTypes.HardwareLockLocal)
                {
                    try
                    {
                        if (keyData.LicenseKeyType == LicenseKeyTypes.HardwareLock)
                        {
                            cl = _licenseActivationService.ActivateLicenseKey(licenseKey, null, false, (ClientLicense)scutexLicense, _hardwareFingerprintService.GetHardwareFingerprint(FingerprintTypes.Default));
                        }
                        else
                        {
                            cl = _licenseActivationService.ActivateLicenseKey(licenseKey, null, false, (ClientLicense)scutexLicense, null);
                        }

                        if (cl.IsLicensed && cl.IsActivated)
                        {
                            registerResult.Result        = ProcessCodes.ActivationSuccess;
                            registerResult.ClientLicense = cl;
                        }
                        else
                        {
                            registerResult.Result = ProcessCodes.ActivationFailed;
                        }
                    }
                    catch
                    {
                        registerResult.Result = ProcessCodes.ActivationFailed;
                    }
                }
                else
                {
                    cl = _licenseActivationService.ActivateLicenseKey(licenseKey, null, true, (ClientLicense)scutexLicense, null);
                    registerResult.Result = ProcessCodes.LicenseKeyNotActivated;
                }
            }
            else
            {
                registerResult.Result = ProcessCodes.KeyInvalid;
            }

            if (cl != null)
            {
                license.IsLicensed  = cl.IsLicensed;
                license.IsActivated = cl.IsActivated;
                license.ActivatedOn = cl.ActivatedOn;
            }

            return(registerResult);
        }
            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]);
            }
示例#20
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);
            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");

            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 ClientLicense SaveClientLicense(ClientLicense clientLicense)
 {
     return(SaveClientLicense(clientLicense, Name));
 }
示例#22
0
 public ClientLicense SaveClientLicense(ClientLicense clientLicense)
 {
     return(_clientLicenseRepository.SaveClientLicense(clientLicense));
 }
示例#23
0
 public ClientLicense SaveClientLicense(ClientLicense clientLicense, string filePath)
 {
     return(_clientLicenseRepository.SaveClientLicense(clientLicense, filePath));
 }
        public ClientLicense ActivateLicenseKey(string licenseKey, Guid?token, bool isOffline, ClientLicense scutexLicense, string hardwareFingerprint)
        {
            /* This method used to live in the LicenseKeyService class, where it should be
             *  but because of a circular reference in the WebServicesProvider and the ServicesLibrary
             *  project requiring the LicenseKeyService to valid keys it was causing and error and had
             *  to be moved here.
             */

            if (_licenseKeyService.ValidateLicenseKey(licenseKey, scutexLicense, true))
            {
                Token t = new Token();
                t.Data      = scutexLicense.ServiceToken;
                t.Timestamp = DateTime.Now;

                string packedToken = _packingService.PackToken(t);

                LicenseActivationPayload payload = new LicenseActivationPayload();
                payload.LicenseKey     = licenseKey;
                payload.ServiceLicense = new ServiceLicense(scutexLicense);
                payload.Token          = token;

                if (!String.IsNullOrEmpty(hardwareFingerprint))
                {
                    payload.HardwareFingerprint = hardwareFingerprint;
                }

                if (!isOffline)
                {
                    ActivationResult result = _licenseActiviationProvider.ActivateLicense(scutexLicense.ServiceAddress, packedToken,
                                                                                          GetClientStandardEncryptionInfo(scutexLicense),
                                                                                          payload, scutexLicense);

                    if (result != null && result.WasRequestValid && result.ActivationSuccessful)
                    {
                        scutexLicense.IsLicensed              = true;
                        scutexLicense.IsActivated             = true;
                        scutexLicense.ActivatingServiceId     = result.ServiceId;
                        scutexLicense.ActivationToken         = result.ActivationToken;
                        scutexLicense.ActivatedOn             = DateTime.Now;
                        scutexLicense.ActivationLastCheckedOn = DateTime.Now;

                        _clientLicenseService.SaveClientLicense(scutexLicense);

                        return(scutexLicense);
                    }
                }
                else
                {
                    scutexLicense.IsLicensed              = true;
                    scutexLicense.IsActivated             = false;
                    scutexLicense.ActivatingServiceId     = null;
                    scutexLicense.ActivationToken         = null;
                    scutexLicense.ActivatedOn             = DateTime.Now;
                    scutexLicense.ActivationLastCheckedOn = DateTime.Now;

                    _clientLicenseService.SaveClientLicense(scutexLicense);

                    return(scutexLicense);
                }
            }

            return(scutexLicense);
        }