Search in sources :

Example 1 with ServerTlsHandler

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

the class ProtocolNegotiatorsTest method engineLog.

@Test
public void engineLog() {
    ChannelHandler handler = new ServerTlsHandler(sslContext, grpcHandler);
    pipeline.addLast(handler);
    channelHandlerCtx = pipeline.context(handler);
    Logger logger = Logger.getLogger(ProtocolNegotiators.class.getName());
    Filter oldFilter = logger.getFilter();
    try {
        logger.setFilter(new Filter() {

            @Override
            public boolean isLoggable(LogRecord record) {
                // We still want to the log method to be exercised, just not printed to stderr.
                return false;
            }
        });
        ProtocolNegotiators.logSslEngineDetails(Level.INFO, channelHandlerCtx, "message", new Exception("bad"));
    } finally {
        logger.setFilter(oldFilter);
    }
}
Also used : Filter(java.util.logging.Filter) SupportedCipherSuiteFilter(io.netty.handler.ssl.SupportedCipherSuiteFilter) LogRecord(java.util.logging.LogRecord) ServerTlsHandler(io.grpc.netty.ProtocolNegotiators.ServerTlsHandler) ChannelHandler(io.netty.channel.ChannelHandler) Logger(java.util.logging.Logger) SSLException(javax.net.ssl.SSLException) ExpectedException(org.junit.rules.ExpectedException) Test(org.junit.Test)

Example 2 with ServerTlsHandler

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

the class ProtocolNegotiatorsTest method tlsHandler_handlerAddedAddsSslHandler.

@Test
public void tlsHandler_handlerAddedAddsSslHandler() throws Exception {
    ChannelHandler handler = new ServerTlsHandler(sslContext, grpcHandler);
    pipeline.addLast(handler);
    assertTrue(pipeline.first() instanceof SslHandler);
}
Also used : ServerTlsHandler(io.grpc.netty.ProtocolNegotiators.ServerTlsHandler) ChannelHandler(io.netty.channel.ChannelHandler) SslHandler(io.netty.handler.ssl.SslHandler) Test(org.junit.Test)

Example 3 with ServerTlsHandler

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

the class ProtocolNegotiatorsTest method tlsHandler_userEventTriggeredSslEvent_supportedProtocolGrpcExp.

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

        @Override
        public String applicationProtocol() {
            return "grpc-exp";
        }
    };
    ChannelHandler handler = new ServerTlsHandler(sslContext, grpcHandler);
    pipeline.addLast(handler);
    pipeline.replace(SslHandler.class, null, goodSslHandler);
    channelHandlerCtx = pipeline.context(handler);
    Object sslEvent = SslHandshakeCompletionEvent.SUCCESS;
    pipeline.fireUserEventTriggered(sslEvent);
    assertTrue(channel.isOpen());
    ChannelHandlerContext grpcHandlerCtx = pipeline.context(grpcHandler);
    assertNotNull(grpcHandlerCtx);
}
Also used : ServerTlsHandler(io.grpc.netty.ProtocolNegotiators.ServerTlsHandler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelHandler(io.netty.channel.ChannelHandler) SslHandler(io.netty.handler.ssl.SslHandler) Test(org.junit.Test)

Example 4 with ServerTlsHandler

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

the class ProtocolNegotiatorsTest method tlsHandler_userEventTriggeredSslEvent_unsupportedProtocol.

@Test
public void tlsHandler_userEventTriggeredSslEvent_unsupportedProtocol() throws Exception {
    SslHandler badSslHandler = new SslHandler(engine, false) {

        @Override
        public String applicationProtocol() {
            return "badprotocol";
        }
    };
    ChannelHandler handler = new ServerTlsHandler(sslContext, grpcHandler);
    pipeline.addLast(handler);
    pipeline.replace(SslHandler.class, null, badSslHandler);
    channelHandlerCtx = pipeline.context(handler);
    Object sslEvent = SslHandshakeCompletionEvent.SUCCESS;
    pipeline.fireUserEventTriggered(sslEvent);
    // No h2 protocol was specified, so this should be closed.
    assertFalse(channel.isOpen());
    ChannelHandlerContext grpcHandlerCtx = pipeline.context(grpcHandler);
    assertNull(grpcHandlerCtx);
}
Also used : ServerTlsHandler(io.grpc.netty.ProtocolNegotiators.ServerTlsHandler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelHandler(io.netty.channel.ChannelHandler) SslHandler(io.netty.handler.ssl.SslHandler) Test(org.junit.Test)

Example 5 with ServerTlsHandler

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

the class ProtocolNegotiatorsTest method tlsHandler_userEventTriggeredSslEvent_supportedProtocolH2.

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

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

Aggregations

ServerTlsHandler (io.grpc.netty.ProtocolNegotiators.ServerTlsHandler)8 ChannelHandler (io.netty.channel.ChannelHandler)8 Test (org.junit.Test)8 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)5 SslHandler (io.netty.handler.ssl.SslHandler)4 SSLException (javax.net.ssl.SSLException)2 ExpectedException (org.junit.rules.ExpectedException)2 SslHandshakeCompletionEvent (io.netty.handler.ssl.SslHandshakeCompletionEvent)1 SupportedCipherSuiteFilter (io.netty.handler.ssl.SupportedCipherSuiteFilter)1 Filter (java.util.logging.Filter)1 LogRecord (java.util.logging.LogRecord)1 Logger (java.util.logging.Logger)1