public KeyStoreAwareSocketFactory(final AbstractSslContextFactory abstractFactory, X509HostnameVerifier hostnameVerifier) throws ClientSslSocketFactoryException, NoSuchAlgorithmException{ super(abstractFactory == null ? SSLContext.getDefault() : abstractFactory.getSSLContext(), hostnameVerifier); if(abstractFactory == null){ this.keyStore = null; this.trustStore = null; }else{ this.keyStore = abstractFactory.getKeyStore(); this.trustStore = abstractFactory.getTrustStore(); } }
public SSLContext getSSLContext() throws ClientSslSocketFactoryException{ return createSSLContext(); }
/** * Creates the SSL context needed to create the socket factory used by this factory. The key and * trust store parameters are optional. If they are null then the JRE defaults will be used. * * @return the newly created SSL context * @throws ClientSslSocketFactoryException if an error is detected loading the specified key or * trust stores */ private SSLContext createSSLContext() throws ClientSslSocketFactoryException { final KeyManager[] keyManagers = this.keyStore != null ? createKeyManagers() : null; final TrustManager[] trustManagers = this.trustStore != null ? createTrustManagers() : null; try { final SSLContext sslcontext = SSLContext.getInstance(SOCKET_ALGORITHM); sslcontext.init(keyManagers, trustManagers, null); return sslcontext; } catch (NoSuchAlgorithmException e) { throw new ClientSslSocketFactoryException(String.format("Failed to create an SSL context that supports algorithm %s: %s", SOCKET_ALGORITHM, e.getMessage()), e); } catch (KeyManagementException e) { throw new ClientSslSocketFactoryException(String.format("Failed to initialize an SSL context: %s", e.getMessage()), e); } }
SSLEngineFactory myFactory = new DefaultFactories.SSLContextBasedFactory(sslContextFactory.getSSLContext()) { @Override public SSLEngine createSSLEngine(ByteBufAllocator allocator) {
public KeyStoreAwareSocketFactory(final AbstractSslContextFactory abstractFactory) throws ClientSslSocketFactoryException, NoSuchAlgorithmException{ super(abstractFactory == null ? SSLContext.getDefault() : abstractFactory.getSSLContext()); if(abstractFactory == null){ this.keyStore = null; this.trustStore = null; }else{ this.keyStore = abstractFactory.getKeyStore(); this.trustStore = abstractFactory.getTrustStore(); } }