Example usage for javax.net.ssl SSLContext getClientSessionContext

List of usage examples for javax.net.ssl SSLContext getClientSessionContext

Introduction

In this page you can find the example usage for javax.net.ssl SSLContext getClientSessionContext.

Prototype

public final SSLSessionContext getClientSessionContext() 

Source Link

Document

Returns the client session context, which represents the set of SSL sessions available for use during the handshake phase of client-side SSL sockets.

Usage

From source file:cc.abstra.trantor.security.ssl.OwnSSLProtocolSocketFactory.java

private SSLContext createSSLContext() throws IOException {
    try {/*  ww w  . ja  va 2 s  .c o m*/
        KeyManager[] keymanagers = null;
        TrustManager[] trustmanagers = null;
        if (sslManager != null) {
            KeyManager km = sslManager.getKeyManager();
            if (km != null) {
                keymanagers = new KeyManager[] { km };
            }
            TrustManager tm = sslManager.getTrustManager();
            if (tm != null) {
                trustmanagers = new TrustManager[] { tm };
            }
        }
        SSLContext sslcontext = SSLContext.getInstance("SSL");
        sslcontext.init(keymanagers, trustmanagers, null);
        sslcontext.getClientSessionContext().setSessionTimeout(SSL_TIME_OUT);
        return sslcontext;
    } catch (NoSuchAlgorithmException ex) {
        LOG.error(ex.getMessage(), ex);
        throw new IOException(ex.getMessage());
    } catch (KeyManagementException ex) {
        LOG.error(ex.getMessage(), ex);
        throw new IOException(ex.getMessage());
    }
}

From source file:android.net.http.CertificateChainValidator.java

/**
 * @param sslContext The SSL context shared accross all the SSL sessions
 * @param host The host associated with the session
 * @return A suitable SSL session from the SSL context
 *//*from ww  w. j  a v  a 2s  .c  o  m*/
private SSLSession getSSLSession(SSLContext sslContext, HttpHost host) {
    if (sslContext != null && host != null) {
        Enumeration en = sslContext.getClientSessionContext().getIds();
        while (en.hasMoreElements()) {
            byte[] id = (byte[]) en.nextElement();
            if (id != null) {
                SSLSession session = sslContext.getClientSessionContext().getSession(id);
                if (session.isValid() && host.getHostName().equals(session.getPeerHost())
                        && host.getPort() == session.getPeerPort()) {
                    return session;
                }
            }
        }
    }

    return null;
}

From source file:com.alibaba.openapi.client.rpc.AlibabaClientReactor.java

private void createIOEventDispatch(ClientPolicy policy, HttpParams params)
        throws NoSuchAlgorithmException, KeyManagementException {
    HttpProcessor httpproc = createHttpProcessor();
    ByteBufferAllocator allocator = new HeapByteBufferAllocator();
    ////HTTP I/O?I/O???I/O?HTTP???NHttpClientHandlerNHttpServiceHandler?HTTP??HTTP???(handler).
    AsyncNHttpClientHandler handler = new AsyncNHttpClientHandler(httpproc,
            new AliNHttpRequstExecutionHandler(new ProtocolProvider(policy), allocator),
            new DefaultConnectionReuseStrategy(), allocator, params);
    //        BufferingHttpClientHandler handler = new BufferingHttpClientHandler(httpproc, new MyHttpRequestExecutionHandler(),
    //                new DefaultConnectionReuseStrategy(), params);
    handler.setEventListener(new EventLogger());
    SSLContext sslcontext = SSLContext.getInstance("TLS");
    sslcontext.init(null, new TrustManager[] { new X509TrustManager() {
        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
            return null;
        }/* ww w  .  j av  a2s.  c  o  m*/

        public void checkServerTrusted(java.security.cert.X509Certificate[] arg0, String arg1)
                throws CertificateException {
        }

        public void checkClientTrusted(java.security.cert.X509Certificate[] arg0, String arg1)
                throws CertificateException {
        }
    } }, new SecureRandom());
    sslcontext.getClientSessionContext().setSessionCacheSize(200);
    sslcontext.getClientSessionContext().setSessionTimeout(30000);
    //dispatchIOhandler
    ioEventDispatch = new AutoSSLClientIOEventDispatch(handler, sslcontext, params);
}

From source file:org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduit.java

public synchronized SSLContext getSSLContext(TLSClientParameters tlsClientParameters)
        throws GeneralSecurityException {

    int hash = tlsClientParameters.hashCode();
    if (hash == lastTlsHash && sslContext != null) {
        return sslContext;
    }//from w  w  w.j a  v  a2s  .  c  o  m

    String provider = tlsClientParameters.getJsseProvider();

    String protocol = tlsClientParameters.getSecureSocketProtocol() != null
            ? tlsClientParameters.getSecureSocketProtocol()
            : "TLS";

    SSLContext ctx = provider == null ? SSLContext.getInstance(protocol)
            : SSLContext.getInstance(protocol, provider);
    ctx.getClientSessionContext().setSessionTimeout(tlsClientParameters.getSslCacheTimeout());

    KeyManager[] keyManagers = tlsClientParameters.getKeyManagers();
    org.apache.cxf.transport.https.SSLUtils.configureKeyManagersWithCertAlias(tlsClientParameters, keyManagers);

    ctx.init(keyManagers, tlsClientParameters.getTrustManagers(), tlsClientParameters.getSecureRandom());

    sslContext = ctx;
    lastTlsHash = hash;
    sslState = null;
    sslURL = null;
    session = null;
    return ctx;
}