Example usage for javax.net.ssl SSLSession getPeerPort

List of usage examples for javax.net.ssl SSLSession getPeerPort

Introduction

In this page you can find the example usage for javax.net.ssl SSLSession getPeerPort.

Prototype

public int getPeerPort();

Source Link

Document

Returns the port number of the peer in this session.

Usage

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  w ww  .j  a  v  a  2s  .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
 *///w w  w . java  2s.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: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   w  w  w .j  a va  2  s . 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;
}