Esempio n. 1
0
        public async Task <IHttpActionResult> GetLicense()
        {
            try
            {
                var userIds = await _applicationUsersService.GetAllUserIds();

                if (userIds == null)
                {
                    userIds = Array.Empty <int>();
                }

                XmlDocument doc = new XmlDocument();
                doc.Load("Files/PublicKey.xml");
                ProductLicenseManager.Initialize(_traceManager, doc.OuterXml);
                var license = ProductLicenseManager.Current.LoadWebLicense(ActivationConstants.WebProductName);

                // Clean Userpool
                if (license != null && license.UsersPool != null && license.UsersPool.Any(u => !userIds.Contains(u)))
                {
                    license.UsersPool.RemoveWhere(u => !userIds.Contains(u));
                    ProductLicenseManager.Current.SaveWebLicense(ActivationConstants.WebProductName, license);
                }

                return(Ok(license));
            }
            catch (Exception ex)
            {
                _traceManager.TraceError(ex, ex.Message);
                return(InternalServerError(ex));
            }
        }
Esempio n. 2
0
        public void LoadSaveLicense()
        {
            string publicXmlKey = KeyHelpers.GetPrivateKey();
            ProductLicenseManager licenseManager = new ProductLicenseManager(null, publicXmlKey,
                                                                             new MockLicenseStore(),
                                                                             new MachineIdentifierProviderMock(),
                                                                             new UserInformationProviderMock()
            {
                Username = "******",
                Company  = "Company",
                Email    = "*****@*****.**"
            });
            ProductLicense license = licenseManager.LoadLicense("MyProductName");

            string productKey       = GenerateProductKey(123, 456, 0, "C", "toto", "Company", "*****@*****.**");
            var    licenseActivated = GetProductActivated(productKey);

            Assert.AreEqual(LicenseStatus.NotFound, license.Status, license.StatusReason);

            license = licenseManager.ActivateProduct(licenseActivated);
            licenseManager.SaveLicense("MyProductName", license);
            license = licenseManager.LoadLicense("MyProductName");

            Assert.AreEqual(LicenseStatus.Licensed, license.Status, license.StatusReason);
            Assert.AreEqual(123, license.ProductID);
            Assert.AreEqual(456, license.ProductFeatures);
            Assert.AreEqual(0, license.TrialDays);
        }
Esempio n. 3
0
        /// <summary>
        /// Check the license information if we have a valid license either trial or real the application
        /// will continue to work. If there is no valid license and the warehouse was created less than 30 days before
        /// the application will work.
        /// </summary>
        public static void InitializeLicenseManager()
        {
            Nullable <LicenseStatus> previous;
            Nullable <short>         previousProductFeatures;

            if (productLicense != null)
            {
                previous = productLicense.Status;
                previousProductFeatures = productLicense.ProductFeatures;
            }
            else
            {
                previous = null;
                previousProductFeatures = null;
            }
            string publicXmlKey = RetrievePublicKey(@"RSAKeys\PublicKey.xml");

            productLicenseManager = new ProductLicenseManager(publicXmlKey);
            if (!Directory.Exists(licensePath))
            {
                CreatePath(licensePath);
            }
            productLicenseManager.SaveMachineKey(Path.Combine(licensePath, "EasyBuilder"));
            productLicense = productLicenseManager.LoadLicense(Path.Combine(licensePath, "EasyBuilder"));
            StringBuilder licenseText = new StringBuilder();

            if (CheckProduct(productLicense))
            {
                licenseText = SwitchLicenseStatus(licenseText);
            }
            else
            {
                LicenseProperties.IsActivated = false;
                licenseText.AppendLine("LIC_WrongProductLicense");
            }

            if (LicenseProperties.ActivatedFeatures.HasFlag(LicenseFeatures.Normal))
            {
                licenseText.Append("LIC_DevelopementFeature");
            }

            if (productLicense.ProductFeatures == 5)
            {
                licenseText.Append("LIC_APPSSTANDARDDEVELOPER");
            }

            LicenseProperties.LicenseTextResult = licenseText.ToString();
            if ((previous.HasValue && previous.Value != productLicense.Status) || (previousProductFeatures.HasValue && previousProductFeatures.Value != productLicense.ProductFeatures))
            {
                EventHandler handler = LicenseChanged;
                if (handler != null)
                {
                    handler(null, EventArgs.Empty);
                }
            }
        }
Esempio n. 4
0
        public IHttpActionResult GetMachineHash()
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load("Files/PublicKey.xml");
                ProductLicenseManager.Initialize(_traceManager, doc.OuterXml);
                var hash = ProductLicenseManager.Current.GetMachineHash();

                return(Ok(hash));
            }
            catch (Exception ex)
            {
                _traceManager.TraceError(ex, ex.Message);
                return(InternalServerError(ex));
            }
        }
