Java 类javax.net.ssl.HandshakeCompletedListener 实例源码

项目:conscrypt    文件:ConscryptSocketBase.java   
final void notifyHandshakeCompletedListeners() {
    if (listeners != null && !listeners.isEmpty()) {
        // notify the listeners
        HandshakeCompletedEvent event = new HandshakeCompletedEvent(this, getActiveSession());
        for (HandshakeCompletedListener listener : listeners) {
            try {
                listener.handshakeCompleted(event);
            } catch (RuntimeException e) {
                // The RI runs the handlers in a separate thread,
                // which we do not. But we try to preserve their
                // behavior of logging a problem and not killing
                // the handshaking thread just because a listener
                // has a problem.
                Thread thread = Thread.currentThread();
                thread.getUncaughtExceptionHandler().uncaughtException(thread, e);
            }
        }
    }
}
项目:javify    文件:HTTPConnection.java   
/**
 * Creates a new HTTP or HTTPS connection on the specified port.
 * @param hostname the name of the host to connect to
 * @param port the port on the host to connect to
 * @param secure whether to use a secure connection
 * @param connectionTimeout the connection timeout
 * @param timeout the socket read timeout
 *
 * @throws IllegalArgumentException if either connectionTimeout or
 * timeout less than zero.
 */
public HTTPConnection(String hostname, int port, boolean secure,
                      int connectionTimeout, int timeout)
{
  if (connectionTimeout < 0 || timeout < 0)
    throw new IllegalArgumentException();

  this.hostname = hostname;
  this.port = port;
  this.secure = secure;
  this.connectionTimeout = connectionTimeout;
  this.timeout = timeout;
  majorVersion = minorVersion = 1;
  handshakeCompletedListeners
    = new ArrayList<HandshakeCompletedListener>(2);
}
项目:jvm-stm    文件:HTTPConnection.java   
/**
 * Creates a new HTTP or HTTPS connection on the specified port.
 * @param hostname the name of the host to connect to
 * @param port the port on the host to connect to
 * @param secure whether to use a secure connection
 * @param connectionTimeout the connection timeout
 * @param timeout the socket read timeout
 *
 * @throws IllegalArgumentException if either connectionTimeout or
 * timeout less than zero.
 */
public HTTPConnection(String hostname, int port, boolean secure,
                      int connectionTimeout, int timeout)
{
  if (connectionTimeout < 0 || timeout < 0)
    throw new IllegalArgumentException();

  this.hostname = hostname;
  this.port = port;
  this.secure = secure;
  this.connectionTimeout = connectionTimeout;
  this.timeout = timeout;
  majorVersion = minorVersion = 1;
  handshakeCompletedListeners
    = new ArrayList<HandshakeCompletedListener>(2);
}
项目:Wilma    文件:SimulatedSSLSocket.java   
@Override
public void connect(SocketAddress endpoint, int timeout) throws IOException {
    Date start = new Date();
    socket.connect(endpoint, timeout);
    Date end = new Date();
    RequestInfo.get().connect(start, end);
    handshakeStart = new Date();
    startHandshake();
    this.addHandshakeCompletedListener(new HandshakeCompletedListener() {
        @Override
        public void handshakeCompleted(HandshakeCompletedEvent handshakeCompletedEvent) {
            if (handshakeStart != null) {
                RequestInfo.get().ssl(handshakeStart, new Date());
            }
        }
    });
}
项目:In-the-Box-Fork    文件:SSLSocketImpl.java   
/**
 * This method works according to the specification of implemented class.
 * @see javax.net.ssl.SSLSocket#removeHandshakeCompletedListener(HandshakeCompletedListener)
 * method documentation for more information
 */
