Search in sources :

Example 6 with ApplicationProtocolConfig

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

the class Http2Server method configureTLS.

private static SslContext configureTLS() throws CertificateException, SSLException {
    SelfSignedCertificate ssc = new SelfSignedCertificate();
    ApplicationProtocolConfig apn = new ApplicationProtocolConfig(Protocol.ALPN, // NO_ADVERTISE is currently the only mode supported by both OpenSsl and JDK providers.
    SelectorFailureBehavior.NO_ADVERTISE, // ACCEPT is currently the only mode supported by both OpenSsl and JDK providers.
    SelectedListenerFailureBehavior.ACCEPT, ApplicationProtocolNames.HTTP_2, ApplicationProtocolNames.HTTP_1_1);
    return SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey(), null).ciphers(CIPHERS, SupportedCipherSuiteFilter.INSTANCE).applicationProtocolConfig(apn).build();
}
Also used : SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) ApplicationProtocolConfig(io.netty.handler.ssl.ApplicationProtocolConfig)

Example 7 with ApplicationProtocolConfig

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

the class Http2Server method main.

public static void main(String[] args) throws Exception {
    // Configure SSL.
    final SslContext sslCtx;
    if (SSL) {
        SslProvider provider = OpenSsl.isAlpnSupported() ? SslProvider.OPENSSL : SslProvider.JDK;
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).sslProvider(provider).ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE).applicationProtocolConfig(new ApplicationProtocolConfig(Protocol.ALPN, // NO_ADVERTISE is currently the only mode supported by both OpenSsl and JDK providers.
        SelectorFailureBehavior.NO_ADVERTISE, // ACCEPT is currently the only mode supported by both OpenSsl and JDK providers.
        SelectedListenerFailureBehavior.ACCEPT, ApplicationProtocolNames.HTTP_2, ApplicationProtocolNames.HTTP_1_1)).build();
    } else {
        sslCtx = null;
    }
    // Configure the server.
    EventLoopGroup group = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.option(ChannelOption.SO_BACKLOG, 1024);
        b.group(group).channel(NioServerSocketChannel.class).handler(new LoggingHandler(LogLevel.INFO)).childHandler(new Http2ServerInitializer(sslCtx));
        Channel ch = b.bind(PORT).sync().channel();
        System.err.println("Open your HTTP/2-enabled web browser and navigate to " + (SSL ? "https" : "http") + "://127.0.0.1:" + PORT + '/');
        ch.closeFuture().sync();
    } finally {
        group.shutdownGracefully();
    }
}
Also used : LoggingHandler(io.netty.handler.logging.LoggingHandler) SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) Channel(io.netty.channel.Channel) SslProvider(io.netty.handler.ssl.SslProvider) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) SslContext(io.netty.handler.ssl.SslContext) ApplicationProtocolConfig(io.netty.handler.ssl.ApplicationProtocolConfig)

Aggregations

ApplicationProtocolConfig (io.netty.handler.ssl.ApplicationProtocolConfig)7 Channel (io.netty.channel.Channel)5 EventLoopGroup (io.netty.channel.EventLoopGroup)5 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)5 SslContext (io.netty.handler.ssl.SslContext)5 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)4 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)3 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)3 LoggingHandler (io.netty.handler.logging.LoggingHandler)3 SslProvider (io.netty.handler.ssl.SslProvider)3 Bootstrap (io.netty.bootstrap.Bootstrap)2 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)2 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)2 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)1 HttpRequest (io.netty.handler.codec.http.HttpRequest)1 HttpScheme (io.netty.handler.codec.http.HttpScheme)1 JdkSslContext (io.netty.handler.ssl.JdkSslContext)1 SslHandler (io.netty.handler.ssl.SslHandler)1 AsciiString (io.netty.util.AsciiString)1