Ejemplo n.º 1
0
        /// <summary>
        /// Is the certificate valid?
        /// </summary>
        /// <param name="certificateStorage">Storage of certificates.</param>
        /// <param name="date">Date on which it must be valid.</param>
        /// <returns>Is certificate valid.</returns>
        public CertificateValidationResult Validate(ICertificateStorage certificateStorage, DateTime date)
        {
            if (SelfSignatureValid)
              {
            if (certificateStorage.IsRootCertificate(this))
            {
              return CertificateValidationResult.Valid;
            }
            else
            {
              CertificateValidationResult result = CertificateValidationResult.NoSignature;

              foreach (Signature signature in this.signatures)
              {
            result = signature.Verify(GetSignatureContent(), certificateStorage, date);

            if (result == CertificateValidationResult.Valid)
            {
              return certificateStorage.IsRevoked(signature.SignerId, Id, date);
            }
              }

              return result;
            }
              }
              else
              {
            return CertificateValidationResult.SelfsignatureInvalid;
              }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Determines until when the certificate will stay valid, provided it isn't revoked until then.
 /// The date may lay in the past if the certificate is not valid now.
 /// </summary>
 /// <param name="certificateStorage">Storage of certificates.</param>
 /// <param name="date">Date on which signers certificates must be valid.</param>
 /// <returns>Date the certificate will expire after.</returns>
 public DateTime ExpectedValidUntil(ICertificateStorage certificateStorage, DateTime date)
 {
     if (SelfSignatureValid)
       {
     if (certificateStorage.IsRootCertificate(this))
     {
       return DateTime.MaxValue;
     }
     else if (this.signatures.Count < 1)
     {
       return DateTime.MinValue;
     }
     else
     {
       return this.signatures.Max(signature => signature.ExpectedValidUntil(GetSignatureContent(), certificateStorage, date));
     }
       }
       else
       {
     return DateTime.MinValue;
       }
 }