/// <summary>Initializes a new instance of the <see cref="LicenseException" /> class with a specified <see cref="LicenseError" />.</summary> /// <param name="error">The specified <see cref="LicenseError"/>.</param> public LicenseException(LicenseError error) : base(error.ExceptionMessage) { if (error == null) { throw new ArgumentNullException("error"); } _error = error; }
public static string FormatLicenseError(LicenseError licenseError) { Debug.Assert(licenseError != null); return(string.Format( CultureInfo.CurrentUICulture, SR.Message_LicenseError, AssemblyLicense.GetAssemblyName(licenseError.Assembly), licenseError.Reason, licenseError.Message, licenseError.License == null ? string.Empty : licenseError.License.SignedString)); }
protected override LicenseError Validate() { if (_verified) { if (CurrentUserData != Data) { _error = new LicenseError(Assembly, LicenseErrorReason.InvalidLicense, Messages.InvalidUserData, this); } _verified = true; } return(_error); }
protected sealed override LicenseError Validate() { if (_verified) { Byte[] encryptedBytes = LicenseManager.BytesFromString(Data); Byte[] bytes = ProtectedData.Unprotect(encryptedBytes, null, DataProtectionScope.LocalMachine); if (new Guid(bytes) != Guid) { _error = new LicenseError(Assembly, LicenseErrorReason.InvalidLicense, Messages.InvalidMachineData, this); } _verified = true; } return(_error); }
protected override LicenseError Validate() { if (!_verified) { Assembly assembly = ProviderData as Assembly; Debug.Assert(assembly != null); string data = GetAssemblyData(assembly); if (string.IsNullOrEmpty(Data) || data != Data) { _error = new LicenseError(Assembly, LicenseErrorReason.InvalidLicense, Messages.InvalidAssemblyData, this); } _verified = true; } return(_error); }
internal LicenseError Validate(string licenseItemName) { if (!IsFrozen) { throw new InvalidOperationException(ExceptionMessages.LicenseMustBeFrozenBeforeValidate); } LicenseItem licenseItem = this[licenseItemName]; if (licenseItem == null) { return(new LicenseError(Assembly, LicenseErrorReason.InvalidLicense, Messages.FormatNoMatchingLicenseItem(licenseItemName), this)); } LicenseError error = ValidateProduct(); if (error != null) { return(error); } // Check ExpirationDate if (IsExpired && !licenseItem.OverrideExpirationDate) { return(new LicenseError(Assembly, LicenseErrorReason.ExpiredLicense, Messages.FormatExpiredLicense(ExpirationDate), this)); } // Check UpgradeExpirationDate DateTime releaseDate = AssemblyInfo.GetReleaseDate(Assembly); if (releaseDate > UpgradeExpirationDate) { return(new LicenseError(Assembly, LicenseErrorReason.InvalidLicense, Messages.FormatUpgradeExpired(UpgradeExpirationDate, releaseDate), this)); } error = Validate(); if (error != null) { return(error); } return(licenseItem.Validate()); }
/// <summary>Initializes a new instance of the <see cref="LicenseException"/> class with serialized data.</summary> /// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param> /// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param> private LicenseException(SerializationInfo info, StreamingContext context) : base(info, context) { _error = (LicenseError)info.GetValue("Error", typeof(LicenseError)); }
private static LicenseError Validate(string licenseItemName, Assembly assembly, bool designMode, bool throwsException) { if (assembly == null) { throw new ArgumentNullException("assembly"); } if (string.IsNullOrEmpty(licenseItemName)) { throw new ArgumentNullException("licenseItemName"); } LicenseError error = null; License license = GetLicense(assembly, designMode); if (license != null) { error = license.Validate(licenseItemName); } if (license == null || error != null) { string publicKeyToken = AssemblyLicense.GetAssemblyPublicKeyToken(assembly); // check the calling assembly's public key token Assembly entryAssembly = Assembly.GetEntryAssembly(); if (entryAssembly != null && entryAssembly != assembly) { if (AssemblyLicense.GetAssemblyPublicKeyToken(entryAssembly) == publicKeyToken) // Entry assembly signed by the same key { if (IsTraceEnabled) { WriteTrace(assembly, Messages.FormatAssemblySignedWithSameKey(entryAssembly)); } return(null); } } // check the calling assembly's public key token Assembly currentAssembly = Assembly.GetExecutingAssembly(); StackTrace stackTrace = new StackTrace(); for (int i = 1; i < stackTrace.FrameCount; i++) { StackFrame stackFrame = stackTrace.GetFrame(i); Type reflectedType = stackFrame.GetMethod().ReflectedType; if (reflectedType == null) { continue; } Assembly reflectedAssembly = reflectedType.Assembly; if (reflectedAssembly == assembly || reflectedAssembly == currentAssembly) { continue; } if (AssemblyLicense.GetAssemblyPublicKeyToken(reflectedAssembly) == publicKeyToken) // Calling assembly signed by the same key { if (IsTraceEnabled) { WriteTrace(assembly, Messages.FormatAssemblySignedWithSameKey(reflectedAssembly)); } return(null); } } } if (license == null) { error = new LicenseError(assembly, LicenseErrorReason.NullLicense, Messages.NullLicense, null); } if (error != null && throwsException) { throw new LicenseException(error); } return(error); }