Example usage for javax.net.ssl SSLSessionContext getIds

List of usage examples for javax.net.ssl SSLSessionContext getIds

Introduction

In this page you can find the example usage for javax.net.ssl SSLSessionContext getIds.

Prototype

public Enumeration<byte[]> getIds();

Source Link

Document

Returns an Enumeration of all session id's grouped under this SSLSessionContext.

Usage

From source file:com.thoughtworks.go.security.AuthSSLProtocolSocketFactory.java

private boolean isEmptyKeyStore() {
    SSLSessionContext sessionContext = sslContextWithKeyStore.getClientSessionContext();
    @SuppressWarnings("unchecked")
    Enumeration<byte[]> sessionIds = sessionContext.getIds();
    if (sessionIds.hasMoreElements()) {
        byte[] sessionId = sessionIds.nextElement();
        Certificate[] localCertificates = sessionContext.getSession(sessionId).getLocalCertificates();
        return localCertificates == null || localCertificates.length > 0;
    } else {//  w  w w  .j a v  a2s. c  o m
        return true;
    }
}

From source file:ee.ria.xroad.proxy.clientproxy.FastestConnectionSelectingSSLSocketFactory.java

private CachedSSLSessionHostInformation getCachedSSLSessionHostURI(URI[] addresses) {
    SSLSessionContext sessionCtx = sslContext.getClientSessionContext();

    Enumeration<byte[]> ids = sessionCtx.getIds();
    while (ids.hasMoreElements()) {
        byte[] id = ids.nextElement();

        SSLSession session = sessionCtx.getSession(id);
        if (session != null) {
            for (URI address : addresses) {
                if (isSessionHost(session, address)) {
                    log.trace("Found cached session for {}", address);
                    return new CachedSSLSessionHostInformation(address, session);
                }/*  w ww  .j  a  v  a2s .co  m*/
            }
        }
    }

    return new CachedSSLSessionHostInformation();
}

From source file:com.ksc.http.conn.ssl.SdkTLSSocketFactory.java

/**
 * Invalidates all SSL/TLS sessions in {@code sessionContext} associated with {@code remoteAddress}.
 *
 * @param sessionContext collection of SSL/TLS sessions to be (potentially) invalidated
 * @param remoteAddress  associated with sessions to invalidate
 *//*from   ww w .  j a va2s.c o m*/
private void clearSessionCache(final SSLSessionContext sessionContext, final InetSocketAddress remoteAddress) {
    final String hostName = remoteAddress.getHostName();
    final int port = remoteAddress.getPort();
    final Enumeration<byte[]> ids = sessionContext.getIds();

    if (ids == null) {
        return;
    }

    while (ids.hasMoreElements()) {
        final byte[] id = ids.nextElement();
        final SSLSession session = sessionContext.getSession(id);
        if (session != null && session.getPeerHost() != null && session.getPeerHost().equalsIgnoreCase(hostName)
                && session.getPeerPort() == port) {
            session.invalidate();
            if (LOG.isDebugEnabled()) {
                LOG.debug("Invalidated session " + session);
            }
        }
    }
}

From source file:com.amazonaws.http.conn.ssl.SdkTLSSocketFactory.java

/**
 * Invalidates all SSL/TLS sessions in {@code sessionContext} associated with {@code remoteAddress}.
 * @param sessionContext collection of SSL/TLS sessions to be (potentially) invalidated
 * @param remoteAddress associated with sessions to invalidate
 *///from   w w w  . ja v a  2 s  .c  o m
private void clearSessionCache(final SSLSessionContext sessionContext, final InetSocketAddress remoteAddress) {
    final String hostName = remoteAddress.getHostName();
    final int port = remoteAddress.getPort();
    final Enumeration<byte[]> ids = sessionContext.getIds();

    if (ids == null) {
        return;
    }

    while (ids.hasMoreElements()) {
        final byte[] id = ids.nextElement();
        final SSLSession session = sessionContext.getSession(id);
        if (session != null && session.getPeerHost() != null && session.getPeerHost().equalsIgnoreCase(hostName)
                && session.getPeerPort() == port) {
            session.invalidate();
            if (log.isDebugEnabled()) {
                log.debug("Invalidated session " + session);
            }
        }
    }
}