/// <summary> /// Determines until when the signature will be valid if ever. /// The date may lay in the past if it is not valid any more. /// </summary> /// <param name="objectData">Data to check against.</param> /// <param name="certificateStorage">Storage of certificates.</param> /// <param name="date">Date at which the signers certificate must be valid.</param> /// <returns>Date after which the signature expires.</returns> public DateTime ExpectedValidUntil(byte[] objectData, ICertificateStorage certificateStorage, DateTime date) { if (certificateStorage.Has(SignerId)) { Certificate signer = certificateStorage.Get(SignerId); if (signer.VerifySimple(AssmblySigningData(objectData), Data)) { if (signer.Validate(certificateStorage, date) == CertificateValidationResult.Valid) { return ValidUntil; } else { return DateTime.MinValue; } } else { return DateTime.MinValue; } } else { return DateTime.MinValue; } }
/// <summary> /// Verifies a signature. /// </summary> /// <remarks> /// Also check the validity of the signer's certificate. /// </remarks> /// <param name="objectData">Data to check against.</param> /// <param name="certificateStorage">Storage of certificates.</param> /// <param name="date">Date at which the signature must be valid.</param> /// <returns>Is the signature valid.</returns> public CertificateValidationResult Verify(byte[] objectData, ICertificateStorage certificateStorage, DateTime date) { if (ValidFrom.Date <= date.Date) { if (ValidUntil.Date >= date.Date) { if (certificateStorage.Has(SignerId)) { Certificate signer = certificateStorage.Get(SignerId); if (signer.VerifySimple(AssmblySigningData(objectData), Data)) { if (signer.Validate(certificateStorage, date) == CertificateValidationResult.Valid) { return CertificateValidationResult.Valid; } else { return CertificateValidationResult.SignerInvalid; } } else { return CertificateValidationResult.SignatureDataInvalid; } } else { return CertificateValidationResult.UnknownSigner; } } else { return CertificateValidationResult.Outdated; } } else { return CertificateValidationResult.NotYetValid; } }
/// <summary> /// Determines until when the signature will become valid. /// </summary> /// <param name="certificateStorage">Storage of certificates.</param> /// <param name="date">Date at which the signers certificate must be valid.</param> /// <returns>Date after which the signature expires.</returns> public DateTime ExpectedValidFrom(byte[] objectData, ICertificateStorage certificateStorage) { if (certificateStorage.Has(SignerId)) { Certificate signer = certificateStorage.Get(SignerId); if (signer.VerifySimple(AssmblySigningData(objectData), Data)) { return ValidFrom; } else { return DateTime.MaxValue; } } else { return DateTime.MaxValue; } }