protected static TrustManagerFactory buildTrustManagerFactory(final File certChainFile,
      TrustManagerFactory trustManagerFactory)
          throws NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException {
    KeyStore ks = KeyStore.getInstance("JKS");
    ks.load(null, null);
    CertificateFactory cf = CertificateFactory.getInstance("X.509");

    List<ByteBuffer> certs = PemReader.readCertificates(certChainFile);

    for (ByteBuffer buf : certs) {
      X509Certificate cert = (X509Certificate) cf
          .generateCertificate(new ByteArrayInputStream(buf.array()));
      X500Principal principal = cert.getSubjectX500Principal();
      ks.setCertificateEntry(principal.getName("RFC2253"), cert);
    }

    // Set up trust manager factory to use our key store.
    if (trustManagerFactory == null) {
      trustManagerFactory = TrustManagerFactory
          .getInstance(TrustManagerFactory.getDefaultAlgorithm());
    }
    trustManagerFactory.init(ks);

    return trustManagerFactory;
  }
protected static TrustManagerFactory buildTrustManagerFactory(final File certChainFile,
      TrustManagerFactory trustManagerFactory)
          throws NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException {
    KeyStore ks = KeyStore.getInstance("JKS");
    ks.load(null, null);
    CertificateFactory cf = CertificateFactory.getInstance("X.509");

    List<ByteBuffer> certs = PemReader.readCertificates(certChainFile);

    for (ByteBuffer buf : certs) {
      X509Certificate cert = (X509Certificate) cf
          .generateCertificate(new ByteArrayInputStream(buf.array()));
      X500Principal principal = cert.getSubjectX500Principal();
      ks.setCertificateEntry(principal.getName("RFC2253"), cert);
    }

    
    if (trustManagerFactory == null) {
      trustManagerFactory = TrustManagerFactory
          .getInstance(TrustManagerFactory.getDefaultAlgorithm());
    }
    trustManagerFactory.init(ks);

    return trustManagerFactory;
  }
protected static TrustManagerFactory buildTrustManagerFactory ( final File certChainFile , TrustManagerFactory trustManagerFactory ) throws NoSuchAlgorithmException , CertificateException , KeyStoreException , IOException { KeyStore ks = KeyStore . getInstance ( "JKS" ) ; ks . load ( null , null ) ; CertificateFactory cf = CertificateFactory . getInstance ( "X.509" ) ; List < ByteBuffer > certs = PemReader . readCertificates ( certChainFile ) ; for ( ByteBuffer buf : certs ) { X509Certificate cert = ( X509Certificate ) cf . generateCertificate ( new ByteArrayInputStream ( buf . array ( ) ) ) ; X500Principal principal = cert . getSubjectX500Principal ( ) ; ks . setCertificateEntry ( principal . getName ( "RFC2253" ) , cert ) ; } // Set up trust manager factory to use our key store. if ( trustManagerFactory == null ) { trustManagerFactory = TrustManagerFactory . getInstance ( TrustManagerFactory . getDefaultAlgorithm ( ) ) ; } trustManagerFactory . init ( ks ) ; return trustManagerFactory ; }
Build a {@link TrustManagerFactory} from a certificate chain file.

@param certChainFile The certificate file to build from.
@param trustManagerFactory The existing {@link TrustManagerFactory} that will be used if not
{@code null}.
@return A {@link TrustManagerFactory} which contains the certificates in {@code certChainFile}
Build a { @link TrustManagerFactory } from a certificate chain file .