下面列出了怎么用io.netty.handler.ssl.SniHandler的API类实例代码及写法,或者点击链接到github查看源代码。
private ChannelHandler getServerHandler(
boolean requireClientCert, PrivateKey privateKey, X509Certificate certificate)
throws Exception {
SslContext sslContext =
SslContextBuilder.forServer(privateKey, certificate)
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.clientAuth(requireClientCert ? ClientAuth.REQUIRE : ClientAuth.NONE)
.build();
return new SniHandler(
hostname -> {
sniHostReceived = hostname;
return sslContext;
});
}
/**
* Determine if the {@link ChannelPipeline} is configured for SSL/TLS.
*
* @param pipeline The pipeline to check.
* @return {@code true} if the pipeline is configured to use SSL/TLS.
*/
public static boolean isSslEnabled(ChannelPipeline pipeline) {
return pipeline.get(SslHandler.class) != null || pipeline.get(SniHandler.class) != null;
}