Ejemplo n.º 1
0
 protected internal virtual SignatureLevelXL VerifyLevelXL(AdvancedSignature signature
                                                           , DateTime referenceTime, ValidationContext ctx)
 {
     try
     {
         Result levelReached = new Result();
         Result everyNeededCertAreInSignature = new Result();
         everyNeededCertAreInSignature.SetStatus(Result.ResultStatus.VALID, null);
         Result everyNeededRevocationData = new Result();
         everyNeededRevocationData.SetStatus(Result.ResultStatus.VALID, null);
         IList <X509Certificate> refs = signature.GetCertificates();
         if (refs.IsEmpty())
         {
             LOG.Info("There is no certificate refs in the signature");
             everyNeededCertAreInSignature.SetStatus(Result.ResultStatus.INVALID, "no.certificate.value"
                                                     );
         }
         else
         {
             if (!EveryCertificateValueAreThere(ctx, refs, signature.GetSigningCertificate()))
             {
                 everyNeededCertAreInSignature.SetStatus(Result.ResultStatus.INVALID, "not.all.needed.certificate.value"
                                                         );
             }
         }
         LOG.Info("Every certificate found " + everyNeededCertAreInSignature);
         int valueCount = 0;
         IList <BasicOcspResp> ocspValues = signature.GetOCSPs();
         if (ocspValues != null)
         {
             valueCount += ocspValues.Count;
             if (!EveryOCSPValueOrRefAreThere(ctx, ocspValues))
             {
                 everyNeededRevocationData.SetStatus(Result.ResultStatus.INVALID, "not.all.needed.ocsp.value"
                                                     );
             }
         }
         IList <X509Crl> crlValues = signature.GetCRLs();
         if (crlValues != null)
         {
             valueCount += crlValues.Count;
             if (!EveryCRLValueOrRefAreThere(ctx, crlValues))
             {
                 everyNeededRevocationData.SetStatus(Result.ResultStatus.INVALID, "not.all.needed.crl.value"
                                                     );
             }
         }
         if (valueCount == 0)
         {
             everyNeededRevocationData.SetStatus(Result.ResultStatus.INVALID, "no.revocation.data.value"
                                                 );
         }
         levelReached.SetStatus((everyNeededCertAreInSignature.GetStatus() == Result.ResultStatus
                                 .VALID && everyNeededRevocationData.GetStatus() == Result.ResultStatus.VALID) ?
                                Result.ResultStatus.VALID : Result.ResultStatus.INVALID, null);
         return(new SignatureLevelXL(levelReached, everyNeededCertAreInSignature, everyNeededRevocationData
                                     ));
     }
     catch (Exception)
     {
         return(new SignatureLevelXL(new Result(Result.ResultStatus.INVALID, "exception.while.verifying"
                                                ), new Result(Result.ResultStatus.INVALID, "exception.while.verifying"), new Result
                                         (Result.ResultStatus.INVALID, "exception.while.verifying")));
     }
 }