public static List<VerificationException> verifyCertificates(Certificate[] certs,KeyStore keystore,Collection<CRL> crls,Calendar calendar){
  List<VerificationException> result=new ArrayList<>();
  for (int k=0; k < certs.length; ++k) {
    X509Certificate cert=(X509Certificate)certs[k];
    String err=verifyCertificate(cert,crls,calendar);
    if (err != null)     result.add(new VerificationException(cert,err));
    try {
      for (      X509Certificate certStoreX509 : SignUtils.getCertificates(keystore)) {
        try {
          if (verifyCertificate(certStoreX509,crls,calendar) != null)           continue;
          try {
            cert.verify(certStoreX509.getPublicKey());
            return result;
          }
 catch (          Exception e) {
            continue;
          }
        }
 catch (        Exception ex) {
        }
      }
    }
 catch (    Exception e) {
    }
    int j;
    for (j=0; j < certs.length; ++j) {
      if (j == k)       continue;
      X509Certificate certNext=(X509Certificate)certs[j];
      try {
        cert.verify(certNext.getPublicKey());
        break;
      }
 catch (      Exception e) {
      }
    }
    if (j == certs.length) {
      result.add(new VerificationException(cert,"Cannot be verified against the KeyStore or the certificate chain"));
    }
  }
  if (result.size() == 0)   result.add(new VerificationException((Certificate)null,"Invalid state. Possible circular certificate chain"));
  return result;
}

public static List < VerificationException > verifyCertificates ( Certificate [ ] certs , KeyStore keystore , Collection < CRL > crls , Calendar calendar ) { List < VerificationException > result = new ArrayList < > ( ) ; for ( int k = 0 ; k < certs . length ; ++ k ) { X509Certificate cert = ( X509Certificate ) certs [ k ] ; String err = verifyCertificate ( cert , crls , calendar ) ; if ( err != null ) result . add ( new VerificationException ( cert , err ) ) ; try { for ( X509Certificate certStoreX509 : SignUtils . getCertificates ( keystore ) ) { try { if ( verifyCertificate ( certStoreX509 , crls , calendar ) != null ) continue ; try { cert . verify ( certStoreX509 . getPublicKey ( ) ) ; return result ; } catch ( Exception e ) { continue ; } } catch ( Exception ex ) { } } } catch ( Exception e ) { } int j ; for ( j = 0 ; j < certs . length ; ++ j ) { if ( j == k ) continue ; X509Certificate certNext = ( X509Certificate ) certs [ j ] ; try { cert . verify ( certNext . getPublicKey ( ) ) ; break ; } catch ( Exception e ) { } } if ( j == certs . length ) { result . add ( new VerificationException ( cert , "Cannot be verified against the KeyStore or the certificate chain" ) ) ; } } if ( result . size ( ) == 0 ) result . add ( new VerificationException ( ( Certificate ) null , "Invalid state. Possible circular certificate chain" ) ) ; return result ; }
verifies a certificate chain against a keystore .
