Search in sources :

Example 6 with SSLOption

use of io.servicecomb.foundation.ssl.SSLOption in project java-chassis by ServiceComb.

the class TcpServer method init.

public void init(Vertx vertx, String sslKey, AsyncResultCallback<InetSocketAddress> callback) {
    NetServer netServer;
    if (endpointObject.isSslEnabled()) {
        SSLOptionFactory factory = SSLOptionFactory.createSSLOptionFactory(sslKey, null);
        SSLOption sslOption;
        if (factory == null) {
            sslOption = SSLOption.buildFromYaml(sslKey);
        } else {
            sslOption = factory.createSSLOption();
        }
        SSLCustom sslCustom = SSLCustom.createSSLCustom(sslOption.getSslCustomClass());
        NetServerOptions serverOptions = new NetServerOptions();
        VertxTLSBuilder.buildNetServerOptions(sslOption, sslCustom, serverOptions);
        netServer = vertx.createNetServer(serverOptions);
    } else {
        netServer = vertx.createNetServer();
    }
    netServer.connectHandler(netSocket -> {
        TcpServerConnection connection = createTcpServerConnection();
        connection.init(netSocket);
    });
    InetSocketAddress socketAddress = endpointObject.getSocketAddress();
    netServer.listen(socketAddress.getPort(), socketAddress.getHostString(), ar -> {
        if (ar.succeeded()) {
            callback.success(socketAddress);
            return;
        }
        String msg = String.format("listen failed, address=%s", socketAddress.toString());
        callback.fail(new Exception(msg, ar.cause()));
    });
}
Also used : SSLOptionFactory(io.servicecomb.foundation.ssl.SSLOptionFactory) InetSocketAddress(java.net.InetSocketAddress) NetServerOptions(io.vertx.core.net.NetServerOptions) NetServer(io.vertx.core.net.NetServer) SSLOption(io.servicecomb.foundation.ssl.SSLOption) SSLCustom(io.servicecomb.foundation.ssl.SSLCustom)

Example 7 with SSLOption

use of io.servicecomb.foundation.ssl.SSLOption in project java-chassis by ServiceComb.

the class TestVertxTLSBuilder method testbuildClientOptionsBaseAuthPeerFalse.

@Test
public void testbuildClientOptionsBaseAuthPeerFalse() {
    SSLOption option = SSLOption.buildFromYaml("rest.consumer");
    SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass());
    HttpClientOptions serverOptions = new HttpClientOptions();
    new MockUp<SSLOption>() {

        @Mock
        public boolean isAuthPeer() {
            return false;
        }
    };
    VertxTLSBuilder.buildClientOptionsBase(option, custom, serverOptions);
    Assert.assertEquals(serverOptions.getEnabledSecureTransportProtocols().toArray().length, 1);
    Assert.assertEquals(serverOptions.isTrustAll(), true);
}
Also used : MockUp(mockit.MockUp) SSLOption(io.servicecomb.foundation.ssl.SSLOption) SSLCustom(io.servicecomb.foundation.ssl.SSLCustom) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Test(org.junit.Test)

Example 8 with SSLOption

use of io.servicecomb.foundation.ssl.SSLOption in project java-chassis by ServiceComb.

the class TestVertxTLSBuilder method testbuildHttpClientOptions.

@Test
public void testbuildHttpClientOptions() {
    SSLOption option = SSLOption.buildFromYaml("rest.consumer");
    SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass());
    HttpClientOptions serverOptions = new HttpClientOptions();
    VertxTLSBuilder.buildHttpClientOptions(option, custom, serverOptions);
    Assert.assertEquals(serverOptions.getEnabledSecureTransportProtocols().toArray().length, 1);
    Assert.assertEquals(serverOptions.isTrustAll(), true);
}
Also used : SSLOption(io.servicecomb.foundation.ssl.SSLOption) SSLCustom(io.servicecomb.foundation.ssl.SSLCustom) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Test(org.junit.Test)

Example 9 with SSLOption

use of io.servicecomb.foundation.ssl.SSLOption in project java-chassis by ServiceComb.

the class TestVertxTLSBuilder method testbuildClientOptionsBaseSTORE_PKCS12.

@Test
public void testbuildClientOptionsBaseSTORE_PKCS12() {
    SSLOption option = SSLOption.buildFromYaml("rest.consumer");
    SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass());
    HttpClientOptions serverOptions = new HttpClientOptions();
    new MockUp<SSLOption>() {

        @Mock
        public String getTrustStoreType() {
            return "PKCS12";
        }
    };
    VertxTLSBuilder.buildClientOptionsBase(option, custom, serverOptions);
    Assert.assertEquals(serverOptions.getEnabledSecureTransportProtocols().toArray().length, 1);
    Assert.assertEquals(serverOptions.isTrustAll(), true);
}
Also used : MockUp(mockit.MockUp) SSLOption(io.servicecomb.foundation.ssl.SSLOption) SSLCustom(io.servicecomb.foundation.ssl.SSLCustom) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Test(org.junit.Test)

Example 10 with SSLOption

use of io.servicecomb.foundation.ssl.SSLOption in project java-chassis by ServiceComb.

the class TestVertxTLSBuilder method testbuildClientOptionsBase.

@Test
public void testbuildClientOptionsBase() {
    SSLOption option = SSLOption.buildFromYaml("rest.consumer");
    SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass());
    HttpClientOptions serverOptions = new HttpClientOptions();
    VertxTLSBuilder.buildClientOptionsBase(option, custom, serverOptions);
    Assert.assertEquals(serverOptions.getEnabledSecureTransportProtocols().toArray().length, 1);
    Assert.assertEquals(serverOptions.isTrustAll(), true);
}
Also used : SSLOption(io.servicecomb.foundation.ssl.SSLOption) SSLCustom(io.servicecomb.foundation.ssl.SSLCustom) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Test(org.junit.Test)

Aggregations

SSLCustom (io.servicecomb.foundation.ssl.SSLCustom)13 SSLOption (io.servicecomb.foundation.ssl.SSLOption)13 Test (org.junit.Test)8 HttpClientOptions (io.vertx.core.http.HttpClientOptions)7 SSLOptionFactory (io.servicecomb.foundation.ssl.SSLOptionFactory)5 MockUp (mockit.MockUp)4 HttpServerOptions (io.vertx.core.http.HttpServerOptions)3 TcpClientConfig (io.servicecomb.foundation.vertx.client.tcp.TcpClientConfig)1 NetServer (io.vertx.core.net.NetServer)1 NetServerOptions (io.vertx.core.net.NetServerOptions)1 InetSocketAddress (java.net.InetSocketAddress)1