Search in sources :

Example 1 with SslConfig

use of io.fabric8.gateway.handlers.detecting.protocol.ssl.SslConfig in project fabric8 by jboss-fuse.

the class DetectingGatewayTest method createGateway.

public DetectingGateway createGateway() {
    String loadBalancerType = LoadBalancers.STICKY_LOAD_BALANCER;
    int stickyLoadBalancerCacheSize = LoadBalancers.STICKY_LOAD_BALANCER_DEFAULT_CACHE_SIZE;
    LoadBalancer serviceLoadBalancer = LoadBalancers.createLoadBalancer(loadBalancerType, stickyLoadBalancerCacheSize);
    ArrayList<Protocol> protocols = new ArrayList<Protocol>();
    protocols.add(new StompProtocol());
    protocols.add(new MqttProtocol());
    protocols.add(new AmqpProtocol());
    protocols.add(new OpenwireProtocol());
    protocols.add(new HttpProtocol());
    protocols.add(new SslProtocol());
    DetectingGateway gateway = new DetectingGateway();
    gateway.setPort(0);
    gateway.setVertx(vertx);
    SslConfig sslConfig = new SslConfig(new File(basedir(), "src/test/resources/server.ks"), "password");
    sslConfig.setKeyPassword("password");
    gateway.setSslConfig(sslConfig);
    gateway.setServiceMap(serviceMap);
    gateway.setProtocols(protocols);
    gateway.setServiceLoadBalancer(serviceLoadBalancer);
    gateway.setDefaultVirtualHost("broker1");
    gateway.setConnectionTimeout(5000);
    gateway.init();
    gateways.add(gateway);
    return gateway;
}
Also used : SslProtocol(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol) ArrayList(java.util.ArrayList) LoadBalancer(io.fabric8.gateway.loadbalancer.LoadBalancer) MqttProtocol(io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol) OpenwireProtocol(io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol) SslConfig(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslConfig) HttpProtocol(io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol) StompProtocol(io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol) AmqpProtocol(io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol) MqttProtocol(io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol) SslProtocol(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol) StompProtocol(io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol) AmqpProtocol(io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol) HttpProtocol(io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol) OpenwireProtocol(io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol) File(java.io.File)

Example 2 with SslConfig

use of io.fabric8.gateway.handlers.detecting.protocol.ssl.SslConfig in project fabric8 by jboss-fuse.

the class DetectingGatewayVirtualHostTest method createGateway.

public DetectingGateway createGateway() {
    String loadBalancerType = LoadBalancers.ROUND_ROBIN_LOAD_BALANCER;
    int stickyLoadBalancerCacheSize = LoadBalancers.STICKY_LOAD_BALANCER_DEFAULT_CACHE_SIZE;
    LoadBalancer serviceLoadBalancer = LoadBalancers.createLoadBalancer(loadBalancerType, stickyLoadBalancerCacheSize);
    ArrayList<Protocol> protocols = new ArrayList<Protocol>();
    protocols.add(new StompProtocol());
    protocols.add(new MqttProtocol());
    protocols.add(new AmqpProtocol());
    protocols.add(new OpenwireProtocol());
    protocols.add(new HttpProtocol());
    protocols.add(new SslProtocol());
    DetectingGateway gateway = new DetectingGateway();
    gateway.setPort(0);
    gateway.setVertx(vertx);
    SslConfig sslConfig = new SslConfig(new File(basedir(), "src/test/resources/server.ks"), "password");
    sslConfig.setKeyPassword("password");
    gateway.setSslConfig(sslConfig);
    gateway.setServiceMap(serviceMap);
    gateway.setProtocols(protocols);
    gateway.setServiceLoadBalancer(serviceLoadBalancer);
    gateway.setDefaultVirtualHost("broker");
    gateway.setConnectionTimeout(500000);
    gateway.init();
    gateways.add(gateway);
    return gateway;
}
Also used : SslProtocol(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol) ArrayList(java.util.ArrayList) LoadBalancer(io.fabric8.gateway.loadbalancer.LoadBalancer) MqttProtocol(io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol) OpenwireProtocol(io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol) SslConfig(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslConfig) HttpProtocol(io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol) StompProtocol(io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol) AmqpProtocol(io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol) MqttProtocol(io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol) SslProtocol(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol) StompProtocol(io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol) AmqpProtocol(io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol) HttpProtocol(io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol) OpenwireProtocol(io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol) File(java.io.File)

Example 3 with SslConfig

use of io.fabric8.gateway.handlers.detecting.protocol.ssl.SslConfig in project fabric8 by jboss-fuse.

