javax.net.ssl.SSLException: Not trusted server certificate .
来源:互联网 发布:数据加密保密性 编辑:程序博客网 时间:2024/06/05 22:39
今天写项目遇到:
05-13 02:54:19.636: WARN/System.err(294): javax.net.ssl.SSLException: Not trusted server certificate
at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:360)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.getSecureSocket(HttpConnection.java:168)
at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection$HttpsEngine.connect(HttpsURLConnection.java:398)
at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection.connect(HttpsURLConnection.java:146)
at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:75)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:136)
at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:90)
at com.ceosoft.acemetrix.wsdl.WSDLClient.MakeCall(WSDLClient.java:130)
at com.ceosoft.acemetrix.wsdl.WSDLClient.InvokeMethod(WSDLClient.java:108)
at com.ceosoft.acemetrix.wsdl.WSDLClient.getDailyTop5(WSDLClient.java:146)
at com.ceosoft.acemetrix.data.manager.DataManager$1.launch(DataManager.java:144)
at com.ceosoft.acemetrix.data.DataTask.doInBackground(DataTask.java:74)
at com.ceosoft.acemetrix.data.DataTask.doInBackground(DataTask.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:185)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
at java.lang.Thread.run(Thread.java:1096)
Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: TrustAnchor for CertPath not found.
at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:168)
at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:355)
... 18 more
Caused by: java.security.cert.CertPathValidatorException: TrustAnchor for CertPath not found.
at org.bouncycastle.jce.provider.PKIXCertPathValidatorSpi.engineValidate(PKIXCertPathValidatorSpi.java:149)
at java.security.cert.CertPathValidator.validate(CertPathValidator.java:211)
at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:164)
... 19 more
-----------------------------------------------------------------------------------------------------
找了一些参考资料:
http://stackoverflow.com/questions/995514/https-connection-android#1000205
http://groups.google.com/group/android-developers/browse_thread/thread/62d856cdcfa9f16e/dd59b1998d23a660?lnk=gst&q=SSL+fake+cert#dd59b1998d23a660
------------------------------------------------------------------------------------------------
得到结论:
call allowAllSSL() before you do any SSL communication/call to ksoap2. It will register a new default HostnameVerifier and TrustManager. ksoap2, when doing its SSL communication, will use the default ones and it works like a charm.
-------------------------------------------------------------------------------------------------
解决方法:
在项目中添加类:
public class _FakeX509TrustManager implements X509TrustManager {
private static TrustManager[] trustManagers;
private static final X509Certificate[] _AcceptedIssuers = new
X509Certificate[] {};
@Override
public void checkClientTrusted(X509Certificate[] chain, String
authType) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String
authType) throws CertificateException {
}
public boolean isClientTrusted(X509Certificate[] chain) {
return true;
}
public boolean isServerTrusted(X509Certificate[] chain) {
return true;
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return _AcceptedIssuers;
}
public static void allowAllSSL() {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier()
{
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
SSLContext context = null;
if (trustManagers == null) {
trustManagers = new TrustManager[] { new _FakeX509TrustManager() };
}
try {
context = SSLContext.getInstance("TLS");
context.init(null, trustManagers, new SecureRandom());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
}
}
--------------然后在:
调用:
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
_FakeX509TrustManager.allowAllSSL();// solution:javax.net.ssl.SSLException: Not trusted server certificate
androidHttpTransport.call(soap_action, Envelope);
SoapObject response = (SoapObject)Envelope.getResponse();
return response;
}
catch(Exception e)
{
e.printStackTrace();
}
return null;
原文地址:http://blog.csdn.net/woshicaixianfeng/article/details/6416983
- 出现javax.net.ssl.SSLException: Not trusted server certificate错误
- javax.net.ssl.SSLException: Not trusted server certificate
- javax.net.ssl.SSLException: Not trusted server certificate .
- Android ksoap 访问https SSL Webservice报错 javax.net.ssl.SSLException: Not trusted server certificate
- https请求报错解决:javax.net.ssl.SSLException: Not trusted ...
- javax.net.ssl.SSLException: hostname in certificate didn't match:
- javax.net.ssl.SSLException: hostname in certificate didn't match:
- javax.net.ssl.SSLException
- Android 链接https出现 javax.net.ssl.SSLException: hostname in certificate didn't match:
- Android 链接https出现 javax.net.ssl.SSLException: hostname in certificate didn't match:
- Android 链接https出现 javax.net.ssl.SSLException: hostname in certificate didn't match:
- Android javax.net.ssl.SSLException: hostname in certificate didn't match...
- Android 链接https出现 javax.net.ssl.SSLException: hostname in certificate didn't match:
- 12. javax.net.ssl.SSLException: hostname in certificate didn't match证书不匹配的主机名
- HttpClient请求https,抛出javax.net.ssl.SSLException: hostname in certificate didn't match:
- HttpsURLConnection请求https,抛出javax.net.ssl.SSLException: hostname in certificate didn't match:
- HttpClient访问报错 javax.net.ssl.SSLException: hostname in certificate didn't match
- Android 异常:javax.net.ssl.SSLException: hostname in certificate didn't match
- 读取文件乱码
- dos2unix
- filco的后续
- 调用子程序
- C++拷贝构造函数(深拷贝,浅拷贝)
- javax.net.ssl.SSLException: Not trusted server certificate .
- linux md5sum的使用
- 使用ffmpeg进行视频文件转换成FLV整理
- MyEclipse 下配置WebLogic10 服务器
- 关于Linux中的链接
- webservice soap hessian
- FTP大附件上传解决方案
- POJ 1745 Divisibility
- Codeforces Beta Round #35 (Div. 2) E. Parade(成段更新)