Search in sources :

Example 1 with ReferenceCountedOpenSslEngine

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

the class OcspTest method testServerOcspNotEnabled.

private static void testServerOcspNotEnabled(SslProvider sslProvider) throws Exception {
    SelfSignedCertificate ssc = new SelfSignedCertificate();
    try {
        SslContext context = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).sslProvider(sslProvider).build();
        try {
            SslHandler sslHandler = context.newHandler(ByteBufAllocator.DEFAULT);
            final ReferenceCountedOpenSslEngine engine = (ReferenceCountedOpenSslEngine) sslHandler.engine();
            try {
                assertThrows(IllegalStateException.class, new Executable() {

                    @Override
                    public void execute() {
                        engine.setOcspResponse(new byte[] { 1, 2, 3 });
                    }
                });
            } finally {
                engine.release();
            }
        } finally {
            ReferenceCountUtil.release(context);
        }
    } finally {
        ssc.delete();
    }
}
Also used : ReferenceCountedOpenSslEngine(io.netty.handler.ssl.ReferenceCountedOpenSslEngine) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) Executable(org.junit.jupiter.api.function.Executable) SslHandler(io.netty.handler.ssl.SslHandler) SslContext(io.netty.handler.ssl.SslContext)

Example 2 with ReferenceCountedOpenSslEngine

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

the class OcspServerExample method newServerHandler.

private static ChannelInitializer<Channel> newServerHandler(final ReferenceCountedOpenSslContext context, final OCSPResp response) {
    return new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) throws Exception {
            SslHandler sslHandler = context.newHandler(ch.alloc());
            if (response != null) {
                ReferenceCountedOpenSslEngine engine = (ReferenceCountedOpenSslEngine) sslHandler.engine();
                engine.setOcspResponse(response.getEncoded());
            }
            ChannelPipeline pipeline = ch.pipeline();
            pipeline.addLast(sslHandler);
        // so on and so forth...
        }
    };
}
Also used : ReferenceCountedOpenSslEngine(io.netty.handler.ssl.ReferenceCountedOpenSslEngine) Channel(io.netty.channel.Channel) ChannelInitializer(io.netty.channel.ChannelInitializer) SslHandler(io.netty.handler.ssl.SslHandler) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 3 with ReferenceCountedOpenSslEngine

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

the class OcspTest method newClientHandler.

private static ChannelHandler newClientHandler(final SslContext context, final OcspClientCallback callback, final ChannelHandler handler) {
    return new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) throws Exception {
            ChannelPipeline pipeline = ch.pipeline();
            SslHandler sslHandler = context.newHandler(ch.alloc());
            ReferenceCountedOpenSslEngine engine = (ReferenceCountedOpenSslEngine) sslHandler.engine();
            pipeline.addLast(sslHandler);
            pipeline.addLast(new OcspClientCallbackHandler(engine, callback));
            if (handler != null) {
                pipeline.addLast(handler);
            }
        }
    };
}
Also used : ReferenceCountedOpenSslEngine(io.netty.handler.ssl.ReferenceCountedOpenSslEngine) LocalServerChannel(io.netty.channel.local.LocalServerChannel) LocalChannel(io.netty.channel.local.LocalChannel) Channel(io.netty.channel.Channel) ChannelInitializer(io.netty.channel.ChannelInitializer) ChannelPipeline(io.netty.channel.ChannelPipeline) SslHandler(io.netty.handler.ssl.SslHandler)

Example 4 with ReferenceCountedOpenSslEngine

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

the class OcspTest method newServerHandler.

private static ChannelHandler newServerHandler(final SslContext context, final byte[] response, final ChannelHandler handler) {
    return new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) throws Exception {
            ChannelPipeline pipeline = ch.pipeline();
            SslHandler sslHandler = context.newHandler(ch.alloc());
            if (response != null) {
                ReferenceCountedOpenSslEngine engine = (ReferenceCountedOpenSslEngine) sslHandler.engine();
                engine.setOcspResponse(response);
            }
            pipeline.addLast(sslHandler);
            if (handler != null) {
                pipeline.addLast(handler);
            }
        }
    };
}
Also used : ReferenceCountedOpenSslEngine(io.netty.handler.ssl.ReferenceCountedOpenSslEngine) LocalServerChannel(io.netty.channel.local.LocalServerChannel) LocalChannel(io.netty.channel.local.LocalChannel) Channel(io.netty.channel.Channel) ChannelInitializer(io.netty.channel.ChannelInitializer) ChannelPipeline(io.netty.channel.ChannelPipeline) SslHandler(io.netty.handler.ssl.SslHandler)

Example 5 with ReferenceCountedOpenSslEngine

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

the class OcspTest method testClientOcspNotEnabled.

private static void testClientOcspNotEnabled(SslProvider sslProvider) throws Exception {
    SslContext context = SslContextBuilder.forClient().sslProvider(sslProvider).build();
    try {
        SslHandler sslHandler = context.newHandler(ByteBufAllocator.DEFAULT);
        final ReferenceCountedOpenSslEngine engine = (ReferenceCountedOpenSslEngine) sslHandler.engine();
        try {
            assertThrows(IllegalStateException.class, new Executable() {

                @Override
                public void execute() {
                    engine.getOcspResponse();
                }
            });
        } finally {
            engine.release();
        }
    } finally {
        ReferenceCountUtil.release(context);
    }
}
Also used : ReferenceCountedOpenSslEngine(io.netty.handler.ssl.ReferenceCountedOpenSslEngine) Executable(org.junit.jupiter.api.function.Executable) SslHandler(io.netty.handler.ssl.SslHandler) SslContext(io.netty.handler.ssl.SslContext)

Aggregations

ReferenceCountedOpenSslEngine (io.netty.handler.ssl.ReferenceCountedOpenSslEngine)6 SslHandler (io.netty.handler.ssl.SslHandler)6 Channel (io.netty.channel.Channel)4 ChannelInitializer (io.netty.channel.ChannelInitializer)4 ChannelPipeline (io.netty.channel.ChannelPipeline)4 LocalChannel (io.netty.channel.local.LocalChannel)2 LocalServerChannel (io.netty.channel.local.LocalServerChannel)2 SslContext (io.netty.handler.ssl.SslContext)2 Executable (org.junit.jupiter.api.function.Executable)2 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 HttpClientCodec (io.netty.handler.codec.http.HttpClientCodec)1 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)1 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)1