@Override
public void removeHandshakeCompletedListener(
        HandshakeCompletedListener listener) {
    if (listener == null) {
        throw new IllegalArgumentException("Provided listener is null");
    }
    if (listeners == null) {
        throw new IllegalArgumentException(
                "Provided listener is not registered");
    }
    if (!listeners.remove(listener)) {
        throw new IllegalArgumentException(
                "Provided listener is not registered");
    }
}
项目:In-the-Box-Fork    文件:OpenSSLSocketImpl.java   
private void notifyHandshakeCompletedListeners() {
    if (listeners != null && !listeners.isEmpty()) {
        // notify the listeners
        HandshakeCompletedEvent event =
            new HandshakeCompletedEvent(this, sslSession);
        for (HandshakeCompletedListener listener : listeners) {
            try {
                listener.handshakeCompleted(event);
            } catch (RuntimeException e) {
                // The RI runs the handlers in a separate thread,
                // which we do not. But we try to preserve their
                // behavior of logging a problem and not killing
                // the handshaking thread just because a listener
                // has a problem.
                Thread thread = Thread.currentThread();
                thread.getUncaughtExceptionHandler().uncaughtException(thread, e);
            }
        }
    }
}
项目:In-the-Box-Fork    文件:OpenSSLSocketImpl.java   
/**
 * The method removes a registered listener.
 * @throws IllegalArgumentException if listener is null or not registered
 */
@Override
public void removeHandshakeCompletedListener(
        HandshakeCompletedListener listener) {
    if (listener == null) {
        throw new IllegalArgumentException("Provided listener is null");
    }
    if (listeners == null) {
        throw new IllegalArgumentException(
                "Provided listener is not registered");
    }
    if (!listeners.remove(listener)) {
        throw new IllegalArgumentException(
                "Provided listener is not registered");
    }
}
项目:cn1    文件:SSLSocketImpl.java   
/**
 * This method works according to the specification of implemented class.
 * @see javax.net.ssl.SSLSocket#removeHandshakeCompletedListener(HandshakeCompletedListener)
 * method documentation for more information
 */
@Override
public void removeHandshakeCompletedListener(
        HandshakeCompletedListener listener) {
    if (listener == null) {
        throw new IllegalArgumentException("Provided listener is null");
    }
    if (listeners == null) {
        throw new IllegalArgumentException(
                "Provided listener is not registered");
    }
    if (!listeners.remove(listener)) {
        throw new IllegalArgumentException(
                "Provided listener is not registered");
    }
}
项目:JamVM-PH    文件:HTTPConnection.java   
/**
 * Creates a new HTTP or HTTPS connection on the specified port.
 * @param hostname the name of the host to connect to
 * @param port the port on the host to connect to
 * @param secure whether to use a secure connection
 * @param connectionTimeout the connection timeout
 * @param timeout the socket read timeout
 *
 * @throws IllegalArgumentException if either connectionTimeout or
 * timeout less than zero.
 */
public HTTPConnection(String hostname, int port, boolean secure,
                      int connectionTimeout, int timeout)
{
  if (connectionTimeout < 0 || timeout < 0)
    throw new IllegalArgumentException();

  this.hostname = hostname;
  this.port = port;
  this.secure = secure;
  this.connectionTimeout = connectionTimeout;
  this.timeout = timeout;
  majorVersion = minorVersion = 1;
  handshakeCompletedListeners
    = new ArrayList<HandshakeCompletedListener>(2);
}
项目:classpath    文件:HTTPConnection.java   
/**
 * Creates a new HTTP or HTTPS connection on the specified port.
 * @param hostname the name of the host to connect to
 * @param port the port on the host to connect to
 * @param secure whether to use a secure connection
 * @param connectionTimeout the connection timeout
 * @param timeout the socket read timeout
 *
 * @throws IllegalArgumentException if either connectionTimeout or
 * timeout less than zero.
 */
