예제 #1
0
        public void An_not_expired_non_OEM_license_is_valid()
        {
            var rsa = new RSACryptoServiceProvider();
            var licenseGenerator = new LicenseGenerator(rsa.ToXmlString(true));
            var licenseValues    = new Dictionary <string, string>();

            var license          = licenseGenerator.Generate("Foo", Guid.NewGuid(), DateTime.Today.AddDays(1), licenseValues, LicenseType.Subscription);
            var licenseValidator = new StringLicenseValidator(rsa.ToXmlString(false), license)
            {
                DisableFloatingLicenses = true,
                SubscriptionEndpoint    = "http://uberprof.com/Subscriptions.svc"
            };

            licenseValidator.AssertValidLicense();
        }
예제 #2
0
        public void An_expired_non_OEM_license_is_invalid()
        {
            var rsa = new RSACryptoServiceProvider();
            var licenseGenerator = new LicenseGenerator(rsa.ToXmlString(true));
            var licenseValues    = new Dictionary <string, string>();

            var license          = licenseGenerator.Generate("Foo", Guid.NewGuid(), new DateTime(2000, 1, 1), licenseValues, LicenseType.Subscription);
            var licenseValidator = new StringLicenseValidator(rsa.ToXmlString(false), license)
            {
                DisableFloatingLicenses = true,
                SubscriptionEndpoint    = "http://uberprof.com/Subscriptions.svc"
            };

            Assert.Throws <LicenseExpiredException>(() => licenseValidator.AssertValidLicense());
        }
예제 #3
0
 public string LeaseLicense(string previousLicense)
 {
     var tempFileName = Path.GetTempFileName();
     try
     {
         var stringLicenseValidator = new StringLicenseValidator(BaseLicenseTest.public_only, previousLicense);
         if (stringLicenseValidator.TryLoadingLicenseValuesFromValidatedXml() == false)
             throw new InvalidOperationException("Invalid license provided");
         return new LicenseGenerator(BaseLicenseTest.public_and_private).Generate(stringLicenseValidator.Name,
                                                                                  stringLicenseValidator.UserId,
                                                                                  DateTime.UtcNow.AddDays(15),
                                                                                  stringLicenseValidator.LicenseAttributes,
                                                                                  LicenseType.Subscription);
     }
     finally
     {
         File.Delete(tempFileName);
     }
 }
예제 #4
0
        private void PromptUserForLicenseIfTrialHasExpiredInternal()
        {
            if (!(Debugger.IsAttached && SystemInformation.UserInteractive))
            {
                //We only prompt user if user is in debugging mode and we are running in interactive mode
                return;
            }

            bool createdNew;
            using (new Mutex(true, string.Format("NServiceBus-{0}", SoftwareVersion.ToString(2)), out createdNew))
            {
                if (!createdNew)
                {
                    //Dialog already displaying for this software version by another process, so we just use the already assigned license.
                    return;
                }

                //prompt user for license file
                if (trialPeriodHasExpired)
                {
                    bool validLicense;

                    using (var form = new TrialExpired())
                    {
                        form.CurrentLicenseExpireDate = license.ExpirationDate;

                        form.ValidateLicenseFile = (f, s) =>
                            {
                                StringLicenseValidator licenseValidator = null;

                                try
                                {
                                    string selectedLicenseText = ReadAllTextWithoutLocking(s);
                                    licenseValidator = new StringLicenseValidator(LicenseDescriptor.PublicKey,
                                                                                  selectedLicenseText);
                                    licenseValidator.AssertValidLicense();

                                    using (var registryKey = Registry.CurrentUser.CreateSubKey(String.Format(@"SOFTWARE\NServiceBus\{0}", SoftwareVersion.ToString(2))))
                                    {
                                        if (registryKey == null)
                                        {
                                            return false;
                                        }

                                        registryKey.SetValue("License", selectedLicenseText, RegistryValueKind.String);
                                    }

                                    return true;
                                }
                                catch (UnauthorizedAccessException ex)
                                {
                                    Logger.Debug("Could not write to the registry.", ex);
                                    f.DisplayError();
                                }
                                catch (LicenseExpiredException)
                                {
                                    if (licenseValidator != null)
                                    {
                                        f.DisplayExpiredLicenseError(licenseValidator.ExpirationDate);
                                    }
                                    else
                                    {
                                        f.DisplayError();
                                    }
                                }
                                catch (Exception)
                                {
                                    f.DisplayError();
                                }

                                return false;
                            };

                        validLicense = form.ShowDialog() == DialogResult.OK;
                    }

                    if (validLicense)
                    {
                        //if user specifies a valid license file then run with that license
                        validator = CreateValidator();
                        Validate();
                    }
                }
            }
        }
 public string LeaseLicense(string previousLicense)
 {
     var tempFileName = Path.GetTempFileName();
     try
     {
         var stringLicenseValidator = new StringLicenseValidator(BaseLicenseTest.public_only, previousLicense);
         if (stringLicenseValidator.TryLoadingLicenseValuesFromValidatedXml() == false)
             throw new InvalidOperationException("Invalid license provided");
         return new LicenseGenerator(BaseLicenseTest.public_and_private).Generate(stringLicenseValidator.Name,
                                                                                  stringLicenseValidator.UserId,
                                                                                  DateTime.UtcNow.AddDays(15),
                                                                                  stringLicenseValidator.LicenseAttributes,
                                                                                  LicenseType.Subscription);
     }
     finally
     {
         File.Delete(tempFileName);
     }
 }
