Search in sources :

Example 1 with ClientTlsHandler

use of io.grpc.netty.ProtocolNegotiators.ClientTlsHandler in project grpc-java by grpc.

the class ProtocolNegotiatorsTest method clientTlsHandler_closeDuringNegotiation.

@Test
public void clientTlsHandler_closeDuringNegotiation() throws Exception {
    ClientTlsHandler handler = new ClientTlsHandler(grpcHandler, sslContext, "authority", null, noopLogger);
    pipeline.addLast(new WriteBufferingAndExceptionHandler(handler));
    ChannelFuture pendingWrite = channel.writeAndFlush(NettyClientHandler.NOOP_MESSAGE);
    // SslHandler fires userEventTriggered() before channelInactive()
    pipeline.fireChannelInactive();
    assertThat(pendingWrite.cause()).isInstanceOf(StatusRuntimeException.class);
    assertThat(Status.fromThrowable(pendingWrite.cause()).getCode()).isEqualTo(Status.Code.UNAVAILABLE);
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) ClientTlsHandler(io.grpc.netty.ProtocolNegotiators.ClientTlsHandler) Test(org.junit.Test)

Example 2 with ClientTlsHandler

use of io.grpc.netty.ProtocolNegotiators.ClientTlsHandler in project grpc-java by grpc.

the class ProtocolNegotiatorsTest method clientTlsHandler_userEventTriggeredSslEvent_unsupportedProtocol.

@Test
public void clientTlsHandler_userEventTriggeredSslEvent_unsupportedProtocol() throws Exception {
    SslHandler goodSslHandler = new SslHandler(engine, false) {

        @Override
        public String applicationProtocol() {
            return "badproto";
        }
    };
    DefaultEventLoopGroup elg = new DefaultEventLoopGroup(1);
    ClientTlsHandler handler = new ClientTlsHandler(grpcHandler, sslContext, "authority", elg, noopLogger);
    pipeline.addLast(handler);
    final AtomicReference<Throwable> error = new AtomicReference<>();
    ChannelHandler errorCapture = new ChannelInboundHandlerAdapter() {

        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
            error.set(cause);
        }
    };
    pipeline.addLast(errorCapture);
    pipeline.replace(SslHandler.class, null, goodSslHandler);
    pipeline.fireUserEventTriggered(ProtocolNegotiationEvent.DEFAULT);
    channelHandlerCtx = pipeline.context(handler);
    Object sslEvent = SslHandshakeCompletionEvent.SUCCESS;
    pipeline.fireUserEventTriggered(sslEvent);
    // Bad protocol was specified, so there should be an error, (normally handled by WBAEH)
    assertThat(error.get()).hasMessageThat().contains("Unable to find compatible protocol");
    ChannelHandlerContext grpcHandlerCtx = pipeline.context(grpcHandler);
    assertNull(grpcHandlerCtx);
}
Also used : ClientTlsHandler(io.grpc.netty.ProtocolNegotiators.ClientTlsHandler) AtomicReference(java.util.concurrent.atomic.AtomicReference) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelHandler(io.netty.channel.ChannelHandler) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) SslHandler(io.netty.handler.ssl.SslHandler) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) Test(org.junit.Test)

Example 3 with ClientTlsHandler

use of io.grpc.netty.ProtocolNegotiators.ClientTlsHandler in project grpc-java by grpc.

the class ProtocolNegotiatorsTest method clientTlsHandler_userEventTriggeredSslEvent_supportedProtocolCustom.

@Test
public void clientTlsHandler_userEventTriggeredSslEvent_supportedProtocolCustom() throws Exception {
    SslHandler goodSslHandler = new SslHandler(engine, false) {

        @Override
        public String applicationProtocol() {
            return "managed_mtls";
        }
    };
    DefaultEventLoopGroup elg = new DefaultEventLoopGroup(1);
    File clientCert = TestUtils.loadCert("client.pem");
    File key = TestUtils.loadCert("client.key");
    List<String> alpnList = Arrays.asList("managed_mtls", "h2");
    ApplicationProtocolConfig apn = new ApplicationProtocolConfig(ApplicationProtocolConfig.Protocol.ALPN, ApplicationProtocolConfig.SelectorFailureBehavior.NO_ADVERTISE, ApplicationProtocolConfig.SelectedListenerFailureBehavior.ACCEPT, alpnList);
    sslContext = GrpcSslContexts.forClient().keyManager(clientCert, key).ciphers(TestUtils.preferredTestCiphers(), SupportedCipherSuiteFilter.INSTANCE).applicationProtocolConfig(apn).build();
    ClientTlsHandler handler = new ClientTlsHandler(grpcHandler, sslContext, "authority", elg, noopLogger);
    pipeline.addLast(handler);
    pipeline.replace(SslHandler.class, null, goodSslHandler);
    pipeline.fireUserEventTriggered(ProtocolNegotiationEvent.DEFAULT);
    channelHandlerCtx = pipeline.context(handler);
    Object sslEvent = SslHandshakeCompletionEvent.SUCCESS;
    pipeline.fireUserEventTriggered(sslEvent);
    ChannelHandlerContext grpcHandlerCtx = pipeline.context(grpcHandler);
    assertNotNull(grpcHandlerCtx);
}
Also used : ClientTlsHandler(io.grpc.netty.ProtocolNegotiators.ClientTlsHandler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) File(java.io.File) SslHandler(io.netty.handler.ssl.SslHandler) ApplicationProtocolConfig(io.netty.handler.ssl.ApplicationProtocolConfig) Test(org.junit.Test)

Example 4 with ClientTlsHandler

use of io.grpc.netty.ProtocolNegotiators.ClientTlsHandler in project grpc-java by grpc.

the class ProtocolNegotiatorsTest method clientTlsHandler_userEventTriggeredSslEvent_supportedProtocolH2.

@Test
public void clientTlsHandler_userEventTriggeredSslEvent_supportedProtocolH2() throws Exception {
    SslHandler goodSslHandler = new SslHandler(engine, false) {

        @Override
        public String applicationProtocol() {
            return "h2";
        }
    };
    DefaultEventLoopGroup elg = new DefaultEventLoopGroup(1);
    ClientTlsHandler handler = new ClientTlsHandler(grpcHandler, sslContext, "authority", elg, noopLogger);
    pipeline.addLast(handler);
    pipeline.replace(SslHandler.class, null, goodSslHandler);
    pipeline.fireUserEventTriggered(ProtocolNegotiationEvent.DEFAULT);
    channelHandlerCtx = pipeline.context(handler);
    Object sslEvent = SslHandshakeCompletionEvent.SUCCESS;
    pipeline.fireUserEventTriggered(sslEvent);
    ChannelHandlerContext grpcHandlerCtx = pipeline.context(grpcHandler);
    assertNotNull(grpcHandlerCtx);
}
Also used : ClientTlsHandler(io.grpc.netty.ProtocolNegotiators.ClientTlsHandler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) SslHandler(io.netty.handler.ssl.SslHandler) Test(org.junit.Test)

Aggregations

ClientTlsHandler (io.grpc.netty.ProtocolNegotiators.ClientTlsHandler)4 Test (org.junit.Test)4 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3 DefaultEventLoopGroup (io.netty.channel.DefaultEventLoopGroup)3 SslHandler (io.netty.handler.ssl.SslHandler)3 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelHandler (io.netty.channel.ChannelHandler)1 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)1 ApplicationProtocolConfig (io.netty.handler.ssl.ApplicationProtocolConfig)1 File (java.io.File)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1