有关我的应用的详细信息:
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "My application id"
minSdkVersion 13
targetSdkVersion 22
versionCode 4
versionName "2"
}
我正在使用HttpsURLConnection进行登录身份验证。但是现在我正面临 javax.net.ssl.SSLHandshakeException:javax.net.ssl.SSLProtocolException ,这也是在android lollipop.Authentication下运行的设备上正在运行操作系统版本的设备上正常运行5.请告诉我您对此问题的建议。
以下是我正在使用的代码:
HttpsURLConnection conn = null;
try {
URL url = new URL("URL to my application");
String authStr = username + ":" + password;
String authEncoded = Base64.encodeToString(authStr.getBytes(), Base64.NO_WRAP);
conn = (HttpsURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Authorization", "Basic " + authEncoded);
conn.setDoOutput(true);
conn.setConnectTimeout(120000);
int code = conn.getResponseCode();
if(code ==200){
for(int i=0;i<conn.getHeaderFields().size();i++){
String value = conn.getHeaderField(i);
HeaderElement headerElement = BasicHeaderValueParser.parseHeaderElement(value, new BasicHeaderValueParser());
if(headerElement.getName().equals("SMSESSION")){
cookieString = SMSESSION+"="+headerElement.getValue();
Log.d("validhdvaluelogin",cookieString);
cookieeditor.putString(ArticleListActivity.CURRENT_COOKIE,
cookieString);
cookieeditor.apply();
return true;
}
}
}else {
return false;
}
}
catch (Exception e) {
e.printStackTrace();
return false;
}
if (conn != null) {
conn.disconnect();
}
return false;
以下是例外:
javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL
handshake aborted: ssl=0xb87b0350: Failure in SSL library, usually a
protocol error
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake
failure (external/openssl/ssl/s23_clnt.c:741 0xa9092990:0x00000000)
at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:448)
at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.<init>(OpenSSLSocketImpl.java:661)
at com.android.org.conscrypt.OpenSSLSocketImpl.getInputStream(OpenSSLSocketImpl.java:632)
at org.apache.http.impl.io.SocketInputBuffer.<init>(SocketInputBuffer.java:70)
at org.apache.http.impl.SocketHttpClientConnection.createSessionInputBuffer(SocketHttpClientConnection.java:83)
at org.apache.http.impl.conn.DefaultClientConnection.createSessionInputBuffer(DefaultClientConnection.java:170)
at org.apache.http.impl.SocketHttpClientConnection.bind(SocketHttpClientConnection.java:106)
at org.apache.http.impl.conn.DefaultClientConnection.openCompleted(DefaultClientConnection.java:129)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:172)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
at com.ericsson.labs.it.infoservicemx.network.AuthComm.login(AuthComm.java:148)
at com.ericsson.labs.it.infoservicemx.LoginActivity$UserLoginTask.doInBackground(LoginActivity.java:312)
at com.ericsson.labs.it.infoservicemx.LoginActivity$UserLoginTask.doInBackground(LoginActivity.java:230)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb87b0350: Failure in SSL library, usually a protocol error
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure (external/openssl/ssl/s23_clnt.c:741 0xa9092990:0x00000000)
at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:405)
... 23 more
答案 0 :(得分:2)
我终于找到了解决问题的方法。 通过使用NetCipher库进行httpsurlconnection。 而不是使用:
HttpsUrlConnection conn = (HttpsURLConnection) url.openConnection();
使用:
HttpsUrlConnection conn = NetCipher.getHttpsURLConnection(url);
这解决了我的SSLv3握手问题。