public HTTPConnection(String hostname, int port, boolean secure,
                      int connectionTimeout, int timeout)
{
  if (connectionTimeout < 0 || timeout < 0)
    throw new IllegalArgumentException();

  this.hostname = hostname;
  this.port = port;
  this.secure = secure;
  this.connectionTimeout = connectionTimeout;
  this.timeout = timeout;
  majorVersion = minorVersion = 1;
  handshakeCompletedListeners
    = new ArrayList<HandshakeCompletedListener>(2);
}
项目:freeVM    文件:SSLSocketImpl.java   
/**
 * This method works according to the specification of implemented class.
 * @see javax.net.ssl.SSLSocket#removeHandshakeCompletedListener(HandshakeCompletedListener)
 * method documentation for more information
 */
@Override
public void removeHandshakeCompletedListener(
        HandshakeCompletedListener listener) {
    if (listener == null) {
        throw new IllegalArgumentException("Provided listener is null");
    }
    if (listeners == null) {
        throw new IllegalArgumentException(
                "Provided listener is not registered");
    }
    if (!listeners.remove(listener)) {
        throw new IllegalArgumentException(
                "Provided listener is not registered");
    }
}
项目:cyberduck    文件:CustomTrustSSLProtocolSocketFactory.java   
/**
 * @param socket    Socket to configure
 * @param protocols Enabled SSL protocol versions
 */
protected void configure(final Socket socket, final String[] protocols) throws IOException {
    if(socket instanceof SSLSocket) {
        try {
            if(log.isDebugEnabled()) {
                log.debug(String.format("Configure SSL parameters with protocols %s", Arrays.toString(protocols)));
            }
            ((SSLSocket) socket).setEnabledProtocols(protocols);
            final List<String> ciphers = Arrays.asList(((SSLSocket) socket).getEnabledCipherSuites());
            final List<String> blacklist = preferences.getList("connection.ssl.cipher.blacklist");
            if(!blacklist.isEmpty()) {
                ciphers.removeIf(blacklist::contains);
            }
            ((SSLSocket) socket).setEnabledCipherSuites(ciphers.toArray(new String[ciphers.size()]));
            if(log.isInfoEnabled()) {
                log.info(String.format("Enabled cipher suites %s",
                        Arrays.toString(((SSLSocket) socket).getEnabledCipherSuites())));
                ((SSLSocket) socket).addHandshakeCompletedListener(new HandshakeCompletedListener() {
                    @Override
                    public void handshakeCompleted(final HandshakeCompletedEvent event) {
                        log.info(String.format("Completed handshake with %s and negotiated cipher suite %s",
                                event.getSession().getProtocol(), event.getCipherSuite()));
                        ((SSLSocket) socket).removeHandshakeCompletedListener(this);
                    }
                });
            }
        }
        catch(Exception e) {
            log.warn(String.format("Failed to configure SSL parameters %s", e.getMessage()));
        }
    }
}
项目:dacapobench    文件:SocketFactory.java   
/**
 * Create an SSL client socket using the IOR-encoded
 * security characteristics.
 * Setting want/need client auth on a client socket has no effect so all we can do is use the right host, port, ciphers
 *
 * @param host     The target host name.
 * @param port     The target connection port.
 *
 * @return An appropriately configured client SSLSocket.
 * @exception IOException if ssl socket can't be obtained and configured.
 */
