コード例 #1
0
ファイル: Signature.cs プロジェクト: dbrgn/pi-vote
        /// <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;
              }
        }
コード例 #2
0
ファイル: Signature.cs プロジェクト: dbrgn/pi-vote
        /// <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;
              }
        }
コード例 #3
0
ファイル: Signature.cs プロジェクト: dbrgn/pi-vote
        /// <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;
              }
        }