예제 #6
0
        private bool PromptUserForLicenseInternal()
        {
            if (license.LicenseType == LicenseType.Standard)
            {
                return true;
            }
            else if (license.LicenseType == LicenseType.Trial &&
                    (license.ExpirationDate - DateTime.Now).TotalDays >= TRIAL_NOTIFICATION_DAYS)
            {
                return false;
            }

            //prompt user for license file
            using (var form = new TrialExpired())
            {
                form.CurrentLicenseExpireDate = license.ExpirationDate;

                form.ValidateLicenseFile = (f, s) =>
                {
                    StringLicenseValidator licenseValidator = null;

                    try
                    {
                        string selectedLicenseText = ReadAllTextWithoutLocking(s);
                        licenseValidator = new StringLicenseValidator(LicenseDescriptor.PublicKey,
                                                                        selectedLicenseText);
                        licenseValidator.AssertValidLicense();

                        using (var registryKey = Registry.CurrentUser.CreateSubKey(String.Format(@"SOFTWARE\ParticularSoftware\Studio\{0}", SoftwareVersion.ToString(2))))
                        {
                            if (registryKey == null)
                            {
                                return false;
                            }

                            registryKey.SetValue("License", selectedLicenseText, RegistryValueKind.String);
                        }

                        return true;
                    }
                    catch (UnauthorizedAccessException ex)
                    {
                        tracer.Warn("Could not write to the registry.", ex);
                        f.DisplayError();
                    }
                    catch (LicenseExpiredException)
                    {
                        if (licenseValidator != null)
                        {
                            f.DisplayExpiredLicenseError(licenseValidator.ExpirationDate);
                        }
                        else
                        {
                            f.DisplayError();
                        }
                    }
                    catch (Exception)
                    {
                        f.DisplayError();
                    }

                    return false;
                };

                if (trialPeriodHasExpired)
                {
                    form.ExpiredTrialVersion();
                }
                else
                {
                    form.TrialVersion((license.ExpirationDate - DateTime.Now).Days);
                }

                //if user specifies a valid license file then run with that license
                validator = CreateValidator();
                Validate();

                if (license.LicenseType == LicenseType.Standard)
                {
                    return true;
                }
                else if (license.LicenseType == LicenseType.Trial && trialPeriodHasExpired)
                {
                    throw new LicenseExpiredException();
                }

                return false;
            }
        }