private Socket createSSLSocket(String host, int port, int requires, int supports) throws IOException {
    SSLSocketFactory factory = getSocketFactory();
    SSLSocket socket = (SSLSocket) factory.createSocket(host, port);

    socket.setSoTimeout(SOCKET_TIMEOUT_MS);

    // get a set of cipher suites appropriate for this connections requirements.
    // We request this for each connection, since the outgoing IOR's requirements may be different from
    // our server listener requirements.
    String[] iorSuites = SSLCipherSuiteDatabase.getCipherSuites(requires, supports, factory.getSupportedCipherSuites());
    socket.setEnabledCipherSuites(iorSuites);
    if (log.isDebugEnabled()) {
        log.debug("Created SSL socket to " + host + ":" + port);
        log.debug("    cipher suites:");

        for (int i = 0; i < iorSuites.length; i++) {
            log.debug("    " + iorSuites[i]);
        }
        socket.addHandshakeCompletedListener(new HandshakeCompletedListener() {

            public void handshakeCompleted(HandshakeCompletedEvent handshakeCompletedEvent) {
                Certificate[] certs = handshakeCompletedEvent.getLocalCertificates();
                if (certs != null) {
                    log.debug("handshake returned local certs count: " + certs.length);
                    for (int i = 0; i < certs.length; i++) {
                        Certificate cert = certs[i];
                        log.debug("cert: " + cert.toString());
                    }
                } else {
                    log.debug("handshake returned no local certs");
                }
            }
        });
    }
    return socket;
}
项目:conscrypt    文件:ConscryptSocketBase.java   
@Override
public void removeHandshakeCompletedListener(HandshakeCompletedListener listener) {
    checkArgument(listener != null, "Provided listener is null");
    if (!listeners.remove(listener)) {
        throw new IllegalArgumentException("Provided listener is not registered");
    }
}
项目:conscrypt    文件:SSLSocketTest.java   
@Test
public void test_SSLSocket_HandshakeCompletedListener_RuntimeException() throws Exception {
    final Thread self = Thread.currentThread();
    final UncaughtExceptionHandler original = self.getUncaughtExceptionHandler();
    final RuntimeException expectedException = new RuntimeException("expected");
    final TestUncaughtExceptionHandler test = new TestUncaughtExceptionHandler();
    self.setUncaughtExceptionHandler(test);
    final TestSSLContext c = TestSSLContext.create();
    final SSLSocket client =
            (SSLSocket) c.clientContext.getSocketFactory().createSocket(c.host, c.port);
    final SSLSocket server = (SSLSocket) c.serverSocket.accept();
    Future<Void> future = runAsync(new Callable<Void>() {
        @Override
        public Void call() throws Exception {
            server.startHandshake();
            return null;
        }
    });
    client.addHandshakeCompletedListener(new HandshakeCompletedListener() {
        @Override
        public void handshakeCompleted(HandshakeCompletedEvent event) {
            throw expectedException;
        }
    });
    client.startHandshake();
    future.get();
    client.close();
    server.close();
    c.close();
    assertSame(expectedException, test.actualException);
    self.setUncaughtExceptionHandler(original);
}
项目:javify    文件:HTTPConnection.java   
void addHandshakeCompletedListener(HandshakeCompletedListener l)
{
  synchronized (handshakeCompletedListeners)
    {
      handshakeCompletedListeners.add(l);
    }
}
项目:javify    文件:HTTPConnection.java   
void removeHandshakeCompletedListener(HandshakeCompletedListener l)
{
  synchronized (handshakeCompletedListeners)
    {
      handshakeCompletedListeners.remove(l);
    }
}
项目:javify    文件:SSLSocketImpl.java   
public SSLSocketImpl(SSLContextImpl contextImpl, String host, int port,
                     Socket underlyingSocket, boolean autoClose)
{
  engine = new SSLEngineImpl(contextImpl, host, port);
  engine.setUseClientMode(true); // default to client mode
  listeners = new HashSet<HandshakeCompletedListener>();
  this.underlyingSocket = underlyingSocket;
  this.autoClose = autoClose;
}
项目:keystore-explorer    文件:CustomSslSocketFactory.java   
/**
 * Constructor
 *
 * @param sslSocketFactory The actual SSLSocketFactory (used by this class)
 * @param handshakeListener The class that handles "handshake completed" events
 */
