コード例 #1
0
ファイル: LicenseManager.cs プロジェクト: xqfgbc/NServiceBus
        internal static void InitializeLicense()
        {
            //only do this if not been configured by the fluent API
            if (licenseText == null)
            {
                licenseText = GetExistingLicense();
            }

            if (string.IsNullOrWhiteSpace(licenseText))
            {
                license = GetTrialLicense();
                return;
            }

            LicenseVerifier.Verify(licenseText);

            var foundLicense = LicenseDeserializer.Deserialize(licenseText);

            if (LicenseExpirationChecker.HasLicenseExpired(foundLicense))
            {
                Logger.Fatal(" You can renew it at http://particular.net/licensing.");
                return;
            }

            if (foundLicense.UpgradeProtectionExpiration != null)
            {
                Logger.InfoFormat("UpgradeProtectionExpiration: {0}", foundLicense.UpgradeProtectionExpiration);
            }
            else
            {
                Logger.InfoFormat("Expires on {0}", foundLicense.ExpirationDate);
            }

            license = foundLicense;
        }
コード例 #2
0
        private void Browse_Click(object sender, RoutedEventArgs e)
        {
            using (var openDialog = new OpenFileDialog())
            {
                openDialog.InitializeLifetimeService();
                openDialog.Filter = "License files (*.xml)|*.xml|All files (*.*)|*.*";
                openDialog.Title  = "Select License file";

                var dialogResult = StaThreadRunner.ShowDialogInSTA(() => { return(openDialog.ShowDialog()); });
                if (dialogResult == System.Windows.Forms.DialogResult.OK)
                {
                    var licenseText = NonLockingFileReader.ReadAllTextWithoutLocking(openDialog.FileName);
                    try
                    {
                        LicenseVerifier.Verify(licenseText);
                        var license = LicenseDeserializer.Deserialize(licenseText);

                        if (LicenseExpirationChecker.HasLicenseExpired(license))
                        {
                            var message = string.Format("The license you provided has expired.\r\nEither extend your trial or contact sales to obtain a new license. Or try a different file.");
                            MessageBox.Show(this, message, "License expired", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                            return;
                        }
                        ResultingLicenseText = licenseText;
                        Close();
                    }
                    catch (Exception exception)
                    {
                        var message = string.Format("An error occurred when parsing the license.\r\nMessage: {0}\r\nThe exception details have been appended to your log.", exception.Message);
                        MessageBox.Show(this, message, "Error parsing license", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
        }
コード例 #3
0
        public bool TryInstallLicense(string licenseText)
        {
            try
            {
                if (!LicenseVerifier.TryVerify(licenseText, out _))
                {
                    return(false);
                }

                CurrentLicense = LicenseDeserializer.Deserialize(licenseText);

                if (!CurrentLicense.ValidForApplication("ServiceInsight"))
                {
                    return(false);
                }

                new RegistryLicenseStore().StoreLicense(licenseText);
                new FilePathLicenseStore().StoreLicense(FilePathLicenseStore.UserLevelLicenseLocation, licenseText);

                return(true);
            }
            catch (Exception ex)
            {
                LogTo.Warning(ex, "Can't install license: {ex}", ex);
                return(false);
            }
        }
コード例 #4
0
        public static bool TryImportLicense(string licenseFile, out string errorMessage)
        {
            var licenseText = NonBlockingReader.ReadAllTextWithoutLocking(licenseFile);

            if (!LicenseVerifier.TryVerify(licenseText, out _))
            {
                errorMessage = "Invalid license file";
                return(false);
            }

            if (!TryDeserializeLicense(licenseText, out var license))
            {
                errorMessage = "Invalid license file";
                return(false);
            }

            if (!license.ValidForApplication("ServiceControl"))
            {
                errorMessage = "License is not for ServiceControl";
                return(false);
            }

            if (license.HasExpired())
            {
                errorMessage = "Failed to import because the license has expired";
                return(false);
            }

            try
            {
                new RegistryLicenseStore(Registry.LocalMachine).StoreLicense(licenseText);
            }
            catch (Exception)
            {
                errorMessage = "Failed to import license into the registry";
                return(false);
            }

            try
            {
                var machineLevelLicenseLocation = LicenseFileLocationResolver.GetPathFor(Environment.SpecialFolder.CommonApplicationData);

                new FilePathLicenseStore().StoreLicense(machineLevelLicenseLocation, licenseText);
            }
            catch (Exception)
            {
                errorMessage = "Failed to import license into the filesystem";
                return(false);
            }

            errorMessage = null;
            return(true);
        }
コード例 #5
0
            /// <summary>
            /// Enables SSL over the driver port
            /// </summary>
            /// <param name="context">Context settings for the SSL stream.</param>
            public virtual Builder EnableSsl(SslContext context, string licenseTo, string licenseKey)
            {
                this.sslContext = context;

#if !DEBUG
                if (!LicenseVerifier.VerifyLicense(licenseTo, licenseKey))
                {
                    throw new ReqlDriverError("The SSL/TLS usage license is invalid. Please check your license that you copied all the characters in your license. If you still have trouble, please contact [email protected].");
                }
#endif
                return(this);
            }
コード例 #6
0
        static ActiveLicense DetermineActiveLicense()
        {
            var activeLicense = new ActiveLicense
            {
                IsValid = false
            };

            var licenseText = TryFindLicense();

            if (string.IsNullOrEmpty(licenseText))
            {
                Logger.Warn("No valid license could be found, falling back to trial license");

                activeLicense.Details = License.TrialLicense(TrialStartDateStore.GetTrialStartDate());
            }
            else
            {
                Exception validationFailure;

                if (!LicenseVerifier.TryVerify(licenseText, out validationFailure))
                {
                    Logger.WarnFormat("Found license was not valid: {0}", validationFailure);
                    return(activeLicense);
                }


                var licenseDetails = LicenseDeserializer.Deserialize(licenseText);

                if (!licenseDetails.ValidForApplication("ServiceControl"))
                {
                    Logger.WarnFormat("Found license was is not valid for ServiceControl. Valid apps: '{0}'", string.Join(",", licenseDetails.ValidApplications));
                    return(activeLicense);
                }

                activeLicense.Details = licenseDetails;
            }

            activeLicense.HasExpired = LicenseExpirationChecker.HasLicenseExpired(activeLicense.Details);

            if (activeLicense.HasExpired)
            {
                Logger.WarnFormat("Found license has expired");
            }
            else
            {
                activeLicense.IsValid = true;
            }

            return(activeLicense);
        }
コード例 #7
0
        public void keys_should_throw()
        {
            Action a = () => LicenseVerifier.AssertKeyIsNotBanned("fff");

            a.ShouldNotThrow();

            Action b = () => LicenseVerifier.AssertKeyIsNotBanned(
                "fuIIq8Pre2NzXVi0otn54PCx22NNAbNReAsk/ylDIV/ZrWeC60B+C76oj3/Ptb8b02vxPYdN6nR2nz3IgYG/O6Zy5TKoYl2UnR2aNq8sKxjv9siwsjMS82EZB8pxs0UwPoz+xmrKY40sqiIz+thDI2EH1MlGoZd+KfJImJp7fvI=");

            b.ShouldThrow <UnauthorizedAccessException>();

            Action c = () => LicenseVerifier.AssertKeyIsNotBanned("tE4z+qpOuKWP4XfmAbnyepzI6m/qx2DaI+aDkMes94ujERmA7O6bb0100+LiClLymVLXYXNvkRBg7ot6NGlfyli/8x1h3IgL+HD8gFoWdTAN4oG8wE8ZyrFugnqmAHUDAy4h/KrOqB8VUXwGQh8Y/0ZxOBQb0KOaZJC/MUMbve8=");

            c.ShouldThrow <UnauthorizedAccessException>();
        }
コード例 #8
0
        public AppLicenseManager()
        {
            var licenseText = GetExistingLicense();

            if (!String.IsNullOrEmpty(licenseText))
            {
                Exception ex;
                if (LicenseVerifier.TryVerify(licenseText, out ex))
                {
                    CurrentLicense = LicenseDeserializer.Deserialize(licenseText);
                    return;
                }
            }

            CurrentLicense = CreateTrialLicense();
        }
コード例 #9
0
        public static bool TryImportLicense(string licenseFile, out string errorMessage)
        {
            Exception validationFailure;
            License   license;
            var       licenseText = NonLockingFileReader.ReadAllTextWithoutLocking(licenseFile);

            if (!LicenseVerifier.TryVerify(licenseText, out validationFailure))
            {
                errorMessage = "Invalid license file";
                return(false);
            }

            if (!TryDeserializeLicense(licenseText, out license))
            {
                errorMessage = "Invalid license file";
                return(false);
            }

            if (!license.ValidForApplication("ServiceControl"))
            {
                errorMessage = "License is not for ServiceControl";
                return(false);
            }

            try
            {
                new RegistryLicenseStore(Registry.LocalMachine).StoreLicense(licenseText);
            }
            catch (Exception)
            {
                errorMessage = "Failed to import license into the registry";
                return(false);
            }

            try
            {
                new FilePathLicenseStore().StoreLicense(FilePathLicenseStore.MachineLevelLicenseLocation, licenseText);
            }
            catch (Exception)
            {
                errorMessage = "Failed to import license into the filesystem";
                return(false);
            }

            errorMessage = null;
            return(true);
        }
コード例 #10
0
        public AppLicenseManager()
        {
            string licenseText;

            if (licenseStore.TryReadLicense(out licenseText))
            {
                Exception ex;

                if (LicenseVerifier.TryVerify(licenseText, out ex))
                {
                    CurrentLicense = LicenseDeserializer.Deserialize(licenseText);

                    return;
                }
            }

            CurrentLicense = CreateTrialLicense();
        }
コード例 #11
0
        internal void InitializeLicense(string licenseText)
        {
            //only do this if not been configured by the fluent API
            if (licenseText == null)
            {
                licenseText = GetExistingLicense();
            }

            if (string.IsNullOrWhiteSpace(licenseText))
            {
                license = GetTrialLicense();
                PromptUserForLicenseIfTrialHasExpired();
                return;
            }

            LicenseVerifier.Verify(licenseText);

            var foundLicense = LicenseDeserializer.Deserialize(licenseText);

            if (LicenseExpirationChecker.HasLicenseExpired(foundLicense))
            {
                // If the found license is a trial license then it is actually a extended trial license not a locally generated trial.
                // Set the property to indicate that it is an extended license as it's not set by the license generation
                if (foundLicense.IsTrialLicense)
                {
                    foundLicense.IsExtendedTrial = true;
                    PromptUserForLicenseIfTrialHasExpired();
                    return;
                }
                Logger.Fatal("Your license has expired! You can renew it at https://particular.net/licensing.");
                return;
            }

            if (foundLicense.UpgradeProtectionExpiration != null)
            {
                Logger.InfoFormat("License upgrade protection expires on: {0}", foundLicense.UpgradeProtectionExpiration);
            }
            else
            {
                Logger.InfoFormat("License expires on {0}", foundLicense.ExpirationDate);
            }

            license = foundLicense;
        }
コード例 #12
0
        public static bool TryImportLicense(string licenseFile, out string errorMessage)
        {
            var licenseText = NonBlockingReader.ReadAllTextWithoutLocking(licenseFile);

            if (!LicenseVerifier.TryVerify(licenseText, out _))
            {
                errorMessage = "Invalid license file";
                return(false);
            }

            if (!TryDeserializeLicense(licenseText, out var license))
            {
                errorMessage = "Invalid license file";
                return(false);
            }

            if (!license.ValidForApplication("ServiceControl"))
            {
                errorMessage = "License is not for ServiceControl";
                return(false);
            }

            if (license.HasExpired())
            {
                errorMessage = "Failed to import because the license has expired";
                return(false);
            }

            try
            {
                new FilePathLicenseStore().StoreLicense(GetMachineLevelLicenseLocation(), licenseText);
            }
            catch (Exception)
            {
                errorMessage = "Failed to import license into the filesystem";
                return(false);
            }

            errorMessage = null;
            return(true);
        }
コード例 #13
0
        public static bool TryImportLicense(string licenseFile, out string errorMessage)
        {
            Exception validationFailure;
            License   license;
            var       licenseText = NonLockingFileReader.ReadAllTextWithoutLocking(licenseFile);

            if (!LicenseVerifier.TryVerify(licenseText, out validationFailure))
            {
                errorMessage = "Invalid license file";
                return(false);
            }

            if (!TryDeserializeLicense(licenseText, out license))
            {
                errorMessage = "Invalid license file";
                return(false);
            }

            if (!license.ValidForApplication("ServiceControl"))
            {
                errorMessage = "License is not for ServiceControl";
                return(false);
            }

            try
            {
                using (var localMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Default))
                {
                    new RegistryLicenseStore(localMachine).StoreLicense(licenseText);
                }
            }
            catch (Exception)
            {
                errorMessage = "Failed to import license into the registry";
                return(false);
            }

            errorMessage = null;
            return(true);
        }
コード例 #14
0
        void InitializeLicense()
        {
            //only do this if not been configured by the fluent API
            if (licenseText == null)
            {
                //look in the new platform locations
                if (!(new RegistryLicenseStore().TryReadLicense(out licenseText)))
                {
                    //TODO: Check legacy locations for Service Matrix.
                    if (string.IsNullOrWhiteSpace(licenseText))
                    {
                        license = GetTrialLicense();
                        return;
                    }
                }
            }

            LicenseVerifier.Verify(licenseText);

            var foundLicense = LicenseDeserializer.Deserialize(licenseText);

            if (LicenseExpirationChecker.HasLicenseExpired(foundLicense))
            {
                tracer.Error("You can renew it at http://particular.net/licensing.");
                return;
            }

            if (foundLicense.UpgradeProtectionExpiration != null)
            {
                tracer.Info(string.Format("UpgradeProtectionExpiration: {0}", foundLicense.UpgradeProtectionExpiration));
            }
            else
            {
                tracer.Info(string.Format("Expires on {0}", foundLicense.ExpirationDate));
            }

            license = foundLicense;
        }
コード例 #15
0
        public bool TryInstallLicense(string licenseText)
        {
            try
            {
                Exception verificationException;

                if (!LicenseVerifier.TryVerify(licenseText, out verificationException))
                {
                    return(false);
                }

                CurrentLicense = LicenseDeserializer.Deserialize(licenseText);

                new RegistryLicenseStore().StoreLicense(licenseText);

                return(true);
            }
            catch (Exception ex)
            {
                LogTo.Warning(ex, "Can't install license: {ex}", ex);
                return(false);
            }
        }
コード例 #16
0
        public bool TryInstallLicense(string licenseText)
        {
            try
            {
                Exception verificationException;

                if (!LicenseVerifier.TryVerify(licenseText, out verificationException))
                {
                    return(false);
                }

                CurrentLicense = LicenseDeserializer.Deserialize(licenseText);

                licenseStore.StoreLicense(licenseText);

                return(true);
            }
            catch (Exception ex)
            {
                Logger.WarnFormat("Can't install license: {0}", ex);
                return(false);
            }
        }
コード例 #17
0
        void browseButton_Click(object sender, EventArgs e)
        {
            using (var openDialog = new OpenFileDialog())
            {
                openDialog.InitializeLifetimeService();
                openDialog.Filter = "License files (*.xml)|*.xml|All files (*.*)|*.*";
                openDialog.Title  = "Select License file";

                var dialogResult = StaThreadRunner.ShowDialogInSTA(openDialog.ShowDialog);
                if (dialogResult == DialogResult.OK)
                {
                    var licenseText = NonLockingFileReader.ReadAllTextWithoutLocking(openDialog.FileName);
                    try
                    {
                        LicenseVerifier.Verify(licenseText);
                        var license = LicenseDeserializer.Deserialize(licenseText);

                        if (LicenseExpirationChecker.HasLicenseExpired(license))
                        {
                            var message = string.Format("The license you provided has expired, please select another file.");
                            Logger.Warn(message);
                            MessageBox.Show(this, message, "License expired", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return;
                        }
                        ResultingLicenseText = licenseText;
                        Close();
                    }
                    catch (Exception exception)
                    {
                        var message = string.Format("An error occurred when parsing the license.\r\nMessage: {0}\r\nThe exception details have been appended to your log.", exception.Message);
                        Logger.Warn("Error parsing license", exception);
                        MessageBox.Show(this, message, "Error parsing license", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
コード例 #18
0
 public string RenderHtml()
 {
     return(GetResponse(LicenseVerifier.Check()));
 }
コード例 #19
0
 public string GetJsonOptions()
 {
     return(GetJsonResponse(LicenseVerifier.Check()));
 }