the class FabricDetectingGateway method createDetectingGateway.

protected DetectingGateway createDetectingGateway() {
    DetectingGateway gateway = new DetectingGateway();
    VertxService vertxService = getVertxService();
    LoadBalancer serviceLoadBalancer = LoadBalancers.createLoadBalancer(loadBalancerType, stickyLoadBalancerCacheSize);
    gateway.setVertx(vertxService.getVertx());
    gateway.setPort(port);
    gateway.setServiceMap(serviceMap);
    gateway.setShutdownTacker(shutdownTacker);
    gateway.setServiceLoadBalancer(serviceLoadBalancer);
    gateway.setDefaultVirtualHost(defaultVirtualHost);
    ArrayList<Protocol> protocols = new ArrayList<Protocol>();
    if (isStompEnabled()) {
        protocols.add(new StompProtocol());
    }
    if (isMqttEnabled()) {
        protocols.add(new MqttProtocol());
    }
    if (isAmqpEnabled()) {
        protocols.add(new AmqpProtocol());
    }
    if (isOpenWireEnabled()) {
        protocols.add(new OpenwireProtocol());
    }
    if (isHttpEnabled()) {
        protocols.add(new HttpProtocol());
    }
    if (isSslEnabled()) {
        SslConfig sslConfig = new SslConfig();
        if (Strings.isNotBlank(sslAlgorithm)) {
            sslConfig.setAlgorithm(sslAlgorithm);
        }
        if (Strings.isNotBlank(keyAlias)) {
            sslConfig.setKeyAlias(keyAlias);
        }
        if (Strings.isNotBlank(keyPassword)) {
            sslConfig.setKeyPassword(keyPassword);
        }
        if (Strings.isNotBlank(keyStorePassword)) {
            sslConfig.setKeyStorePassword(keyStorePassword);
        }
        if (keyStoreURL != null) {
            sslConfig.setKeyStoreURL(keyStoreURL);
        }
        if (Strings.isNotBlank(sslProtocol)) {
            sslConfig.setProtocol(sslProtocol);
        }
        if (Strings.isNotBlank(sslStoreType)) {
            sslConfig.setStoreType(sslStoreType);
        }
        if (Strings.isNotBlank(trustStorePassword)) {
            sslConfig.setTrustStorePassword(trustStorePassword);
        }
        if (trustStoreURL != null) {
            sslConfig.setTrustStoreURL(trustStoreURL);
        }
        if (Strings.isNotBlank(enabledCipherSuites)) {
            sslConfig.setEnabledCipherSuites(enabledCipherSuites);
        }
        if (Strings.isNotBlank(disabledCypherSuites)) {
            sslConfig.setDisabledCypherSuites(disabledCypherSuites);
        }
        gateway.setSslConfig(sslConfig);
        // validating configuration
        try {
            SSLContext sslContext = SSLContext.getInstance(sslConfig.getProtocol());
            sslContext.init(sslConfig.getKeyManagers(), sslConfig.getTrustManagers(), null);
        } catch (Exception e) {
            throw new ComponentException(e);
        }
        protocols.add(new SslProtocol());
    }
    if (protocols.isEmpty()) {
        return null;
    }
    gateway.setProtocols(protocols);
    return gateway;
}
Also used : DetectingGateway(io.fabric8.gateway.handlers.detecting.DetectingGateway) SslProtocol(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol) VertxService(io.fabric8.gateway.fabric.support.vertx.VertxService) ArrayList(java.util.ArrayList) LoadBalancer(io.fabric8.gateway.loadbalancer.LoadBalancer) SSLContext(javax.net.ssl.SSLContext) MqttProtocol(io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol) OpenwireProtocol(io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol) ComponentException(org.osgi.service.component.ComponentException) ShutdownException(io.fabric8.common.util.ShutdownTracker.ShutdownException) SslConfig(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslConfig) HttpProtocol(io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol) StompProtocol(io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol) AmqpProtocol(io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol) ComponentException(org.osgi.service.component.ComponentException) MqttProtocol(io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol) SslProtocol(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol) StompProtocol(io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol) AmqpProtocol(io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol) HttpProtocol(io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol) OpenwireProtocol(io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol) Protocol(io.fabric8.gateway.handlers.detecting.Protocol)

Example 4 with SslConfig

use of io.fabric8.gateway.handlers.detecting.protocol.ssl.SslConfig in project fabric8 by jboss-fuse.

the class ExtendedBurnIn method startDetectingGateway.