Esempio n. 5
0
        public void ActivateProductMachineMismatch()
        {
            MachineIdentifierProviderMock machineMock = new MachineIdentifierProviderMock(false);
            string productKey       = GenerateProductKey(123, 456, 0, "C", "toto", "Company", "*****@*****.**");
            var    licenseActivated = GetProductActivated(productKey);

            string publicXmlKey = KeyHelpers.GetPrivateKey();
            ProductLicenseManager licenseManager = new ProductLicenseManager(null, publicXmlKey, null, machineMock,
                                                                             new UserInformationProviderMock()
            {
                Username = "******",
                Company  = "Company",
                Email    = "*****@*****.**"
            });
            ProductLicense license = licenseManager.ActivateProduct(licenseActivated);

            Assert.AreEqual(LicenseStatus.MachineHashMismatch, license.Status, license.StatusReason);
        }
Esempio n. 6
0
        public IHttpActionResult SetLicense([DynamicBody] dynamic param)
        {
            try
            {
                WebProductLicense productLicense = (WebProductLicense)param.productLicense;

                XmlDocument doc = new XmlDocument();
                doc.Load("Files/PublicKey.xml");
                ProductLicenseManager.Initialize(_traceManager, doc.OuterXml);
                ProductLicenseManager.Current.SaveWebLicense(ActivationConstants.WebProductName, productLicense);

                return(Ok());
            }
            catch (Exception ex)
            {
                _traceManager.TraceError(ex, ex.Message);
                return(InternalServerError(ex));
            }
        }
Esempio n. 7
0
        public IHttpActionResult ActivateLicense([DynamicBody] dynamic param)
        {
            try
            {
                ProductLicenseInfo productLicenseInfo = (ProductLicenseInfo)param.productLicenseInfo;

                XmlDocument doc = new XmlDocument();
                doc.Load("Files/PublicKey.xml");
                ProductLicenseManager.Initialize(_traceManager, doc.OuterXml);
                var license = ProductLicenseManager.Current.ActivateWebProduct(productLicenseInfo);

                return(Ok(license));
            }
            catch (Exception ex)
            {
                _traceManager.TraceError(ex, ex.Message);
                return(InternalServerError(ex));
            }
        }
Esempio n. 8
0
        public void ActivateProductWrongUserInfo()
        {
            string productKey       = GenerateProductKey(123, 456, 0, "C", "toto", "Company", "*****@*****.**");
            var    licenseActivated = GetProductActivated(productKey);

            string publicXmlKey = KeyHelpers.GetPrivateKey();
            ProductLicenseManager licenseManager = new ProductLicenseManager(null, publicXmlKey,
                                                                             new MockLicenseStore(),
                                                                             new MachineIdentifierProviderMock(),
                                                                             new UserInformationProviderMock()
            {
                Username = "******",
                Company  = "Company",
                Email    = "*****@*****.**"
            });
            ProductLicense license = licenseManager.ActivateProduct(licenseActivated);

            Assert.AreEqual(LicenseStatus.Invalid, license.Status, license.StatusReason);
        }
Esempio n. 9
0
        public void LoadSaveLicenseRealHash()
        {
            System.Threading.Thread.CurrentThread.CurrentCulture   = System.Globalization.CultureInfo.GetCultureInfo("fr-FR");
            System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("fr-FR");

            string publicXmlKey = KeyHelpers.GetPrivateKey();
            ProductLicenseManager licenseManager = new ProductLicenseManager(null, publicXmlKey,
                                                                             new MockLicenseStore(),
                                                                             new MachineIdentifierProvider(null, new Security.Activation.MachineIdentifiers.VolumeInfoIdentifier(null)),
                                                                             new UserInformationProviderMock()
            {
                Username = "******",
                Company  = "Company",
                Email    = "*****@*****.**"
            });

            var hash = licenseManager.GetMachineHash();

            ProductLicense license = licenseManager.LoadLicense("MyProductName");

            string productKey       = GenerateProductKey(123, 456, 0, "C", "toto", "Company", "*****@*****.**");
            var    licenseActivated = GetProductActivatedRealHash(productKey, hash);

            try
            {
                using (StreamWriter writer = new StreamWriter("out.ksk", false))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(ProductLicenseInfo));
                    serializer.Serialize(writer, licenseActivated);
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
                return;
            }

            Assert.AreEqual(LicenseStatus.NotFound, license.Status, license.StatusReason);

            KProcess.Ksmed.Security.Activation.ProductLicenseInfo licenseInfo = null;
            try
            {
                using (System.IO.StreamReader reader = new System.IO.StreamReader("out.ksk"))
                {
                    var serializer = new System.Xml.Serialization.XmlSerializer(typeof(KProcess.Ksmed.Security.Activation.ProductLicenseInfo));
                    licenseInfo = (KProcess.Ksmed.Security.Activation.ProductLicenseInfo)serializer.Deserialize(reader);
                }
                license = licenseManager.ActivateProduct(licenseInfo);
            }
            catch (Exception e)
            {
                Assert.Fail(e.Message);
            }

            license = licenseManager.ActivateProduct(licenseInfo);
            licenseManager.SaveLicense("MyProductName", license);
            license = licenseManager.LoadLicense("MyProductName");

            Assert.AreEqual(LicenseStatus.Licensed, license.Status, license.StatusReason);
            Assert.AreEqual(123, license.ProductID);
            Assert.AreEqual(456, license.ProductFeatures);
            Assert.AreEqual(0, license.TrialDays);
        }