internal LicenseManagerSingleton(IReadOnlyCollection <RSADecryptPublic> trustedKeys, ILicenseClock clock, IPersistentStringCache cache) { TrustedKeys = trustedKeys; Clock = clock; SetHttpMessageHandler(null, true); Cache = cache; }
public ImperfectDebounce(Action callback, long intervalSeconds, ILicenseClock clock) { this.callback = callback; this.clock = clock; IntervalTicks = clock.TicksPerSecond * intervalSeconds; lastBegun = -IntervalTicks; }
public LicenseFetcher(ILicenseClock clock, Func <HttpClient> getClient, Action <string, IReadOnlyCollection <FetchResult> > licenseResult, Func <IInfoAccumulator> getInfo, IIssueReceiver sink, string licenseId, string licenseSecret, string[] baseUrls, long?licenseFetchIntervalSeconds) { this.clock = clock; LicenseFetchIntervalSeconds = licenseFetchIntervalSeconds ?? LicenseFetchIntervalSeconds; regular = new ImperfectDebounce(() => QueueLicenseFetch(false), LicenseFetchIntervalSeconds, clock); error = new ImperfectDebounce(() => QueueLicenseFetch(true), 0, clock); this.getClient = getClient; this.getInfo = getInfo; this.licenseResult = licenseResult; this.baseUrls = baseUrls; id = licenseId; secret = licenseSecret; this.sink = sink; }
public MockConfig(LicenseManagerSingleton mgr, ILicenseClock clock, string[] codes, IEnumerable <KeyValuePair <string, string> > domainMappings) { this.codes = codes; this.mgr = mgr; Clock = clock ?? Clock; mgr.MonitorLicenses(this); mgr.MonitorHeartbeat(this); // Ensure our cache is appropriately invalidated cache = null; mgr.AddLicenseChangeHandler(this, (me, manager) => me.cache = null); // And repopulated, so that errors show up. if (Result == null) { throw new ApplicationException("Failed to populate license result"); } this.domainMappings = domainMappings; }
public LicensedPlugin(ILicenseManager mgr, ILicenseClock clock, params string[] codes) { this.codes = codes; this.mgr = mgr; Clock = clock ?? Clock; }
internal LicenseManagerSingleton(IReadOnlyCollection <RSADecryptPublic> trustedKeys, ILicenseClock clock) : this(trustedKeys, clock, new PersistentGlobalStringCache()) { }
internal LicenseEnforcer(ILicenseManager mgr, Func <Uri> getCurrentRequestUrl, ILicenseClock clock, IReadOnlyCollection <RSADecryptPublic> trusted) { this.mgr = mgr; this.Clock = clock; this.GetCurrentRequestUrl = getCurrentRequestUrl; trustedKeys = trusted; }
public Computation(Config c, IReadOnlyCollection <RSADecryptPublic> trustedKeys, IIssueReceiver permanentIssueSink, ILicenseManager mgr, ILicenseClock clock, bool enforcementEnabled) : base("Computation") { permanentIssues = permanentIssueSink; EnforcementEnabled = enforcementEnabled; this.clock = clock; Scope = c.Plugins.LicenseScope; LicenseError = c.Plugins.LicenseError; this.mgr = mgr; if (mgr.FirstHeartbeat == null) { throw new ArgumentException("ILicenseManager.Heartbeat() must be called before Computation.new"); } // What features are installed on this instance? // For a license to be OK, it must have one of each of this nested list; IEnumerable <IEnumerable <string> > pluginFeaturesUsed = c.Plugins.GetAll <ILicensedPlugin>().Select(p => p.LicenseFeatureCodes).ToList(); // Create or fetch all relevant license chains; ignore the empty/invalid ones, they're logged to the manager instance chains = c.Plugins.GetAll <ILicenseProvider>() .SelectMany(p => p.GetLicenses()) .Select(str => mgr.GetOrAdd(str, c.Plugins.LicenseScope)) .Where(x => x != null && x.Licenses().Any()) .Concat(Scope.HasFlag(LicenseAccess.ProcessReadonly) ? mgr.GetSharedLicenses() : Enumerable.Empty <ILicenseChain>()) .Distinct() .ToList(); // Set up our domain map/normalize/search manager domainLookup = new DomainLookup(c, permanentIssueSink, chains); // Check for tampering via interfaces if (chains.Any(chain => chain.Licenses().Any(b => !b.Revalidate(trustedKeys)))) { EverythingDenied = true; permanentIssueSink.AcceptIssue(new Issue( "Licenses failed to revalidate; please contact [email protected]", IssueSeverity.Error)); } // Look for grace periods var gracePeriods = chains.Where(IsPendingLicense).Select(GetGracePeriodFor).ToList(); // Look for fetched and valid licenses var validLicenses = chains.Where(chain => !IsPendingLicense(chain)) .SelectMany(chain => chain.Licenses()) .Where(b => !b.Fields.IsRemotePlaceholder() && IsLicenseValid(b)) .ToList(); // This computation expires when we cross an expires, issued date, or NetworkGracePeriod expiration ComputationExpires = chains.SelectMany(chain => chain.Licenses()) .SelectMany(b => new[] { b.Fields.Expires, b.Fields.Issued }) .Concat(gracePeriods) .Where(date => date != null) .OrderBy(d => d) .FirstOrDefault(d => d > clock.GetUtcNow()); AllDomainsLicensed = gracePeriods.Any(t => t != null) || validLicenses .Any(license => !license.Fields.GetAllDomains().Any() && AreFeaturesLicensed(license, pluginFeaturesUsed, false)); KnownDomainStatus = validLicenses.SelectMany( b => b.Fields.GetAllDomains() .SelectMany(domain => b.Fields.GetFeatures() .Select( feature => new KeyValuePair <string, string>( domain, feature)))) .GroupBy(pair => pair.Key, pair => pair.Value, (k, v) => new KeyValuePair <string, IEnumerable <string> >(k, v)) .Select(pair => new KeyValuePair <string, bool>(pair.Key, pluginFeaturesUsed.All( set => set.Intersect(pair.Value, StringComparer.OrdinalIgnoreCase) .Any()))) .ToDictionary(pair => pair.Key, pair => pair.Value, StringComparer.Ordinal); if (UpgradeNeeded()) { foreach (var b in validLicenses) { AreFeaturesLicensed(b, pluginFeaturesUsed, true); } } }