Android ksoap 访问https SSL Webservice报错 javax.net.ssl.SSLException: Not trusted server certificate

今天写项目遇到:

 

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.

 

你可能感兴趣的:(android,webservice,server,ssl,360)