Example usage for io.netty.handler.ssl SslHandler handshakeFuture

List of usage examples for io.netty.handler.ssl SslHandler handshakeFuture

Introduction

In this page you can find the example usage for io.netty.handler.ssl SslHandler handshakeFuture.

Prototype

public Future<Channel> handshakeFuture() 

Source Link

Document

Returns a Future that will get notified once the current TLS handshake completes.

Usage

From source file:org.vertx.java.core.net.impl.DefaultNetSocket.java

License:Open Source License

@Override
public NetSocket ssl(final Handler<Void> handler) {
    SslHandler sslHandler = channel.pipeline().get(SslHandler.class);
    if (sslHandler == null) {
        sslHandler = helper.createSslHandler(vertx, client);
        channel.pipeline().addFirst(sslHandler);
    }//  w w w . j av  a 2  s.co  m
    sslHandler.handshakeFuture().addListener(new GenericFutureListener<Future<Channel>>() {
        @Override
        public void operationComplete(final Future<Channel> future) throws Exception {
            if (context.isOnCorrectWorker(channel.eventLoop())) {
                if (future.isSuccess()) {
                    try {
                        vertx.setContext(context);
                        handler.handle(null);
                    } catch (Throwable t) {
                        context.reportException(t);
                    }
                } else {
                    context.reportException(future.cause());
                }

            } else {
                context.execute(new Runnable() {
                    public void run() {
                        if (future.isSuccess()) {
                            handler.handle(null);
                        } else {
                            context.reportException(future.cause());
                        }
                    }
                });
            }
        }
    });
    return this;
}

From source file:org.waarp.common.crypto.ssl.WaarpSslUtility.java

License:Open Source License

/**
 * Wait for the handshake on the given channel (better to use addSslHandler when handler is added after channel is active)
 * /* w ww. ja  v a2s  . c  o  m*/
 * @param channel
 * @return True if the Handshake is done correctly
 */
public static boolean waitForHandshake(Channel channel) {
    final ChannelHandler handler = channel.pipeline().first();
    if (handler instanceof SslHandler) {
        logger.debug("Start handshake SSL: " + channel);
        final SslHandler sslHandler = (SslHandler) handler;
        // Get the SslHandler and begin handshake ASAP.
        // Get notified when SSL handshake is done.
        Future<Channel> handshakeFuture = sslHandler.handshakeFuture();
        try {
            handshakeFuture.await(sslHandler.getHandshakeTimeoutMillis() + 100);
        } catch (InterruptedException e1) {
        }
        logger.debug("Handshake: " + handshakeFuture.isSuccess() + ": " + channel, handshakeFuture.cause());
        if (!handshakeFuture.isSuccess()) {
            channel.close();
            return false;
        }
        return true;
    } else {
        logger.error("SSL Not found but connected: " + handler.getClass().getName());
        return true;
    }
}

From source file:org.waarp.openr66.protocol.networkhandler.ssl.NetworkSslServerHandler.java

License:Open Source License

@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    Channel networkChannel = ctx.channel();
    logger.debug("Add channel to ssl");
    WaarpSslUtility.addSslOpenedChannel(networkChannel);
    isSSL = true;/*from  ww w  .  ja v a  2s.  c  om*/
    // Check first if allowed
    if (NetworkTransaction.isBlacklisted(networkChannel)) {
        logger.warn("Connection refused since Partner is in BlackListed from "
                + networkChannel.remoteAddress().toString());
        isBlackListed = true;
        if (Configuration.configuration.getR66Mib() != null) {
            Configuration.configuration.getR66Mib().notifyError("Black Listed connection temptative",
                    "During Handshake");
        }
        // close immediately the connection
        WaarpSslUtility.closingSslChannel(networkChannel);
        return;
    }
    // Get the SslHandler in the current pipeline.
    // We added it in NetworkSslServerInitializer.
    final ChannelHandler handler = ctx.pipeline().first();
    if (handler instanceof SslHandler) {
        final SslHandler sslHandler = (SslHandler) handler;
        sslHandler.handshakeFuture().addListener(new GenericFutureListener<Future<? super Channel>>() {
            public void operationComplete(Future<? super Channel> future) throws Exception {
                if (!future.isSuccess()) {
                    if (Configuration.configuration.getR66Mib() != null) {
                        Configuration.configuration.getR66Mib().notifyError("SSL Connection Error",
                                "During Handshake");
                    }
                }
            }
        });
    } else {
        logger.error("SSL Not found");
    }
    super.channelActive(ctx);
}

From source file:org.waarp.openr66.proxy.network.ssl.NetworkSslServerHandler.java

License:Open Source License

@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    Channel channel = ctx.channel();
    logger.debug("Add channel to ssl");
    WaarpSslUtility.addSslOpenedChannel(channel);
    isSSL = true;/*  w w  w  .  j a  va 2  s.co m*/
    // Get the SslHandler in the current pipeline.
    // We added it in NetworkSslServerInitializer.
    final ChannelHandler handler = ctx.pipeline().first();
    if (handler instanceof SslHandler) {
        final SslHandler sslHandler = (SslHandler) handler;
        sslHandler.handshakeFuture().addListener(new GenericFutureListener<Future<? super Channel>>() {
            public void operationComplete(Future<? super Channel> future) throws Exception {
                if (!future.isSuccess()) {
                    if (Configuration.configuration.getR66Mib() != null) {
                        Configuration.configuration.getR66Mib().notifyError("SSL Connection Error",
                                "During Handshake");
                    }
                }
            }
        });
    } else {
        logger.error("SSL Not found");
    }
    super.channelActive(ctx);
}