Java1.7 access Https occur SSLProtocolException and CertificateException through SSL, and download java1.7

Source: Internet
Author: User
Tags ssl connection

Java1.7 access Https occur SSLProtocolException and CertificateException through SSL, and download java1.7


I recently called one of the Advanced Mass Sending interfaces on the public platform:

Https://file.api.weixin.qq.com/cgi-bin/media/uploadvideo? When access_token = ACCESS_TOKEN, an exception is thrown during https access:

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

Keyword: unrecognized unacknowledged name.

Google, solution, code added:

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

Call this interface again to throw a new exception:

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

Continue to process. Add the following code:

 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());
The CustomizedHostnameVerifier class is as follows:

import javax.net.ssl.HostnameVerifier;import javax.net.ssl.SSLSession;/** * HostnameVerifier * bug fixed : 

Cause:

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.

In short:

Because this interface is not authenticated, https is not secure, and all the code needs to be dont verify.



Refer:

Http://iteches.com/archives/45015

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




When you configure the android SDK in eclipse 37, Fetching https: // dl-sslgooglecom/and appears.

This problem seems to be caused by a wall.
Now you can download the sdk-r18 sdk, can be downloaded normally, if you still can not download, you can contact me, I will send you a copy
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.