Android应用程序中的SSL没有对等证书错误

时间:2015-10-23 12:09:44

标签: java android ssl https ssl-certificate

我正在开发使用SSL连接到HTTPS的应用程序。

我的代码

    HttpParams params = new BasicHttpParams();
 ClientConnectionManager connectionManager = null;
 try {
 KeyStore trustStore = KeyStore.getInstance(KeyStore
 .getDefaultType());
 trustStore.load(null, null);
 SchemeRegistry registry = new SchemeRegistry();
 SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
  sf.setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
registry.register(new Scheme("http", PlainSocketFactory
 .getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
connectionManager = new SingleClientConnManager(params, registry);
}
catch (Exception e) {
Log.e(TAG, Log.getStackTraceString(e));
}
DefaultHttpClient client = null;
HttpGet httpget = new HttpGet(url);
HttpResponse response = client.execute(httpget);

当我调用client.execute()方法时,我收到此错误,

    10-23 11:22:33.316: E/iPOLiS_SDK(5338): IOException
 10-23 11:22:33.321: E/iPOLiS_SDK(5338):       javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
 10-23 11:22:33.321: E/iPOLiS_SDK(5338):  at com.android.org.conscrypt.SSLNullSession.getPeerCertificates(SSLNullSession.java:104)
10-23 11:22:33.321: E/iPOLiS_SDK(5338):  at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:93)
10-23 11:22:33.321: E/iPOLiS_SDK(5338):  at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:388)
10-23 11:22:33.321: E/iPOLiS_SDK(5338):  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:214)
10-23 11:22:33.321: E/iPOLiS_SDK(5338):  at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:167)
10-23 11:22:33.321: E/iPOLiS_SDK(5338):  at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:125)
10-23 11:22:33.321: E/iPOLiS_SDK(5338):  at org.apache.http.impl.client.DefaultRequestDirector.executeOriginal(DefaultRequestDirector.java:1288)
10-23 11:22:33.321: E/iPOLiS_SDK(5338):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:700)
10-23 11:22:33.321: E/iPOLiS_SDK(5338):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:691)
10-23 11:22:33.321: E/iPOLiS_SDK(5338):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:514)
10-23 11:22:33.321: E/iPOLiS_SDK(5338):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:492)
10-23 11:22:33.321: E/iPOLiS_SDK(5338):  at com.samsung.techwin.ipolis.control.AbstractHttpController.query(AbstractHttpController.java:272)
10-23 11:22:33.321: E/iPOLiS_SDK(5338):  at com.samsung.techwin.ipolis.control.AbstractSingleCameraController$1.run(AbstractSingleCameraController.java:61)
10-23 11:22:33.321: E/iPOLiS_SDK(5338):  at java.lang.Thread.run(Thread.java:818)

仅在连接到某些HTTPS请求时才会发生。 但我无法理解如何纠正这个错误。

如果我做错了,请支持了解原因或代码

0 个答案:

没有答案