android - android Javax.net. ssl.SSLHandshakeException: Javax.net. ssl.SSLProtocolException: 在SSL库中,通常会出现协议错误,SSL握手中止:失败

  显示原文与译文双语对照的内容
94 0

我正在尝试在android中运行以下代码


URLConnection l_connection = null;


//Create connection


 uzip=new UnZipData(mContext);


 l_url = new URL(serverurl);



 if ("https".equals(l_url.getProtocol())) {


 System.out.println("<<<<<<<<<<< <<Before TLS>> >>>>>>>>>>");


 sslcontext = SSLContext.getInstance("TLS");


 System.out.println("<<<<<<<<<<< <<After TLS>> >>>>>>>>>>");


 sslcontext.init(null,


 new TrustManager[] { new CustomTrustManager()},


 new java.security.SecureRandom());


 HttpsURLConnection


. setDefaultHostnameVerifier(new CustomHostnameVerifier());


 HttpsURLConnection.setDefaultSSLSocketFactory(sslcontext


. getSocketFactory());



 l_connection = (HttpsURLConnection) l_url.openConnection();


 ((HttpsURLConnection) l_connection).setRequestMethod("POST");


 } else {


 l_connection = (HttpURLConnection) l_url.openConnection();


 ((HttpURLConnection) l_connection).setRequestMethod("POST");


 }


/*System.setProperty("http.agent","Android_Phone");*/



 l_connection.setConnectTimeout(10000);


 l_connection.setRequestProperty("Content-Language","en-US");


 l_connection.setUseCaches(false);


 l_connection.setDoInput(true);


 l_connection.setDoOutput(true);


 System.out.println("<<<<<<<<<<< <<Before Connection>> >>>>>>>>>>");


 l_connection.connect();



l_connection.connect() 上,它给了这个 SSLhandshakeException 。 有时它是有效的,但大多数时候它会给出异常。 它只在 模拟器 4.0上发生。 我在安卓 4.4和 5.0上做了测试,。 这是什么原因导致? 请帮助

Stacktrace


 04-28 15:51:13.143: W/System.err(2915): javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x870c918: Failure in SSL library, usually a protocol error


04-28 15:51:13.143: W/System.err(2915): error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:658 0xb7c393a1:0x00000000)


04-28 15:51:13.143: W/System.err(2915): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:460)


04-28 15:51:13.143: W/System.err(2915): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:257)


04-28 15:51:13.143: W/System.err(2915): at libcore.net.http.HttpConnection.setupSecureSocket(HttpConnection.java:210)


04-28 15:51:13.143: W/System.err(2915): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:477)


04-28 15:51:13.153: W/System.err(2915): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:441)


04-28 15:51:13.153: W/System.err(2915): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)


04-28 15:51:13.153: W/System.err(2915): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)


04-28 15:51:13.153: W/System.err(2915): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)


04-28 15:51:13.153: W/System.err(2915): at libcore.net.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:164)


04-28 15:51:13.153: W/System.err(2915): at com.ofss.fcdb.mobile.android.rms.helpers.NetworkConnector.getConnection(NetworkConnector.java:170)


04-28 15:51:13.153: W/System.err(2915): at com.ofss.fcdb.mobile.android.rms.util.InitiateRMS$2.run(InitiateRMS.java:221)


04-28 15:51:13.153: W/System.err(2915): at java.lang.Thread.run(Thread.java:856)


04-28 15:51:13.153: W/System.err(2915): Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x870c918: Failure in SSL library, usually a protocol error


04-28 15:51:13.153: W/System.err(2915): error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:658 0xb7c393a1:0x00000000)


04-28 15:51:13.153: W/System.err(2915): at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method)


04-28 15:51:13.153: W/System.err(2915): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:410)


04-28 15:51:13.153: W/System.err(2915):. . . 11 more


04-28 16:42:44.139: W/ResourceType(3140): No package identifier when getting value for resource number 0x00000000



时间: 原作者:

...