public CustomSslSocketFactory(SSLSocketFactory sslSocketFactory, HandshakeCompletedListener handshakeListener,
        boolean sniEnabled) {
    this.sslSocketFactory = sslSocketFactory;
    this.handshakeListener = handshakeListener;
    this.sniEnabled = sniEnabled;
}
项目:jvm-stm    文件:HTTPConnection.java   
void addHandshakeCompletedListener(HandshakeCompletedListener l)
{
  synchronized (handshakeCompletedListeners)
    {
      handshakeCompletedListeners.add(l);
    }
}
项目:jvm-stm    文件:HTTPConnection.java   
void removeHandshakeCompletedListener(HandshakeCompletedListener l)
{
  synchronized (handshakeCompletedListeners)
    {
      handshakeCompletedListeners.remove(l);
    }
}
项目:jvm-stm    文件:SSLSocketImpl.java   
public SSLSocketImpl(SSLContextImpl contextImpl, String host, int port,
                     Socket underlyingSocket, boolean autoClose)
{
  engine = new SSLEngineImpl(contextImpl, host, port);
  engine.setUseClientMode(true); // default to client mode
  listeners = new HashSet<HandshakeCompletedListener>();
  this.underlyingSocket = underlyingSocket;
  this.autoClose = autoClose;
}
项目:namecoinj    文件:SSLEngineSSLSocket.java   
public void handshakeCompleted() {
    if(listenerList.isEmpty()) {
        return;
    }
    final HandshakeCompletedEvent event = new HandshakeCompletedEvent(this, engine.getSession());
    for(HandshakeCompletedListener listener: listenerList) {
        listener.handshakeCompleted(event);
    }
}
项目:digibytej-alice    文件:SSLEngineSSLSocket.java   
public void handshakeCompleted() {
    if(listenerList.isEmpty()) {
        return;
    }
    final HandshakeCompletedEvent event = new HandshakeCompletedEvent(this, engine.getSession());
    for(HandshakeCompletedListener listener: listenerList) {
        listener.handshakeCompleted(event);
    }
}
项目:In-the-Box-Fork    文件:SSLSocketImpl.java   
/**
 * This method works according to the specification of implemented class.
 * @see javax.net.ssl.SSLSocket#addHandshakeCompletedListener(HandshakeCompletedListener)
 * method documentation for more information
 */
@Override
public void addHandshakeCompletedListener(
        HandshakeCompletedListener listener) {
    if (listener == null) {
        throw new IllegalArgumentException("Provided listener is null");
    }
    if (listeners == null) {
        listeners = new ArrayList<HandshakeCompletedListener>();
    }
    listeners.add(listener);
}
项目:In-the-Box-Fork    文件:OpenSSLSocketImpl.java   
/**
 * Registers a listener to be notified that a SSL handshake
 * was successfully completed on this connection.
 * @throws <code>IllegalArgumentException</code> if listener is null.
 */
@Override
public void addHandshakeCompletedListener(
        HandshakeCompletedListener listener) {
    if (listener == null) {
        throw new IllegalArgumentException("Provided listener is null");
    }
    if (listeners == null) {
        listeners = new ArrayList();
    }
    listeners.add(listener);
}
项目:eIDSuite    文件:EidSSLSocket.java   
@Override
public void startHandshake() throws IOException {
    Log.d(TAG, "SSLSocket.startHandshake");

    EidTlsClient client = new EidTlsClient(eidService, host, port);
    tlsClientProtocol.connect(client);

    this.session = new EidSSLSession(client);

    for (HandshakeCompletedListener listener : listeners) {
        listener.handshakeCompleted(new HandshakeCompletedEvent(this, this.session));
    }
}
项目:cn1    文件:SSLSocketImpl.java   
/**
 * This method works according to the specification of implemented class.
 * @see javax.net.ssl.SSLSocket#addHandshakeCompletedListener(HandshakeCompletedListener)
 * method documentation for more information
 */
