Https JSSE 研究

本文详细介绍了SSLSession的相关方法,如获取加密套件、证书信息等,并深入探讨了HttpsURLConnection的配置选项,包括自定义验证器和SSL套接字工厂。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、SSLSession

          SSLSession.getCIpherSuite()返回(String)在这个session中所有的连接使用的加密函数(cipher suite)

       

          SSLSession.getCreationTime()返回一个Long类型的数据,代表SSLSession创建的时间

 

          SSLSession.getId()返回代表Session对象的一个字节数组

  

          SSLSession.getLastAccessedTime()返回Long类型的数据,

 

SSLSession.getLocalCertificates()返回一个将要发送到对方的本地证书链

SSLSession.getLocalPrincipal()返回代表该端的一个证书

SSLSession.getPeerCertificates()返回对方的证书链

SSLSession.getPeerHost()返回对方的hostname或者ip地址

SSLSession.getPeerPort()返回对方的端口号

SSLSession。getProtocol()返回这个session中所有的连接使用的协议

SSLSession.invalidate(),使session无效,以后的连接不能再使用,但是之前的连接可以继续使用知道连接关闭
SSLSession.isValid(),如果可以恢复或者加入一个连接,返回true

 

2、HttpsURLConnection

set DefaultHostnameVerifier(),可以设置自己的验证类,继承HostnameVerifier接口,实现其中public boolean verify(String hostname, SSLSession session);方法

HostnameVerifier是当调用connect()方法,用来验证服务器主机名是否符合证书中CN项(默认的)。

HttpsURLConnection.setSSLSocketFactory(),可以设置自定义的 SSLSocketFactory类,setSSLSocketFactory(), which can be used to pass your own SSLSocketFactory for the SSLContext you want to use. After the set() method is called, any calls to connect() will use the new SSLSocketFactory object.
HttpsURLConnection.set DefaultSSLSocketFactory(),设置成功后,一个新的HttpsURLConnection实例将会产生

 

private static class Validator implements HostnameVerifier { public boolean verify(String hostName, SSLSession session) { try { X500Principal hostID = (X500Principal)session.getPeerPrincipal(); return hostID.getName().equals("CN=Test CA Certificate"); } catch (Exception e) { return false; } } }

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值