code: public boolean validateKeyChain(X509Certificate client, KeyStore keyStore) throws KeyStoreException, CertificateException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException {
  
          X509Certificate[] certs = new X509Certificate[keyStore.size()];
          int i = 0;
  
          Enumeration<String> alias = keyStore.aliases();
  
          while (alias.hasMoreElements()) {
              certs[i++] = (X509Certificate) keyStore.getCertificate(alias.nextElement());
          }
  
          return validateKeyChain(client, certs);
      }
docs: Validate keychain
  
  @param client   is the client X509Certificate
  @param keyStore containing all trusted certificate
  @return true if validation until root certificate success, false otherwise
  @throws KeyStoreException KeyStore is invalid
  @throws CertificateException Certificate is Invalid
  @throws InvalidAlgorithmParameterException Algorithm Parameter is Invalid
  @throws NoSuchAlgorithmException Algorithm Does Not Exist
  @throws NoSuchProviderException No Such Security Provider Exists