public DetectingGateway startDetectingGateway() {
    String loadBalancerType = LoadBalancers.STICKY_LOAD_BALANCER;
    int stickyLoadBalancerCacheSize = LoadBalancers.STICKY_LOAD_BALANCER_DEFAULT_CACHE_SIZE;
    LoadBalancer serviceLoadBalancer = LoadBalancers.createLoadBalancer(loadBalancerType, stickyLoadBalancerCacheSize);
    ArrayList<Protocol> protocols = new ArrayList<Protocol>();
    protocols.add(new StompProtocol());
    protocols.add(new MqttProtocol());
    protocols.add(new AmqpProtocol());
    protocols.add(new OpenwireProtocol());
    protocols.add(new HttpProtocol());
    protocols.add(new SslProtocol());
    DetectingGateway gateway = new DetectingGateway();
    gateway.setPort(0);
    gateway.setVertx(vertx);
    SslConfig sslConfig = new SslConfig(new File(basedir(), "src/test/resources/server.ks"), "password");
    sslConfig.setKeyPassword("password");
    gateway.setSslConfig(sslConfig);
    gateway.setServiceMap(serviceMap);
    gateway.setProtocols(protocols);
    gateway.setServiceLoadBalancer(serviceLoadBalancer);
    gateway.setDefaultVirtualHost("broker1");
    gateway.setConnectionTimeout(5000);
    if (httpGatewayServer != null) {
        gateway.setHttpGateway(new InetSocketAddress("localhost", httpGatewayServer.getPort()));
    }
    gateway.init();
    gateways.add(gateway);
    return gateway;
}
Also used : DetectingGateway(io.fabric8.gateway.handlers.detecting.DetectingGateway) SslProtocol(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol) InetSocketAddress(java.net.InetSocketAddress) RoundRobinLoadBalancer(io.fabric8.gateway.loadbalancer.RoundRobinLoadBalancer) LoadBalancer(io.fabric8.gateway.loadbalancer.LoadBalancer) MqttProtocol(io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol) OpenwireProtocol(io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol) SslConfig(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslConfig) HttpProtocol(io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol) StompProtocol(io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol) AmqpProtocol(io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol) MqttProtocol(io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol) SslProtocol(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol) StompProtocol(io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol) AmqpProtocol(io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol) HttpProtocol(io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol) OpenwireProtocol(io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol) Protocol(io.fabric8.gateway.handlers.detecting.Protocol) File(java.io.File)

Example 5 with SslConfig

use of io.fabric8.gateway.handlers.detecting.protocol.ssl.SslConfig in project fabric8 by jboss-fuse.

the class DetectingGateway method handle.

