Exemple #1
0
        public void SaveLicense(string productName, ProductLicenseInfo licenseInfo)
        {
            lock (_syncRoot)
            {
                if (licenseInfo == null) // Delete the license
                {
                    using (var machineStore = IsolatedStorageFile.GetMachineStoreForAssembly())
                    {
                        if (machineStore != null)
                        {
                            machineStore.DeleteFile(productName);
                        }
                    }
                    return;
                }

                using (var machineStore = IsolatedStorageFile.GetMachineStoreForAssembly())
                {
                    if (machineStore != null)
                    {
                        using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(productName, FileMode.Create, machineStore))
                            using (StreamWriter writer = new StreamWriter(stream))
                            {
                                XmlSerializer serializer = new XmlSerializer(typeof(ProductLicenseInfo));
                                serializer.Serialize(writer, licenseInfo);
                            }
                    }
                }
            }
        }
Exemple #2
0
 public ProductLicense(RSACryptoServiceProvider cryptoService, IMachineIdentifierProvider identifierService, ProductLicenseInfo licenseInfo, IUserInformationProvider userInfoProvider)
 {
     _hashService       = new SHA1CryptoServiceProvider();
     _cryptoService     = cryptoService;
     _identifierService = identifierService;
     _userInfoProvider  = userInfoProvider;
     LicenseInfo        = licenseInfo;
     ProcessLicense();
 }
Exemple #3
0
 public ProductLicense LoadLicense(string productName)
 {
     try
     {
         ProductLicenseInfo licenseInfo    = _licenseStore.LoadLicense(productName);
         ProductLicense     productLicense = new ProductLicense(_cryptoService, _identifierService, licenseInfo, _userInfoProvider);
         return(productLicense);
     }
     catch (LicenseNotFoundException ex)
     {
         return(new ProductLicense(LicenseStatus.NotFound, ex.Message));
     }
     catch (Exception ex)
     {
         return(new ProductLicense(LicenseStatus.Invalid, ex.Message));
     }
 }
Exemple #4
0
 public WebProductLicense LoadWebLicense(string productName)
 {
     try
     {
         ProductLicenseInfo licenseInfo    = _licenseStore.LoadLicense(productName);
         UsersPool          usersPool      = _licenseStore.LoadUsersPoolLicense(ActivationConstants.WebUsersPoolName);
         WebProductLicense  productLicense = new WebProductLicense(_cryptoService, _identifierService, licenseInfo, _userInfoProvider, usersPool);
         return(productLicense);
     }
     catch (LicenseNotFoundException ex)
     {
         return(new WebProductLicense(WebLicenseStatus.NotFound, "Common_License_StatusReason_Exception", ex.Message));
     }
     catch (Exception ex)
     {
         return(new WebProductLicense(WebLicenseStatus.Invalid, "Common_License_StatusReason_Exception", ex.Message));
     }
 }
Exemple #5
0
 public ProductLicense ActivateProduct(ProductLicenseInfo licenseInfo)
 {
     try
     {
         if (licenseInfo.Signature != null)
         {
             ProductLicense productLicense = new ProductLicense(_cryptoService, _identifierService, licenseInfo, _userInfoProvider);
             return(productLicense);
         }
         else
         {
             return(new ProductLicense(LicenseStatus.Invalid, licenseInfo.ActivationInfo));
         }
     }
     catch (Exception ex)
     {
         return(new ProductLicense(LicenseStatus.InternalError, ex.Message));
     }
 }
Exemple #6
0
 public WebProductLicense ActivateWebProduct(ProductLicenseInfo licenseInfo)
 {
     try
     {
         if (licenseInfo.Signature != null)
         {
             UsersPool         usersPool      = _licenseStore.LoadUsersPoolLicense(ActivationConstants.WebUsersPoolName);
             WebProductLicense productLicense = new WebProductLicense(_cryptoService, _identifierService, licenseInfo, _userInfoProvider, usersPool);
             return(productLicense);
         }
         else
         {
             return(new WebProductLicense(WebLicenseStatus.Invalid, "Common_License_StatusReason_Exception", licenseInfo.ActivationInfo));
         }
     }
     catch (Exception ex)
     {
         return(new WebProductLicense(WebLicenseStatus.InternalError, "Common_License_StatusReason_Exception", ex.Message));
     }
 }
Exemple #7
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);
        }