Java1.7 SSL訪問Https occur SSLProtocolException and CertificateException,java1.7下載

來源:互聯網
上載者:User

Java1.7 SSL訪問Https occur SSLProtocolException and CertificateException,java1.7下載


最近在調用公眾平台進階群發介面之一:

https://file.api.weixin.qq.com/cgi-bin/media/uploadvideo?access_token=ACCESS_TOKEN 時,https訪問拋出異常:

javax.net.ssl.SSLProtocolException: handshake alert: unrecognized_name

異常中出現關鍵字:unrecognized 未被承認的name。

google之,處理辦法,代碼加入:

 //bug fiexd for: javax.net.ssl.SSLProtocolException: handshake alert: unrecognized_name System.setProperty ("jsse.enableSNIExtension", "false");

再次調用該介面,拋出新的異常:

javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: No subject alternative DNS name matching file.api.weixin.qq.com found.

繼續處理,代碼加入:

 URL url = new URL(requestUrl); httpUrlConn = (HttpsURLConnection)url.openConnection(); httpUrlConn.setSSLSocketFactory(ssf); //bug fixed for: java.security.cert.CertificateException: No subject alternative DNS name matching httpUrlConn.setHostnameVerifier(new CustomizedHostnameVerifier());
其中CustomizedHostnameVerifier類如下:

import javax.net.ssl.HostnameVerifier;import javax.net.ssl.SSLSession;/** * HostnameVerifier * bug fixed : <http://iteches.com/archives/45015> * @author will_awoke * @version 2014-8-15 * @see CustomizedHostnameVerifier * @since */public class CustomizedHostnameVerifier implements HostnameVerifier{    @Override    public boolean verify(String arg0, SSLSession arg1)    {        return true;    }}

原因:

and then apply this class to your single SSL connection
HttpsURLConnection connection = (HttpsURLConnection) new URL("
https://url").openConnection();
connection.setHostnameVerifier(new CustomizedHostNameVerifier());
or apply to all SLL connection
HttpsURLConnection.setDefaultHostnameVerifier(new CustomizedHostnameVerifier());
However this method might pose a security risk because basically we don’t verify the hostname anymore. The server may use other website’s certificate and the program will still accept it.

簡而言之:

因為的這個介面是未認證https不安全的,所有需要代碼中需要dont verify。



參考:

http://iteches.com/archives/45015

http://stackoverflow.com/questions/7615645/ssl-handshake-alert-unrecognized-name-error-since-upgrade-to-java-1-7-0




在eclipse 37中配置android SDK時,出現Fetching https://dl-sslgooglecom/and

這個問題好像是 被牆了
你現在可以去下載sdk-r18的sdk ,已經可以正常下載了,如果你還是下載不了,可以聯絡我,我發一份給你
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.