public void handle(final SocketWrapper socket) {
    try {
        shutdownTracker.retain();
        if (!socketsConnecting.add(socket)) {
            throw new AssertionError("Socket existed in the socketsConnecting set");
        }
    } catch (Throwable e) {
        LOG.debug("Could not accept connection from: " + socket.remoteAddress(), e);
        socket.close();
        // shutdownTracker.release();
        return;
    }
    receivedConnectionAttempts.incrementAndGet();
    if (connectionTimeout > 0) {
        vertx.setTimer(connectionTimeout, new Handler<Long>() {

            public void handle(Long timerID) {
                if (socketsConnecting.contains(socket)) {
                    handleConnectFailure(socket, String.format("Gateway client '%s' protocol detection timeout.", socket.remoteAddress()));
                }
            }
        });
    }
    ReadStream<ReadStream> readStream = socket.readStream();
    readStream.exceptionHandler(new Handler<Throwable>() {

        @Override
        public void handle(Throwable e) {
            handleConnectFailure(socket, String.format("Failed to route gateway client '%s' due to: %s", socket.remoteAddress(), e));
        }
    });
    readStream.endHandler(new Handler<Void>() {

        @Override
        public void handle(Void event) {
            handleConnectFailure(socket, String.format("Gateway client '%s' closed the connection before it could be routed.", socket.remoteAddress()));
        }
    });
    readStream.dataHandler(new Handler<Buffer>() {

        Buffer received = new Buffer();

        {
            LOG.debug("Inititalized new Handler[{}] for socket: {}", this, socket.remoteAddress());
        }

        @Override
        public void handle(Buffer event) {
            received.appendBuffer(event);
            if (LOG.isTraceEnabled()) {
                LOG.trace("Socket received following data: {}", event.copy().toString().replaceAll("\r", " "));
                LOG.trace("Data handled by Handler {}", this.toString());
            }
            for (final Protocol protocol : protocols) {
                if (protocol.matches(received)) {
                    if ("ssl".equals(protocol.getProtocolName())) {
                        LOG.info(String.format("SSL Connection from '%s'", socket.remoteAddress()));
                        String disabledCypherSuites = null;
                        String enabledCipherSuites = null;
                        if (sslConfig != null) {
                            disabledCypherSuites = sslConfig.getDisabledCypherSuites();
                            enabledCipherSuites = sslConfig.getEnabledCipherSuites();
                        }
                        if (sslContext == null) {
                            try {
                                if (sslConfig != null) {
                                    sslContext = SSLContext.getInstance(sslConfig.getProtocol());
                                    sslContext.init(sslConfig.getKeyManagers(), sslConfig.getTrustManagers(), null);
                                } else {
                                    sslContext = SSLContext.getDefault();
                                }
                            } catch (Exception e) {
                                handleConnectFailure(socket, "Could initialize SSL: " + e);
                                return;
                            }
                        }
                        // lets wrap it up in a SslSocketWrapper.
                        SslSocketWrapper sslSocketWrapper = new SslSocketWrapper(socket);
                        sslSocketWrapper.putBackHeader(received);
                        sslSocketWrapper.initServer(sslContext, clientAuth, disabledCypherSuites, enabledCipherSuites);
                        // Undo initial connection accounting since we will be redoing @ the SSL level.
                        boolean removed = socketsConnecting.remove(socket);
                        assert removed;
                        receivedConnectionAttempts.decrementAndGet();
                        try {
                            DetectingGateway.this.handle(sslSocketWrapper);
                        } finally {
                            shutdownTracker.release();
                        }
                        return;
                    } else if ("http".equals(protocol.getProtocolName())) {
                        InetSocketAddress target = getHttpGateway();
                        if (target != null) {
                            try {
                                URI url = new URI("http://" + target.getHostString() + ":" + target.getPort());
                                LOG.info(String.format("Connecting '%s' to '%s:%d' using the http protocol", socket.remoteAddress(), url.getHost(), url.getPort()));
                                ConnectionParameters params = new ConnectionParameters();
                                params.protocol = "http";
                                createClient(params, socket, url, received);
                                return;
                            } catch (URISyntaxException e) {
                                handleConnectFailure(socket, "Could not build valid connect URI: " + e);
                                return;
                            }
                        } else {
                            handleConnectFailure(socket, "No http gateway available for the http protocol");
                            return;
                        }
                    } else {
                        protocol.snoopConnectionParameters(socket, received, new Handler<ConnectionParameters>() {

                            @Override
                            public void handle(ConnectionParameters connectionParameters) {
                                // this will install a new dataHandler on the socket.
                                if (connectionParameters.protocol == null)
                                    connectionParameters.protocol = protocol.getProtocolName();
                                if (connectionParameters.protocolSchemes == null)
                                    connectionParameters.protocolSchemes = protocol.getProtocolSchemes();
                                route(socket, connectionParameters, received);
                            }
                        });
                        return;
                    }
                }
            }
            if (received.length() >= maxProtocolIdentificationLength) {
                handleConnectFailure(socket, "Connection did not use one of the enabled protocols " + getProtocolNames());
            }
        }
    });
}
Also used : Buffer(org.vertx.java.core.buffer.Buffer) InetSocketAddress(java.net.InetSocketAddress) ConnectionParameters(io.fabric8.gateway.handlers.loadbalancer.ConnectionParameters) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) ReadStream(org.vertx.java.core.streams.ReadStream) AtomicLong(java.util.concurrent.atomic.AtomicLong) SslSocketWrapper(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslSocketWrapper)

Aggregations

AmqpProtocol (io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol)4 HttpProtocol (io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol)4 MqttProtocol (io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol)4 OpenwireProtocol (io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol)4 SslConfig (io.fabric8.gateway.handlers.detecting.protocol.ssl.SslConfig)4 SslProtocol (io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol)4 StompProtocol (io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol)4 LoadBalancer (io.fabric8.gateway.loadbalancer.LoadBalancer)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 DetectingGateway (io.fabric8.gateway.handlers.detecting.DetectingGateway)2 Protocol (io.fabric8.gateway.handlers.detecting.Protocol)2 InetSocketAddress (java.net.InetSocketAddress)2 ShutdownException (io.fabric8.common.util.ShutdownTracker.ShutdownException)1 VertxService (io.fabric8.gateway.fabric.support.vertx.VertxService)1 SslSocketWrapper (io.fabric8.gateway.handlers.detecting.protocol.ssl.SslSocketWrapper)1 ConnectionParameters (io.fabric8.gateway.handlers.loadbalancer.ConnectionParameters)1 RoundRobinLoadBalancer (io.fabric8.gateway.loadbalancer.RoundRobinLoadBalancer)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1