Search in sources :

Example 46 with SslContext

use of io.netty.handler.ssl.SslContext in project grpc-java by grpc.

the class ProtocolNegotiatorsTest method tls_host.

@Test
public void tls_host() throws SSLException {
    SslContext ctx = GrpcSslContexts.forClient().build();
    TlsNegotiator negotiator = (TlsNegotiator) ProtocolNegotiators.tls(ctx, "[::1]");
    assertEquals("[::1]", negotiator.getHost());
    assertEquals(-1, negotiator.getPort());
}
Also used : TlsNegotiator(io.grpc.netty.ProtocolNegotiators.TlsNegotiator) SslContext(io.netty.handler.ssl.SslContext) Test(org.junit.Test)

Example 47 with SslContext

use of io.netty.handler.ssl.SslContext in project grpc-java by grpc.

the class NettyClientTransportTest method newNegotiator.

private ProtocolNegotiator newNegotiator() throws IOException {
    File clientCert = TestUtils.loadCert("ca.pem");
    SslContext clientContext = GrpcSslContexts.forClient().trustManager(clientCert).ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE).build();
    return ProtocolNegotiators.tls(clientContext, authority);
}
Also used : File(java.io.File) SslContext(io.netty.handler.ssl.SslContext)

Example 48 with SslContext

use of io.netty.handler.ssl.SslContext in project netty by netty.

the class SocketSslGreetingTest method data.

@Parameters(name = "{index}: serverEngine = {0}, clientEngine = {1}")
public static Collection<Object[]> data() throws Exception {
    List<SslContext> serverContexts = new ArrayList<SslContext>();
    serverContexts.add(SslContextBuilder.forServer(CERT_FILE, KEY_FILE).sslProvider(SslProvider.JDK).build());
    List<SslContext> clientContexts = new ArrayList<SslContext>();
    clientContexts.add(SslContextBuilder.forClient().sslProvider(SslProvider.JDK).trustManager(CERT_FILE).build());
    boolean hasOpenSsl = OpenSsl.isAvailable();
    if (hasOpenSsl) {
        serverContexts.add(SslContextBuilder.forServer(CERT_FILE, KEY_FILE).sslProvider(SslProvider.OPENSSL).build());
        clientContexts.add(SslContextBuilder.forClient().sslProvider(SslProvider.OPENSSL).trustManager(CERT_FILE).build());
    } else {
        logger.warn("OpenSSL is unavailable and thus will not be tested.", OpenSsl.unavailabilityCause());
    }
    List<Object[]> params = new ArrayList<Object[]>();
    for (SslContext sc : serverContexts) {
        for (SslContext cc : clientContexts) {
            params.add(new Object[] { sc, cc });
        }
    }
    return params;
}
Also used : ArrayList(java.util.ArrayList) SslContext(io.netty.handler.ssl.SslContext) Parameters(org.junit.runners.Parameterized.Parameters)

Example 49 with SslContext

use of io.netty.handler.ssl.SslContext in project netty by netty.

the class SocketStartTlsTest method data.

@Parameters(name = "{index}: serverEngine = {0}, clientEngine = {1}")
public static Collection<Object[]> data() throws Exception {
    List<SslContext> serverContexts = new ArrayList<SslContext>();
    serverContexts.add(SslContextBuilder.forServer(CERT_FILE, KEY_FILE).sslProvider(SslProvider.JDK).build());
    List<SslContext> clientContexts = new ArrayList<SslContext>();
    clientContexts.add(SslContextBuilder.forClient().sslProvider(SslProvider.JDK).trustManager(CERT_FILE).build());
    boolean hasOpenSsl = OpenSsl.isAvailable();
    if (hasOpenSsl) {
        serverContexts.add(SslContextBuilder.forServer(CERT_FILE, KEY_FILE).sslProvider(SslProvider.OPENSSL).build());
        clientContexts.add(SslContextBuilder.forClient().sslProvider(SslProvider.OPENSSL).trustManager(CERT_FILE).build());
    } else {
        logger.warn("OpenSSL is unavailable and thus will not be tested.", OpenSsl.unavailabilityCause());
    }
    List<Object[]> params = new ArrayList<Object[]>();
    for (SslContext sc : serverContexts) {
        for (SslContext cc : clientContexts) {
            params.add(new Object[] { sc, cc });
        }
    }
    return params;
}
Also used : ArrayList(java.util.ArrayList) SslContext(io.netty.handler.ssl.SslContext) Parameters(org.junit.runners.Parameterized.Parameters)

Example 50 with SslContext

use of io.netty.handler.ssl.SslContext in project netty by netty.

the class SocketSslClientRenegotiateTest method data.

@Parameters(name = "{index}: serverEngine = {0}, clientEngine = {1}")
public static Collection<Object[]> data() throws Exception {
    List<SslContext> serverContexts = new ArrayList<SslContext>();
    List<SslContext> clientContexts = new ArrayList<SslContext>();
    clientContexts.add(new JdkSslClientContext(CERT_FILE));
    boolean hasOpenSsl = OpenSsl.isAvailable();
    if (hasOpenSsl) {
        OpenSslServerContext context = new OpenSslServerContext(CERT_FILE, KEY_FILE);
        context.setRejectRemoteInitiatedRenegotiation(true);
        serverContexts.add(context);
    } else {
        logger.warn("OpenSSL is unavailable and thus will not be tested.", OpenSsl.unavailabilityCause());
    }
    List<Object[]> params = new ArrayList<Object[]>();
    for (SslContext sc : serverContexts) {
        for (SslContext cc : clientContexts) {
            for (int i = 0; i < 32; i++) {
                params.add(new Object[] { sc, cc });
            }
        }
    }
    return params;
}
Also used : JdkSslClientContext(io.netty.handler.ssl.JdkSslClientContext) OpenSslServerContext(io.netty.handler.ssl.OpenSslServerContext) ArrayList(java.util.ArrayList) SslContext(io.netty.handler.ssl.SslContext) Parameters(org.junit.runners.Parameterized.Parameters)

Aggregations

SslContext (io.netty.handler.ssl.SslContext)68 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)41 EventLoopGroup (io.netty.channel.EventLoopGroup)38 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)24 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)23 LoggingHandler (io.netty.handler.logging.LoggingHandler)22 Channel (io.netty.channel.Channel)21 SocketChannel (io.netty.channel.socket.SocketChannel)20 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)19 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)19 Bootstrap (io.netty.bootstrap.Bootstrap)17 File (java.io.File)14 ChannelFuture (io.netty.channel.ChannelFuture)13 ChannelPipeline (io.netty.channel.ChannelPipeline)13 Test (org.junit.Test)10 SslContextBuilder (io.netty.handler.ssl.SslContextBuilder)8 LengthFieldBasedFrameDecoder (io.netty.handler.codec.LengthFieldBasedFrameDecoder)6 ApplicationProtocolConfig (io.netty.handler.ssl.ApplicationProtocolConfig)5 EpollEventLoopGroup (io.netty.channel.epoll.EpollEventLoopGroup)4 SslHandler (io.netty.handler.ssl.SslHandler)4