private string PeriodBackupToolTip(LicensingStatus license) { const string enabledMsg = "Periodic Backup is enabled according to your license, in order to activate it go to the settings section after creating the database"; if (license == null || license.Attributes == null) { return(enabledMsg); } string active; if (license.Attributes.TryGetValue("PeriodicBackup", out active) == false) { return(enabledMsg); } bool result; bool.TryParse(active, out result); if (result) { return(enabledMsg); } return("Periodic Backup Bundle is not approved in you license"); }
private void ExecuteInternal(InMemoryRavenConfiguration config) { var licensePath = GetLicensePath(config); var licenseText = GetLicenseText(config); if (TryLoadLicense(licenseText) == false) return; try { licenseValidator.AssertValidLicense(() => { string value; LicenseAttributes = licenseValidator.LicenseAttributes; AssertForV2(licenseValidator.LicenseAttributes); if (licenseValidator.LicenseAttributes.TryGetValue("OEM", out value) && "true".Equals(value, StringComparison.InvariantCultureIgnoreCase)) { licenseValidator.MultipleLicenseUsageBehavior = AbstractLicenseValidator.MultipleLicenseUsage.AllowSameLicense; } }); CurrentLicense = new LicensingStatus { Status = "Commercial - " + licenseValidator.LicenseType, Error = false, Message = "Valid license at " + licensePath, Attributes = licenseValidator.LicenseAttributes }; } catch (Exception e) { logger.ErrorException("Could not validate license at " + licensePath + ", " + licenseText, e); try { var xmlDocument = new XmlDocument(); xmlDocument.LoadXml(licensePath); var sig = xmlDocument.SelectSingleNode("/license/Signature"); if (sig != null && sig.ParentNode != null) sig.ParentNode.RemoveChild(sig); var stringBuilder = new StringBuilder(); xmlDocument.WriteTo(XmlWriter.Create(stringBuilder)); licenseText = stringBuilder.ToString(); } catch (Exception) { // couldn't remove the signature, maybe not XML? } CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = true, Message = "Could not validate license: " + licensePath + ", " + licenseText + Environment.NewLine + e }; } }
private void TestTimeoutCallback(object state) { licensingStatus = GetLicensingStatus(); DeactivateTimer(); requestManger.IsInHotSpareMode = true; CheckHotSpareLicenseStats(); }
public void Execute(RavenDBOptions serverOptions) { landlord = serverOptions.DatabaseLandlord; licensingStatus = GetLicensingStatus(); ValidateLicense.CurrentLicenseChanged += OnCurrentLicenseChanged; CheckSupportCoverage(); supportTimer = landlord.SystemDatabase.TimerManager.NewTimer(_ => CheckSupportCoverage(), OneDay, OneDay); }
private bool LicenseEqual(LicensingStatus license1, LicensingStatus license2) { string id1; string id2; license1.Attributes.TryGetValue("UserId", out id1); license2.Attributes.TryGetValue("UserId", out id2); return(id1 == id2 && license1.Status == license2.Status); }
public void Execute(RavenDBOptions serverOptions) { requestManger = serverOptions.RequestManager; landlord = serverOptions.DatabaseLandlord; requestManger.HotSpareValidator = this; licensingStatus = GetLicensingStatus(); ValidateLicense.CurrentLicenseChanged += OnCurrentLicenseChanged; CheckHotSpareLicenseStats(); }
public void Execute(DocumentDatabase database) { string publicKey; using (var stream = typeof(ValidateLicense).Assembly.GetManifestResourceStream("Raven.Database.Commercial.RavenDB.public")) { if (stream == null) { throw new InvalidOperationException("Could not find public key for the license"); } publicKey = new StreamReader(stream).ReadToEnd(); } var fullPath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "license.xml")); licenseValidator = new LicenseValidator(publicKey, fullPath) { DisableFloatingLicenses = true, }; licenseValidator.LicenseInvalidated += LicenseValidatorOnLicenseInvalidated; licenseValidator.MultipleLicensesWereDiscovered += LicenseValidatorOnMultipleLicensesWereDiscovered; if (File.Exists(fullPath) == false) { CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = false, Message = "No license file was found at " + fullPath + "\r\nThe AGPL license restrictions apply, only Open Source / Development work is permitted." }; return; } try { licenseValidator.AssertValidLicense(); CurrentLicense = new LicensingStatus { Status = "Commercial - " + licenseValidator.LicenseType, Error = false, Message = "Valid license " + fullPath }; } catch (Exception e) { logger.ErrorException("Could not validate license at " + fullPath, e); CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = true, Message = "Could not validate license file at " + fullPath + Environment.NewLine + e }; } }
static ValidateLicense() { CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = false, Message = "No license file was found.\r\n" + "The AGPL license restrictions apply, only Open Source / Development work is permitted." }; }
private void OnLicenseInvalidated(InvalidationType invalidationType) { logger.Error("The license have expired and can no longer be used"); CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = true, Message = "License expired" }; }
private void OnCurrentLicenseChanged(LicensingStatus newLicense) { //don't want to do anything if the license is the same. if (LicenseEqual(licensingStatus, newLicense)) { return; } licensingStatus = newLicense; CheckHotSpareLicenseStats(); }
private bool TryLoadLicense(InMemoryRavenConfiguration config) { string publicKey; using ( var stream = typeof(ValidateLicense).Assembly.GetManifestResourceStream("Raven.Database.Commercial.RavenDB.public")) { if (stream == null) { throw new InvalidOperationException("Could not find public key for the license"); } publicKey = new StreamReader(stream).ReadToEnd(); } var value = GetLicenseText(config); var fullPath = GetLicensePath(config).ToFullPath(); if (IsSameLicense(value, fullPath)) { return(licenseValidator != null); } if (licenseValidator != null) { licenseValidator.Dispose(); } if (string.IsNullOrEmpty(value) == false) { licenseValidator = new StringLicenseValidator(publicKey, value); } else if (File.Exists(fullPath)) { licenseValidator = new LicenseValidator(publicKey, fullPath); } else { CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = false, Message = "No license file was found at " + fullPath + "\r\nThe AGPL license restrictions apply, only Open Source / Development work is permitted." }; return(false); } licenseValidator.DisableFloatingLicenses = true; licenseValidator.SubscriptionEndpoint = "http://licensing.ravendb.net/Subscriptions.svc"; licenseValidator.LicenseInvalidated += OnLicenseInvalidated; licenseValidator.MultipleLicensesWereDiscovered += OnMultipleLicensesWereDiscovered; return(true); }
static ValidateLicense() { CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = false, Message = "No license file was found.\r\n" + "The AGPL license restrictions apply, only Open Source / Development work is permitted.", Attributes = new Dictionary <string, string>(alwaysOnAttributes, StringComparer.OrdinalIgnoreCase) }; }
static ValidateLicense() { CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = false, Message = "No license file was found.\r\n" + "The AGPL license restrictions apply, only Open Source / Development work is permitted.", Attributes = new Dictionary<string, string>(alwaysOnAttributes, StringComparer.OrdinalIgnoreCase) }; }
private void OnCurrentLicenseChanged(LicensingStatus newLicense) { //don't want to do anything if the license is the same. if (LicenseEqual(licensingStatus, newLicense)) { return; } licensingStatus = newLicense; DeactivateTimer(); CheckSupportCoverage(); supportTimer = landlord.SystemDatabase.TimerManager.NewTimer(_ => CheckSupportCoverage(), OneDay, OneDay); }
public void Execute(DocumentDatabase database) { string publicKey; using(var stream = typeof(ValidateLicense).Assembly.GetManifestResourceStream("Raven.Database.Commercial.RavenDB.public")) { if(stream == null) throw new InvalidOperationException("Could not find public key for the license"); publicKey = new StreamReader(stream).ReadToEnd(); } var fullPath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "license.xml")); licenseValidator = new LicenseValidator(publicKey, fullPath) { DisableFloatingLicenses = true, }; licenseValidator.LicenseInvalidated+=LicenseValidatorOnLicenseInvalidated; licenseValidator.MultipleLicensesWereDiscovered += LicenseValidatorOnMultipleLicensesWereDiscovered; if(File.Exists(fullPath) == false) { CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = false, Message = "No license file was found at " + fullPath + "\r\nThe AGPL license restrictions apply, only Open Source / Development work is permitted." }; return; } try { licenseValidator.AssertValidLicense(); CurrentLicense = new LicensingStatus { Status = "Commercial - " + licenseValidator.LicenseType, Error = false, Message = "Valid license " + fullPath }; } catch (Exception e) { logger.ErrorException("Could not validate license at " + fullPath, e); CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = true, Message = "Could not validate license file at " + fullPath + Environment.NewLine + e }; } }
private void ActivationTimeoutCallback(object state) { var newLicense = GetLicensingStatus(); DeactivateTimer(); if (LicenseEqual(newLicense, licensingStatus)) { requestManger.IsInHotSpareMode = true; ReportUsageOfExpiredHotSpareLicense(ReportHotSpareUssage.ActivationMode.ExpiredActivation, licensingStatus.Attributes["UserId"]); return; } licensingStatus = newLicense; CheckHotSpareLicenseStats(); }
private void OnMultipleLicensesWereDiscovered(object sender, DiscoveryHost.ClientDiscoveredEventArgs clientDiscoveredEventArgs) { logger.Error("A duplicate license was found at {0} for user {1}. User Id: {2}. Both licenses were disabled!", clientDiscoveredEventArgs.MachineName, clientDiscoveredEventArgs.UserName, clientDiscoveredEventArgs.UserId); CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = true, Message = string.Format("A duplicate license was found at {0} for user {1}. User Id: {2}.", clientDiscoveredEventArgs.MachineName, clientDiscoveredEventArgs.UserName, clientDiscoveredEventArgs.UserId) }; }
private void ExecuteInternal(InMemoryRavenConfiguration config) { var licensePath = GetLicensePath(config); var licenseText = GetLicenseText(config); if (TryLoadLicense(licenseText) == false) { return; } try { licenseValidator.AssertValidLicense(() => { string value; LicenseAttributes = licenseValidator.LicenseAttributes; AssertForV2(licenseValidator.LicenseAttributes); if (licenseValidator.LicenseAttributes.TryGetValue("OEM", out value) && "true".Equals(value, StringComparison.InvariantCultureIgnoreCase)) { licenseValidator.MultipleLicenseUsageBehavior = AbstractLicenseValidator.MultipleLicenseUsage.AllowSameLicense; } }); CurrentLicense = new LicensingStatus { Status = "Commercial - " + licenseValidator.LicenseType, Error = false, Message = "Valid license at " + licensePath }; } catch (Exception e) { logger.ErrorException("Could not validate license at " + licensePath + ", " + licenseText, e); CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = true, Message = "Could not validate license: " + licensePath + ", " + licenseText + Environment.NewLine + e }; } }
private void TestTimeoutCallback(object state) { licensingStatus = GetLicensingStatus(); DeactivateTimer(); try { Abstractions.Util.AsyncHelpers.RunSync(() => ChangeHotSpareModeWithinCluster(true)); } catch { //the reason we fail here is only because we are running within a cluster and could not get the leader to approve our voting state licensingTimer = landlord.SystemDatabase.TimerManager.NewTimer(TestTimeoutCallback, TimeSpan.FromMinutes(1), NonRecurringTimeSpan); return; } requestManger.IsInHotSpareMode = true; CheckHotSpareLicenseStats(); }
private void ExecuteInternal(InMemoryRavenConfiguration config) { var licensePath = GetLicensePath(config); var licenseText = GetLicenseText(config); if (TryLoadLicense(licenseText) == false) return; try { licenseValidator.AssertValidLicense(() => { string value; LicenseAttributes = licenseValidator.LicenseAttributes; AssertForV2(licenseValidator.LicenseAttributes); if (licenseValidator.LicenseAttributes.TryGetValue("OEM", out value) && "true".Equals(value, StringComparison.InvariantCultureIgnoreCase)) { licenseValidator.MultipleLicenseUsageBehavior = AbstractLicenseValidator.MultipleLicenseUsage.AllowSameLicense; } }); CurrentLicense = new LicensingStatus { Status = "Commercial - " + licenseValidator.LicenseType, Error = false, Message = "Valid license at " + licensePath }; } catch (Exception e) { logger.ErrorException("Could not validate license at " + licensePath + ", " + licenseText, e); CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = true, Message = "Could not validate license: " + licensePath + ", " + licenseText + Environment.NewLine + e }; } }
private void ActivationTimeoutCallback(object state) { var newLicense = GetLicensingStatus(); DeactivateTimer(); if (LicenseEqual(newLicense, licensingStatus)) { try { Abstractions.Util.AsyncHelpers.RunSync(() => ChangeHotSpareModeWithinCluster(true)); } catch { //the reason we fail here is only because we are running within a cluster and could not get the leader to approve our voting state licensingTimer = landlord.SystemDatabase.TimerManager.NewTimer(ActivationTimeoutCallback, TimeSpan.FromMinutes(1), NonRecurringTimeSpan); return; } requestManger.IsInHotSpareMode = true; ReportUsageOfExpiredHotSpareLicense(ReportHotSpareUsage.ActivationMode.ExpiredActivation, licensingStatus.Attributes["UserId"]); return; } licensingStatus = newLicense; CheckHotSpareLicenseStats(); }
private bool TryLoadLicense(string licenseText) { string publicKey; using ( var stream = typeof(ValidateLicense).Assembly.GetManifestResourceStream("Raven.Database.Commercial.RavenDB.public")) { if (stream == null) { throw new InvalidOperationException("Could not find public key for the license"); } publicKey = new StreamReader(stream).ReadToEnd(); } licenseValidator = new StringLicenseValidator(publicKey, licenseText) { DisableFloatingLicenses = true, SubscriptionEndpoint = "http://uberprof.com/Subscriptions.svc" }; licenseValidator.LicenseInvalidated += OnLicenseInvalidated; licenseValidator.MultipleLicensesWereDiscovered += OnMultipleLicensesWereDiscovered; if (string.IsNullOrEmpty(licenseText)) { CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = false, Message = "No license file was found at " + licenseText + "\r\nThe AGPL license restrictions apply, only Open Source / Development work is permitted." }; return(false); } return(true); }
private void ExecuteInternal(InMemoryRavenConfiguration config) { var licensePath = GetLicensePath(config); var licenseText = GetLicenseText(config); if (TryLoadLicense(config) == false) return; try { licenseValidator.AssertValidLicense(() => { string value; AssertForV2(licenseValidator.LicenseAttributes); if (licenseValidator.LicenseAttributes.TryGetValue("OEM", out value) && "true".Equals(value, StringComparison.OrdinalIgnoreCase)) { licenseValidator.MultipleLicenseUsageBehavior = AbstractLicenseValidator.MultipleLicenseUsage.AllowSameLicense; } string allowExternalBundles; if (licenseValidator.LicenseAttributes.TryGetValue("allowExternalBundles", out allowExternalBundles) && bool.Parse(allowExternalBundles) == false) { var directoryCatalogs = config.Catalog.Catalogs.OfType<DirectoryCatalog>().ToArray(); foreach (var catalog in directoryCatalogs) { config.Catalog.Catalogs.Remove(catalog); } } }); var attributes = new Dictionary<string, string>(alwaysOnAttributes, StringComparer.OrdinalIgnoreCase); foreach (var licenseAttribute in licenseValidator.LicenseAttributes) { attributes[licenseAttribute.Key] = licenseAttribute.Value; } var message = "Valid license at " + licensePath; var status = "Commercial"; if (licenseValidator.LicenseType != LicenseType.Standard) status += " - " + licenseValidator.LicenseType; if (licenseValidator.IsOemLicense() && licenseValidator.ExpirationDate < SystemTime.UtcNow) { message = string.Format("Expired ({0}) OEM/ISV license at {1}", licenseValidator.ExpirationDate.ToShortDateString(), licensePath); status += " (Expired)"; } CurrentLicense = new LicensingStatus { Status = status, Error = false, Message = message, Attributes = attributes }; } catch (Exception e) { logger.ErrorException("Could not validate license at " + licensePath + ", " + licenseText, e); try { var xmlDocument = new XmlDocument(); xmlDocument.Load(licensePath); var ns = new XmlNamespaceManager(xmlDocument.NameTable); ns.AddNamespace("sig", "http://www.w3.org/2000/09/xmldsig#"); var sig = xmlDocument.SelectSingleNode("/license/sig:Signature", ns); if (sig != null) { sig.RemoveAll(); } licenseText = xmlDocument.InnerXml; } catch (Exception) { // couldn't remove the signature, maybe not XML? } CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = true, Message = "Could not validate license: " + licensePath + ", " + licenseText + Environment.NewLine + e, Attributes = new Dictionary<string, string>(alwaysOnAttributes, StringComparer.OrdinalIgnoreCase) }; } }
private bool TryLoadLicense(InMemoryRavenConfiguration config) { string publicKey; using ( var stream = typeof(ValidateLicense).Assembly.GetManifestResourceStream("Raven.Database.Commercial.RavenDB.public")) { if (stream == null) throw new InvalidOperationException("Could not find public key for the license"); publicKey = new StreamReader(stream).ReadToEnd(); } config.Container.SatisfyImportsOnce(this); var value = config.Settings["Raven/License"]; if (LicenseProvider != null && !string.IsNullOrEmpty(LicenseProvider.License)) { value = LicenseProvider.License; } var fullPath = GetLicensePath(config).ToFullPath(); if (string.IsNullOrEmpty(value) == false) { licenseValidator = new StringLicenseValidator(publicKey, value); } else if (File.Exists(fullPath)) { licenseValidator = new LicenseValidator(publicKey, fullPath); } else { CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = false, Message = "No license file was found at " + fullPath + "\r\nThe AGPL license restrictions apply, only Open Source / Development work is permitted." }; return false; } licenseValidator.DisableFloatingLicenses = true; licenseValidator.SubscriptionEndpoint = "http://uberprof.com/Subscriptions.svc"; licenseValidator.LicenseInvalidated += OnLicenseInvalidated; licenseValidator.MultipleLicensesWereDiscovered += OnMultipleLicensesWereDiscovered; return true; }
private void ExecuteInternal(InMemoryRavenConfiguration config, bool firstTime = false, bool forceUpdate = false) { var licensePath = GetLicensePath(config); var licenseText = GetLicenseText(config); if (TryLoadLicense(config) == false) { return; } string errorMessage = string.Empty; try { try { licenseValidator.AssertValidLicense(() => { string value; errorMessage = AssertLicenseAttributes(licenseValidator.LicenseAttributes, licenseValidator.LicenseType); if (licenseValidator.LicenseAttributes.TryGetValue("OEM", out value) && "true".Equals(value, StringComparison.OrdinalIgnoreCase)) { licenseValidator.MultipleLicenseUsageBehavior = AbstractLicenseValidator.MultipleLicenseUsage.AllowSameLicense; } string allowExternalBundles; if (licenseValidator.LicenseAttributes.TryGetValue("allowExternalBundles", out allowExternalBundles) && bool.Parse(allowExternalBundles) == false) { var directoryCatalogs = config.Catalog.Catalogs.OfType <DirectoryCatalog>().ToArray(); foreach (var catalog in directoryCatalogs) { config.Catalog.Catalogs.Remove(catalog); } } }, config.TurnOffDiscoveryClient, firstTime, forceUpdate); } catch (LicenseExpiredException ex) { errorMessage = ex.Message; } var attributes = new Dictionary <string, string>(alwaysOnAttributes, StringComparer.OrdinalIgnoreCase); foreach (var licenseAttribute in licenseValidator.LicenseAttributes) { attributes[licenseAttribute.Key] = licenseAttribute.Value; } var message = "Valid license at " + licensePath; var status = "Commercial"; if (licenseValidator.LicenseType != LicenseType.Standard) { status += " - " + licenseValidator.LicenseType; } if (licenseValidator.IsOemLicense() && licenseValidator.ExpirationDate < SystemTime.UtcNow) { message = string.Format("Expired ({0}) OEM/ISV license at {1}", licenseValidator.ExpirationDate.ToShortDateString(), licensePath); status += " (Expired)"; } CurrentLicense = new LicensingStatus { Status = status, Error = !String.IsNullOrEmpty(errorMessage), Message = String.IsNullOrEmpty(errorMessage) ? message : errorMessage, Attributes = attributes }; } catch (Exception e) { logger.ErrorException("Could not validate license at " + licensePath + ", " + licenseText, e); try { var xmlDocument = new XmlDocument(); xmlDocument.Load(licensePath); var ns = new XmlNamespaceManager(xmlDocument.NameTable); ns.AddNamespace("sig", "http://www.w3.org/2000/09/xmldsig#"); var sig = xmlDocument.SelectSingleNode("/license/sig:Signature", ns); if (sig != null) { sig.RemoveAll(); } licenseText = xmlDocument.InnerXml; } catch (Exception) { // couldn't remove the signature, maybe not XML? } CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = true, Details = "License Path: " + licensePath + Environment.NewLine + ", License Text: " + licenseText + Environment.NewLine + ", Exception: " + e, Message = "Could not validate license: " + e.Message, Attributes = new Dictionary <string, string>(alwaysOnAttributes, StringComparer.OrdinalIgnoreCase) }; } }
public void Execute(DocumentDatabase database) { if (alreadyRun) return; alreadyRun = true; string publicKey; using(var stream = typeof(ValidateLicense).Assembly.GetManifestResourceStream("Raven.Database.Commercial.RavenDB.public")) { if(stream == null) throw new InvalidOperationException("Could not find public key for the license"); publicKey = new StreamReader(stream).ReadToEnd(); } var licensePath = GetLicensePath(database); var licenseText = GetLicenseText(database); licenseValidator = new StringLicenseValidator(publicKey, licenseText) { DisableFloatingLicenses = true, }; licenseValidator.LicenseInvalidated+=LicenseValidatorOnLicenseInvalidated; licenseValidator.MultipleLicensesWereDiscovered += LicenseValidatorOnMultipleLicensesWereDiscovered; if (string.IsNullOrEmpty(licenseText)) { CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = false, Message = "No license file was found at " + licenseText + "\r\nThe AGPL license restrictions apply, only Open Source / Development work is permitted." }; return; } try { licenseValidator.AssertValidLicense(()=> { string value; if (licenseValidator.LicenseAttributes.TryGetValue("OEM", out value) && "true".Equals(value, StringComparison.InvariantCultureIgnoreCase)) { licenseValidator.MultipleLicenseUsageBehavior = AbstractLicenseValidator.MultipleLicenseUsage.AllowSameLicense; } }); CurrentLicense = new LicensingStatus { Status = "Commercial - " + licenseValidator.LicenseType, Error = false, Message = "Valid license at " + licensePath }; } catch (Exception e) { logger.ErrorException("Could not validate license at " + licensePath + ", " + licenseText, e); CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = true, Message = "Could not validate license: " + licensePath + ", " + licenseText + Environment.NewLine + e }; } }
public void Execute(DocumentDatabase database) { string publicKey; using (var stream = typeof(ValidateLicense).Assembly.GetManifestResourceStream("Raven.Database.Commercial.RavenDB.public")) { if (stream == null) { throw new InvalidOperationException("Could not find public key for the license"); } publicKey = new StreamReader(stream).ReadToEnd(); } var licensePath = GetLicensePath(database); var licenseText = GetLicenseText(database); licenseValidator = new StringLicenseValidator(publicKey, licenseText) { DisableFloatingLicenses = true, }; licenseValidator.LicenseInvalidated += LicenseValidatorOnLicenseInvalidated; licenseValidator.MultipleLicensesWereDiscovered += LicenseValidatorOnMultipleLicensesWereDiscovered; if (string.IsNullOrEmpty(licenseText)) { CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = false, Message = "No license file was found at " + licenseText + "\r\nThe AGPL license restrictions apply, only Open Source / Development work is permitted." }; return; } try { licenseValidator.AssertValidLicense(() => { string value; if (licenseValidator.LicenseAttributes.TryGetValue("OEM", out value) && "true".Equals(value, StringComparison.InvariantCultureIgnoreCase)) { licenseValidator.MultipleLicenseUsageBehavior = AbstractLicenseValidator.MultipleLicenseUsage.AllowSameLicense; } }); CurrentLicense = new LicensingStatus { Status = "Commercial - " + licenseValidator.LicenseType, Error = false, Message = "Valid license at " + licensePath }; } catch (Exception e) { logger.ErrorException("Could not validate license at " + licensePath + ", " + licenseText, e); CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = true, Message = "Could not validate license: " + licensePath + ", " + licenseText + Environment.NewLine + e }; } }
private void ExecuteInternal(InMemoryRavenConfiguration config) { var licensePath = GetLicensePath(config); var licenseText = GetLicenseText(config); if (TryLoadLicense(licenseText) == false) { return; } try { licenseValidator.AssertValidLicense(() => { string value; AssertForV2(licenseValidator.LicenseAttributes); if (licenseValidator.LicenseAttributes.TryGetValue("OEM", out value) && "true".Equals(value, StringComparison.OrdinalIgnoreCase)) { licenseValidator.MultipleLicenseUsageBehavior = AbstractLicenseValidator.MultipleLicenseUsage.AllowSameLicense; } string allowExternalBundles; if (licenseValidator.LicenseAttributes.TryGetValue("allowExternalBundles", out allowExternalBundles) && bool.Parse(allowExternalBundles) == false) { var directoryCatalogs = config.Catalog.Catalogs.OfType <DirectoryCatalog>().ToArray(); foreach (var catalog in directoryCatalogs) { config.Catalog.Catalogs.Remove(catalog); } } }); var attributes = new Dictionary <string, string>(alwaysOnAttributes, StringComparer.OrdinalIgnoreCase); foreach (var licenseAttribute in licenseValidator.LicenseAttributes) { attributes[licenseAttribute.Key] = licenseAttribute.Value; } CurrentLicense = new LicensingStatus { Status = "Commercial - " + licenseValidator.LicenseType, Error = false, Message = "Valid license at " + licensePath, Attributes = attributes }; } catch (Exception e) { logger.ErrorException("Could not validate license at " + licensePath + ", " + licenseText, e); try { var xmlDocument = new XmlDocument(); xmlDocument.LoadXml(licensePath); var sig = xmlDocument.SelectSingleNode("/license/Signature"); if (sig != null && sig.ParentNode != null) { sig.ParentNode.RemoveChild(sig); } var stringBuilder = new StringBuilder(); xmlDocument.WriteTo(XmlWriter.Create(stringBuilder)); licenseText = stringBuilder.ToString(); } catch (Exception) { // couldn't remove the signature, maybe not XML? } CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = true, Message = "Could not validate license: " + licensePath + ", " + licenseText + Environment.NewLine + e, Attributes = new Dictionary <string, string>(alwaysOnAttributes, StringComparer.OrdinalIgnoreCase) }; } }
private bool TryLoadLicense(InMemoryRavenConfiguration config) { string publicKey; using ( var stream = typeof(ValidateLicense).Assembly.GetManifestResourceStream("Raven.Database.Commercial.RavenDB.public")) { if (stream == null) throw new InvalidOperationException("Could not find public key for the license"); publicKey = new StreamReader(stream).ReadToEnd(); } var value = GetLicenseText(config); var fullPath = GetLicensePath(config).ToFullPath(); if (IsSameLicense(value, fullPath)) return licenseValidator != null; if (licenseValidator != null) licenseValidator.Dispose(); if (File.Exists(fullPath)) { if (logger.IsDebugEnabled) logger.Debug("Creating new license validator for file: {0}", fullPath); licenseValidator = new LicenseValidator(publicKey, fullPath); } else if (string.IsNullOrEmpty(value) == false) { if(logger.IsDebugEnabled) logger.Debug("Creating new license validator for string: {0}", value.Substring(0, Math.Min(100, value.Length))); licenseValidator = new StringLicenseValidator(publicKey, value); } else { CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = false, Message = "No license file was found at " + fullPath + "\r\nThe AGPL license restrictions apply, only Open Source / Development work is permitted." }; return false; } licenseValidator.DisableFloatingLicenses = true; licenseValidator.SubscriptionEndpoint = "http://licensing.ravendb.net/Subscriptions.svc"; licenseValidator.LicenseInvalidated += OnLicenseInvalidated; licenseValidator.MultipleLicensesWereDiscovered += OnMultipleLicensesWereDiscovered; return true; }
private void ExecuteInternal(InMemoryRavenConfiguration config) { var licensePath = GetLicensePath(config); var licenseText = GetLicenseText(config); if (TryLoadLicense(licenseText) == false) return; try { licenseValidator.AssertValidLicense(() => { string value; AssertForV2(licenseValidator.LicenseAttributes); if (licenseValidator.LicenseAttributes.TryGetValue("OEM", out value) && "true".Equals(value, StringComparison.OrdinalIgnoreCase)) { licenseValidator.MultipleLicenseUsageBehavior = AbstractLicenseValidator.MultipleLicenseUsage.AllowSameLicense; } string allowExternalBundles; if(licenseValidator.LicenseAttributes.TryGetValue("allowExternalBundles", out allowExternalBundles) && bool.Parse(allowExternalBundles) == false) { var directoryCatalogs = config.Catalog.Catalogs.OfType<DirectoryCatalog>().ToArray(); foreach (var catalog in directoryCatalogs) { config.Catalog.Catalogs.Remove(catalog); } } }); var attributes = new Dictionary<string, string>(alwaysOnAttributes, StringComparer.OrdinalIgnoreCase); foreach (var licenseAttribute in licenseValidator.LicenseAttributes) { attributes[licenseAttribute.Key] = licenseAttribute.Value; } CurrentLicense = new LicensingStatus { Status = "Commercial - " + licenseValidator.LicenseType, Error = false, Message = "Valid license at " + licensePath, Attributes = attributes }; } catch (Exception e) { logger.ErrorException("Could not validate license at " + licensePath + ", " + licenseText, e); try { var xmlDocument = new XmlDocument(); xmlDocument.LoadXml(licensePath); var sig = xmlDocument.SelectSingleNode("/license/Signature"); if (sig != null && sig.ParentNode != null) sig.ParentNode.RemoveChild(sig); var stringBuilder = new StringBuilder(); xmlDocument.WriteTo(XmlWriter.Create(stringBuilder)); licenseText = stringBuilder.ToString(); } catch (Exception) { // couldn't remove the signature, maybe not XML? } CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = true, Message = "Could not validate license: " + licensePath + ", " + licenseText + Environment.NewLine + e, Attributes = new Dictionary<string, string>(alwaysOnAttributes, StringComparer.OrdinalIgnoreCase) }; } }
private bool TryLoadLicense(string licenseText) { string publicKey; using ( var stream = typeof (ValidateLicense).Assembly.GetManifestResourceStream("Raven.Database.Commercial.RavenDB.public")) { if (stream == null) throw new InvalidOperationException("Could not find public key for the license"); publicKey = new StreamReader(stream).ReadToEnd(); } licenseValidator = new StringLicenseValidator(publicKey, licenseText) { DisableFloatingLicenses = true, SubscriptionEndpoint = "http://uberprof.com/Subscriptions.svc" }; licenseValidator.LicenseInvalidated += OnLicenseInvalidated; licenseValidator.MultipleLicensesWereDiscovered += OnMultipleLicensesWereDiscovered; if (string.IsNullOrEmpty(licenseText)) { CurrentLicense = new LicensingStatus { Status = "AGPL - Open Source", Error = false, Message = "No license file was found at " + licenseText + "\r\nThe AGPL license restrictions apply, only Open Source / Development work is permitted." }; return false; } return true; }