/// <summary> /// Redacts the value of the 'Secret' field /// </summary> /// <param name="b"></param> /// <returns></returns> public static string ToRedactedString(this ILicenseBlob b) { return(Join("\n", b.Fields.Pairs.Select( pair => "secret".Equals(pair.Key, StringComparison.OrdinalIgnoreCase) ? $"{pair.Key}: ****redacted****" : $"{pair.Key}: {pair.Value}"))); }
string[] GetLicenseServers(ILicenseBlob blob) { var oldStack = licenseServerStack ?? new string[0]; var newList = blob.Fields.GetValidLicenseServers().ToArray(); return(newList.Concat(oldStack.Except(newList)).Take(10).ToArray()); }
bool AreFeaturesLicensed(ILicenseBlob b, IEnumerable <IEnumerable <string> > oneFromEach, bool logIssues) { var licenseFeatures = b.Fields.GetFeatures(); var notCovered = oneFromEach.Where( set => !set.Intersect(licenseFeatures, StringComparer.OrdinalIgnoreCase).Any()); var success = !notCovered.Any(); if (!success && logIssues) { permanentIssues.AcceptIssue(new Issue( $"License {b.Fields.Id} needs to be upgraded; it does not cover in-use features {notCovered.SelectMany(v => v).Distinct().Delimited(", ")}", b.ToRedactedString(), IssueSeverity.Error)); } return(success); }
public static bool VerifySignature(this ILicenseBlob b, IEnumerable <RSADecryptPublic> trustedKeys, StringBuilder log) { return(trustedKeys.Any(p => { var signature = b.Signature(); var hash = new SHA512Managed().ComputeHash(b.Data()); var decrypted_bytes = p.DecryptPublic(signature); var valid = hash.SequenceEqual(decrypted_bytes); if (log != null) { log.AppendLine("Using public exponent " + p.Exponent.ToString() + " and modulus " + p.Modulus.ToString()); log.AppendLine("Encrypted bytes: " + BitConverter.ToString(signature).ToLower().Replace("-", "")); log.AppendLine("Decrypted sha512: " + BitConverter.ToString(decrypted_bytes).ToLower().Replace("-", "")); log.AppendLine("Expected sha512: " + BitConverter.ToString(hash).ToLower().Replace("-", "")); log.AppendLine(valid ? "Success!" : "Not a match."); } return valid; })); }
/// <summary> /// Returns false if the blob is null, /// if there were no license servers in the blob, /// or if the servers were identical to what we already have. /// </summary> /// <param name="blob"></param> /// <returns></returns> bool TryUpdateLicenseServersInfo(ILicenseBlob blob) { if (blob == null) { return(false); } var interval = blob.Fields.CheckLicenseIntervalMinutes(); var intervalChanged = interval != null && interval != licenseIntervalMinutes; var oldStack = licenseServerStack ?? new string[0]; var newStack = GetLicenseServers(blob); var stackChanged = !newStack.SequenceEqual(oldStack); if (stackChanged) { licenseServerStack = newStack; } if (intervalChanged) { licenseIntervalMinutes = interval.Value; } return(stackChanged || intervalChanged); }
bool IsLicenseValid(ILicenseBlob b) { var details = b.Fields; if (IsLicenseExpired(details)) { permanentIssues.AcceptIssue(new Issue("License " + details.Id + " has expired.", b.ToRedactedString(), IssueSeverity.Error)); return(false); } if (!HasLicenseBegun(details)) { permanentIssues.AcceptIssue(new Issue( "License " + details.Id + " was issued in the future; check system clock.", b.ToRedactedString(), IssueSeverity.Error)); return(false); } if (IsBuildDateNewer(details.SubscriptionExpirationDate)) { permanentIssues.AcceptIssue(new Issue( $"License {details.Id} covers ImageResizer versions prior to {details.SubscriptionExpirationDate?.ToString("D")}, but you are using a build dated {GetBuildDate()?.ToString("D")}", b.ToRedactedString(), IssueSeverity.Error)); return(false); } if (details.IsRevoked()) { var message = b.Fields.GetMessage(); permanentIssues.AcceptIssue(new Issue($"License {details.Id}" + (message != null ? $": {message}" : " is no longer valid"), b.ToRedactedString(), IssueSeverity.Error)); return(false); } return(true); }
public static bool Revalidate(this ILicenseBlob b, IEnumerable <RSADecryptPublic> trustedKeys) { var ourCopy = LicenseBlob.Deserialize(b.Original); return(ourCopy.VerifySignature(trustedKeys, null) && ourCopy.Fields.DataMatches(b.Fields)); }
/// <summary> /// Redacts the value of the 'Secret' field /// </summary> /// <param name="b"></param> /// <returns></returns> public static string ToRedactedString(this ILicenseBlob b) { return(string.Join("\n", b.Fields().Pairs().Select(pair => "secret".Equals(pair.Key, StringComparison.OrdinalIgnoreCase) ? string.Format("{0}: ****redacted****", pair.Key) : string.Format("{0}: {1}", pair.Key, pair.Value)))); }