Beispiel #1
0
        /// <summary>
        /// Main method for validating a signature
        /// </summary>
        /// <param name="signature"></param>
        /// <param name="referenceTime"></param>
        /// <returns>
        /// the report part pertaining to the signature
        /// </returns>
        protected internal virtual SignatureInformation ValidateSignature(IAdvancedSignature signature, DateTime referenceTime, ICAdESLogger logger, SignatureValidationContext signatureValidationContext, bool checkIntegrity, Document externalContent)
        {
            if (signature is null)
            {
                throw new ArgumentNullException(nameof(signature));
            }

            if (signature.SigningCertificate == null)
            {
                logger.Error("There is no signing certificate");
                return(null);
            }



            var signatureVerification               = new SignatureVerification(new SignatureValidationResult(checkIntegrity ? signature.CheckIntegrity(externalContent) : true), signature.SignatureAlgorithm);
            IValidationContext            ctx       = signatureValidationContext.GetExisted(signature.SigningCertificate, referenceTime);
            IList <CertificateAndContext> usedCerts = new List <CertificateAndContext>();

            if (ctx == null)
            {
                ctx = CertificateVerifier.ValidateCertificate(signature.SigningCertificate, referenceTime, signature.CertificateSource, usedCerts, signature.CRLSource, signature.OCSPSource, logger);
                signatureValidationContext.Contexts.Add(ctx);
            }

            var qcStatementInformation     = VerifyQStatement(signature.SigningCertificate);
            var qualificationsVerification = VerifyQualificationsElement(signature, referenceTime, ctx);

            // TODO: serviceinfo is never set, so invalid everytime - hack added  - ?? new ServiceInfo()
            var info = new TrustedListInformation(ctx.GetRelevantServiceInfo() ?? new ServiceInfo());
            var path = new CertPathRevocationAnalysis(ctx, info);


            var signatureLevelXL = VerifyLevelXL(signature, referenceTime, ctx, logger);
            // order matters
            var signatureLevelC        = VerifyLevelC(signature, referenceTime, ctx, signatureLevelXL?.LevelReached.IsValid ?? false, logger);
            var signatureLevelAnalysis = new SignatureLevelAnalysis(
                signature,
                VerifyLevelBES(signature, referenceTime, ctx, externalContent),
                VerifyLevelEPES(signature, referenceTime, ctx),
                VerifyLevelT(signature, referenceTime, ctx),
                signatureLevelC,
                VerifyLevelX(signature, referenceTime, ctx),
                signatureLevelXL,
                VerifyLevelA(signature, referenceTime, ctx, logger, externalContent));


            var signatureInformation = new SignatureInformation(signatureVerification, path, signatureLevelAnalysis, qualificationsVerification, qcStatementInformation, ctx.NeededCertificates.Select(cert => new CertificateVerification(cert, ctx)), ctx);

            return(signatureInformation);
        }
Beispiel #2
0
 public CertPathRevocationAnalysis(IValidationContext ctx, TrustedListInformation info)
 {
     summary = new SignatureValidationResult();
     trustedListInformation = info;
     if (ctx != null && ctx.NeededCertificates != null)
     {
         foreach (CertificateAndContext cert in ctx.NeededCertificates)
         {
             CertificateVerification verif = new CertificateVerification(cert, ctx);
             certificatePathVerification.Add(verif);
         }
     }
     summary.SetStatus(ResultStatus.VALID, null);
     if (certificatePathVerification != null)
     {
         foreach (CertificateVerification verif in certificatePathVerification)
         {
             if (verif.Summary.IsInvalid)
             {
                 summary.SetStatus(ResultStatus.INVALID, verif.Summary.Description ?? "$UI_Signatures_ValidationText_CertificateIsNotValid");
                 break;
             }
             if (verif.Summary.IsUndetermined)
             {
                 summary.SetStatus(ResultStatus.UNDETERMINED, verif.Summary.Description ?? "$UI_Signatures_ValidationText_NoRevocationData");
             }
         }
     }
     if (trustedListInformation != null)
     {
         if (!trustedListInformation.IsServiceWasFound)
         {
             summary.SetStatus(ResultStatus.INVALID, "$UI_Signatures_ValidationText_NoTrustedListServiceWasFound");
         }
     }
     else
     {
         summary.SetStatus(ResultStatus.INVALID, "$UI_Signatures_ValidationText_NoTrustedListServiceWasFound");
     }
 }
Beispiel #3
0
 /// <param>
 /// the trustedListInformation to set
 /// </param>
 public virtual void SetTrustedListInformation(TrustedListInformation trustedListInformation)
 {
     this.trustedListInformation = trustedListInformation;
 }