问题描述
- https请求忽略证书,在4.4系统上可以正常请求,4.2以下都报异常。
-
https请求忽略证书,在4.4系统上正常请求,并返回数据,4.2及以下的系统,试过了,都报一下异常,无论真机还是模拟器。
02-25 05:33:23.591: W/System.err(6405): java.lang.RuntimeException: org.apache.harmony.security.asn1.ASN1Exception: ASN.1 UTCTime: wrong format for DER, identifier at [112]
02-25 05:33:23.591: W/System.err(6405): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:599)
02-25 05:33:23.591: W/System.err(6405): at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method)
02-25 05:33:23.591: W/System.err(6405): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:378)
02-25 05:33:23.591: W/System.err(6405): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.(OpenSSLSocketImpl.java:636)
02-25 05:33:23.591: W/System.err(6405): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.getInputStream(OpenSSLSocketImpl.java:607)
02-25 05:33:23.591: W/System.err(6405): at org.apache.http.impl.io.SocketInputBuffer.(SocketInputBuffer.java:70)
02-25 05:33:23.591: W/System.err(6405): at org.apache.http.impl.SocketHttpClientConnection.createSessionInputBuffer(SocketHttpClientConnection.java:83)
02-25 05:33:23.591: W/System.err(6405): at org.apache.http.impl.conn.DefaultClientConnection.createSessionInputBuffer(DefaultClientConnection.java:170)
02-25 05:33:23.591: W/System.err(6405): at org.apache.http.impl.SocketHttpClientConnection.bind(SocketHttpClientConnection.java:106)
02-25 05:33:23.591: W/System.err(6405): at org.apache.http.impl.conn.DefaultClientConnection.openCompleted(DefaultClientConnection.java:129)
02-25 05:33:23.591: W/System.err(6405): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:172)
02-25 05:33:23.601: W/System.err(6405): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
02-25 05:33:23.601: W/System.err(6405): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
02-25 05:33:23.601: W/System.err(6405): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
02-25 05:33:23.601: W/System.err(6405): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
02-25 05:33:23.601: W/System.err(6405): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
02-25 05:33:23.601: W/System.err(6405): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
02-25 05:33:23.601: W/System.err(6405): at com.iiordanov.bVNC.AutoLoginActivity.initSSLAllWithHttpClient(AutoLoginActivity.java:1064)
02-25 05:33:23.601: W/System.err(6405): at com.iiordanov.bVNC.AutoLoginActivity$4.run(AutoLoginActivity.java:646)
02-25 05:33:23.601: W/System.err(6405): at java.lang.Thread.run(Thread.java:856)
02-25 05:33:23.601: W/System.err(6405): Caused by: org.apache.harmony.security.asn1.ASN1Exception: ASN.1 UTCTime: wrong format for DER, identifier at [112]
02-25 05:33:23.601: W/System.err(6405): at org.apache.harmony.security.asn1.DerInputStream.readUTCTime(DerInputStream.java:135)
02-25 05:33:23.601: W/System.err(6405): at org.apache.harmony.security.asn1.ASN1UTCTime.decode(ASN1UTCTime.java:77)
02-25 05:33:23.601: W/System.err(6405): at org.apache.harmony.security.asn1.ASN1Choice.decode(ASN1Choice.java:308)
02-25 05:33:23.601: W/System.err(6405): at org.apache.harmony.security.asn1.BerInputStream.readSequence(BerInputStream.java:554)
02-25 05:33:23.601: W/System.err(6405): at org.apache.harmony.security.asn1.DerInputStream.readSequence(DerInputStream.java:105)
02-25 05:33:23.601: W/System.err(6405): at org.apache.harmony.security.asn1.ASN1Sequence.decode(ASN1Sequence.java:40)
02-25 05:33:23.601: W/System.err(6405): at org.apache.harmony.security.asn1.BerInputStream.readSequence(BerInputStream.java:554)
02-25 05:33:23.601: W/System.err(6405): at org.apache.harmony.security.asn1.DerInputStream.readSequence(DerInputStream.java:105)
02-25 05:33:23.601: W/System.err(6405): at org.apache.harmony.security.asn1.ASN1Sequence.decode(ASN1Sequence.java:40)
02-25 05:33:23.601: W/System.err(6405): at org.apache.harmony.security.asn1.BerInputStream.readSequence(BerInputStream.java:554)
02-25 05:33:23.601: W/System.err(6405): at org.apache.harmony.security.asn1.DerInputStream.readSequence(DerInputStream.java:105)
02-25 05:33:23.601: W/System.err(6405): at org.apache.harmony.security.asn1.ASN1Sequence.decode(ASN1Sequence.java:40)
02-25 05:33:23.601: W/System.err(6405): at org.apache.harmony.security.asn1.ASN1Type.decode(ASN1Type.java:82)
02-25 05:33:23.601: W/System.err(6405): at org.apache.harmony.security.provider.cert.X509CertImpl.(X509CertImpl.java:128)
02-25 05:33:23.601: W/System.err(6405): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:577)
02-25 05:33:23.601: W/System.err(6405): ... 19 more请大神赐教!如果回答能解决我的问题,C币必追加!
解决方案
看来没有合理的方案了,这个问题已解决。是服务器做了更改。既然没有人给出有效的方案,只要结贴了
解决方案二:
我的请求方法:
public String initSSLAllWithHttpClient(int what,String url) throws ClientProtocolException, IOException {
String data = "";
int status = 0;
int timeOut = 30 * 1000;
HttpParams param = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(param, timeOut);
HttpConnectionParams.setSoTimeout(param, timeOut);
HttpConnectionParams.setTcpNoDelay(param, true);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", TrustAllSSLSocketFactory.getDefault(), 443));
ClientConnectionManager manager = new ThreadSafeClientConnManager(param, registry);
DefaultHttpClient client = new DefaultHttpClient(manager, param);
HttpGet request = new HttpGet(url);
// HttpGet request = new HttpGet("https://www.alipay.com/");
String usernamePassword = loginbean.getUsername()+"@"+loginbean.getYuming_address()+":"+loginbean.getPassword();
String enToStr = "Basic"+" "+Base64.encodeToString(usernamePassword.getBytes(), Base64.NO_WRAP);
request.addHeader("Filter", "true");
request.addHeader("Authorization", enToStr);//admin@internal:abc123
request.addHeader("Content-type", "application/xml");
HttpResponse response = client.execute(request);
try{
status = response.getStatusLine().getStatusCode();
if (status / 100 == 2) {
HttpEntity entity = response.getEntity();
data = EntityUtils.toString(entity, "UTF-8");
}
Log.i("yj", "status---------"+status);
Log.i("yj", "httpurlconnection---------"+data);
}catch(Exception e){
e.printStackTrace();
Message msg = mHandler.obtainMessage(10001);
msg.arg1 = status;
msg.obj = e;
mHandler.sendMessage(msg);
}
Message msg = mHandler.obtainMessage(what);
msg.arg1 = status;
msg.obj = data;
mHandler.sendMessage(msg);
return data;
}
解决方案三:
http://blog.csdn.net/dengbodb/article/details/8281763
解决方案四:
苏小喵,感谢你的回答,只是你给的方案,报的异常跟我一模一样,我试过了,也是4.4可以通过,4.2还是报一样的异常。还是很感谢你的热心回答。
解决方案五:
苏小喵,感谢你的回答,只是你给的方案,报的异常跟我一模一样,我试过了,也是4.4可以通过,4.2还是报一样的异常。还是很感谢你的热心回答。
解决方案六:
oyljerry
oyljerry ,感谢的回答,只是我试过好几种方案,都是这样,你如果有成功的案例,希望赐教!
解决方案七:
没有忽略成功还是检查证书了