Https JSSE 研究

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; } } }

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章