Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.infinispan.commons.util;
 
 
SslContextFactory.

Author(s):
Tristan Tarrant
Since:
5.3
public class SslContextFactory {
   private static final Log log = LogFactory.getLog(SslContextFactory.class);
   public static SSLContext getContext(String keyStoreFileNamechar[] keyStorePasswordString trustStoreFileNamechar[] trustStorePassword) {
      try {
         KeyManager[] keyManagers = null;
         if (keyStoreFileName != null) {
            KeyStore ks = KeyStore.getInstance("JKS");
            loadKeyStore(kskeyStoreFileNamekeyStorePassword);
            KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
            kmf.init(kskeyStorePassword);
            keyManagers = kmf.getKeyManagers();
         }
         TrustManager[] trustManagers = null;
         if (trustStoreFileName != null) {
            KeyStore ks = KeyStore.getInstance("JKS");
            loadKeyStore(kstrustStoreFileNametrustStorePassword);
            TrustManagerFactory tmf = TrustManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
            tmf.init(ks);
            trustManagers = tmf.getTrustManagers();
         }
         SSLContext sslContext = SSLContext.getInstance("TLS");
         sslContext.init(keyManagerstrustManagersnull);
         return sslContext;
      } catch (Exception e) {
         throw .sslInitializationException(e);
      }
   }
   public static SSLEngine getEngine(SSLContext sslContextboolean useClientModeboolean needClientAuth) {
      SSLEngine sslEngine = sslContext.createSSLEngine();
      sslEngine.setUseClientMode(useClientMode);
      sslEngine.setNeedClientAuth(needClientAuth);
      return sslEngine;
   }
   private static void loadKeyStore(KeyStore ksString keyStoreFileNamechar[] keyStorePasswordthrows IOExceptionGeneralSecurityException {
      InputStream is = new BufferedInputStream(new FileInputStream(keyStoreFileName));
      try {
         ks.load(iskeyStorePassword);
      } finally {
         Util.close(is);
      }
   }
New to GrepCode? Check out our FAQ X