我是靠谱客的博主 忐忑煎饼,最近开发中收集的这篇文章主要介绍netty 校验_Netty SSL主机名验证支持,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

From what I can tell, there is no 'flag' or config setting I can use to enable SSL hostname verification in Netty. Examples I've seen add custom implementations using the ChannelFuture returned by SslHandler.handshake():

ChannelFuture handshakeFuture = sslHandler.handshake();

handshakeFuture.addListener(new ChannelFutureListener()

{

public void operationComplete(ChannelFuture future) throws Exception

{

if (future.isSuccess())

{

// get peer certs, verify CN (or SAN extension, or..?) against requested domain

...

I just want to make sure I'm on the right track here, and that I'm not missing a way to simply "enable" hostname verification.

解决方案

If you're using Java 7, you can do this by configuring the SSLSocket or SSLEngine to do it for you via the default trust manager. (This is independent of Netty.)

Something like this should work:

SSLContext sslContext = SSLContext.getDefault();

SSLEngine sslEngine = sslContext.createSSLEngine();

SSLParameters sslParams = new SSLParameters();

sslParams.setEndpointIdentificationAlgorithm("HTTPS");

sslEngine.setSSLParameters(sslParams);

The SSLEngine instance can be passed as an argument to the SslHandler constructor, as described in this example.

The endpoint identification algorithm can be either HTTPS or LDAP. For other protocols, the HTTPS rules should be fairly sensible.

(You can of course check that it works by connecting to that host using a wrong host name, for example using a URL with the IP address instead of the host name, assuming that the certificate doesn't contain a Subject Alternative Name IP address entry for it.)

最后

以上就是忐忑煎饼为你收集整理的netty 校验_Netty SSL主机名验证支持的全部内容,希望文章能够帮你解决netty 校验_Netty SSL主机名验证支持所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(52)

评论列表共有 0 条评论

立即
投稿
返回
顶部