@Override
public void addHandshakeCompletedListener(
        HandshakeCompletedListener listener) {
    if (listener == null) {
        throw new IllegalArgumentException("Provided listener is null");
    }
    if (listeners == null) {
        listeners = new ArrayList<HandshakeCompletedListener>();
    }
    listeners.add(listener);
}
项目:cn1    文件:StartTlsResponseImplTest.java   
protected MockSSLSocket(Socket socket, String host, int port)
        throws UnknownHostException {
    this.port = port;
    this.localHost = socket.getLocalAddress().getHostAddress();
    this.localPort = socket.getLocalPort();
    address = InetAddress.getByName(host);
    listeners = new LinkedList<HandshakeCompletedListener>();
}
项目:cn1    文件:StartTlsResponseImplTest.java   
@Override
public void startHandshake() throws IOException {
    for (HandshakeCompletedListener listener : listeners) {
        if (this.listeners != null) {
            listener.handshakeCompleted(null);
        } else {
            throw new Error(
                    "should not be here, at MockHandshake.startHandshake()");
        }
    }
}
项目:JamVM-PH    文件:HTTPConnection.java   
void addHandshakeCompletedListener(HandshakeCompletedListener l)
{
  synchronized (handshakeCompletedListeners)
    {
      handshakeCompletedListeners.add(l);
    }
}
项目:JamVM-PH    文件:HTTPConnection.java   
void removeHandshakeCompletedListener(HandshakeCompletedListener l)
{
  synchronized (handshakeCompletedListeners)
    {
      handshakeCompletedListeners.remove(l);
    }
}
项目:JamVM-PH    文件:SSLSocketImpl.java   
public SSLSocketImpl(SSLContextImpl contextImpl, String host, int port,
                     Socket underlyingSocket, boolean autoClose)
{
  engine = new SSLEngineImpl(contextImpl, host, port);
  engine.setUseClientMode(true); // default to client mode
  listeners = new HashSet<HandshakeCompletedListener>();
  this.underlyingSocket = underlyingSocket;
  this.autoClose = autoClose;
}
项目:quarkcoinj    文件:SSLEngineSSLSocket.java   
public void handshakeCompleted() {
    if(listenerList.isEmpty()) {
        return;
    }
    final HandshakeCompletedEvent event = new HandshakeCompletedEvent(this, engine.getSession());
    for(HandshakeCompletedListener listener: listenerList) {
        listener.handshakeCompleted(event);
    }
}
项目:animecoinj    文件:SSLEngineSSLSocket.java   
public void handshakeCompleted() {
    if(listenerList.isEmpty()) {
        return;
    }
    final HandshakeCompletedEvent event = new HandshakeCompletedEvent(this, engine.getSession());
    for(HandshakeCompletedListener listener: listenerList) {
        listener.handshakeCompleted(event);
    }
}
项目:peercoinj    文件:SSLEngineSSLSocket.java   
public void handshakeCompleted() {
    if(listenerList.isEmpty()) {
        return;
    }
    final HandshakeCompletedEvent event = new HandshakeCompletedEvent(this, engine.getSession());
    for(HandshakeCompletedListener listener: listenerList) {
        listener.handshakeCompleted(event);
    }
}
项目:dashj    文件:SSLEngineSSLSocket.java   
public void handshakeCompleted() {
    if(listenerList.isEmpty()) {
        return;
    }
    final HandshakeCompletedEvent event = new HandshakeCompletedEvent(this, engine.getSession());
    for(HandshakeCompletedListener listener: listenerList) {
        listener.handshakeCompleted(event);
    }
}
项目:NuBitsj    文件:SSLEngineSSLSocket.java   
public void handshakeCompleted() {
    if(listenerList.isEmpty()) {
        return;
    }
    final HandshakeCompletedEvent event = new HandshakeCompletedEvent(this, engine.getSession());
    for(HandshakeCompletedListener listener: listenerList) {
        listener.handshakeCompleted(event);
    }
}
项目:classpath    文件:HTTPConnection.java   
void addHandshakeCompletedListener(HandshakeCompletedListener l)
{
  synchronized (handshakeCompletedListeners)
    {
      handshakeCompletedListeners.add(l);
    }
}
项目:classpath    文件:HTTPConnection.java   
void removeHandshakeCompletedListener(HandshakeCompletedListener l)
{
  synchronized (handshakeCompletedListeners)
    {
      handshakeCompletedListeners.remove(l);
    }
}