Ejemplo n.º 1
0
 protected internal virtual SignatureLevelC VerifyLevelC(AdvancedSignature signature
                                                         , DateTime referenceTime, ValidationContext ctx, bool rehashValues)
 {
     try
     {
         IList <CertificateRef> refs          = signature.GetCertificateRefs();
         Result everyNeededCertAreInSignature = new Result();
         if (refs == null || refs.IsEmpty())
         {
             everyNeededCertAreInSignature.SetStatus(Result.ResultStatus.INVALID, "no.certificate.ref"
                                                     );
         }
         else
         {
             if (EveryCertificateRefAreThere(ctx, refs, signature.GetSigningCertificate()))
             {
                 everyNeededCertAreInSignature.SetStatus(Result.ResultStatus.VALID, null);
             }
             else
             {
                 everyNeededCertAreInSignature.SetStatus(Result.ResultStatus.INVALID, "not.all.needed.certificate.ref"
                                                         );
             }
         }
         LOG.Info("Every CertificateRef found " + everyNeededCertAreInSignature);
         IList <OCSPRef> ocspRefs = signature.GetOCSPRefs();
         IList <CRLRef>  crlRefs  = signature.GetCRLRefs();
         int             refCount = 0;
         Result          everyNeededRevocationData = new Result(Result.ResultStatus.VALID, null);
         refCount += ocspRefs.Count;
         refCount += crlRefs.Count;
         Result thereIsRevocationData = null;
         Result levelCReached         = null;
         if (rehashValues)
         {
             if (!EveryOCSPValueOrRefAreThere(ctx, ocspRefs))
             {
                 everyNeededRevocationData.SetStatus(Result.ResultStatus.INVALID, "not.all.needed.ocsp.ref"
                                                     );
             }
             if (!EveryCRLValueOrRefAreThere(ctx, crlRefs))
             {
                 everyNeededRevocationData.SetStatus(Result.ResultStatus.INVALID, "not.all.needed.crl.ref"
                                                     );
             }
             levelCReached = new Result(everyNeededCertAreInSignature.GetStatus() == Result.ResultStatus
                                        .VALID && everyNeededRevocationData.GetStatus() == Result.ResultStatus.VALID);
             return(new SignatureLevelC(levelCReached, everyNeededCertAreInSignature, everyNeededRevocationData
                                        ));
         }
         else
         {
             thereIsRevocationData = new Result();
             if (refCount == 0)
             {
                 thereIsRevocationData.SetStatus(Result.ResultStatus.INVALID, "no.revocation.data.reference"
                                                 );
             }
             else
             {
                 thereIsRevocationData.SetStatus(Result.ResultStatus.VALID, "at.least.one.reference"
                                                 );
             }
             levelCReached = new Result(everyNeededCertAreInSignature.GetStatus() == Result.ResultStatus
                                        .VALID && thereIsRevocationData.GetStatus() == Result.ResultStatus.VALID);
             return(new SignatureLevelC(levelCReached, everyNeededCertAreInSignature, thereIsRevocationData
                                        ));
         }
     }
     catch (Exception)
     {
         return(new SignatureLevelC(new Result(Result.ResultStatus.INVALID, "exception.while.verifying"
                                               ), new Result(Result.ResultStatus.INVALID, "exception.while.verifying"), new Result
                                        (Result.ResultStatus.INVALID, "exception.while.verifying")));
     }
 }