
我有一份真正的证书,由COModo签署,本身由USERTrust签署.但是,当我尝试建立与我的域的连接时,这就是我得到的:
javax.net.ssl.SSLPeerUnverifIEdException: No peer certificate
我用来获得这个的代码是:
public voID postData() { // Add your data try { httpPost post = new httpPost(new URI("https://example.com")); KeyStore trusted = KeyStore.getInstance("BKS"); trusted.load(null,"".tochararray()); SSLSocketFactory sslf = new SSLSocketFactory(trusted); sslf.setHostnameVerifIEr(SSLSocketFactory.ALLOW_ALL_HOSTname_VERIFIER); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme ("https",sslf,443)); SingleClIEntConnManager cm = new SingleClIEntConnManager(post.getParams(),schemeRegistry); httpClIEnt clIEnt = new DefaulthttpClIEnt(cm,post.getParams()); // Execute http Post Request @SuppressWarnings("unused") httpResponse result = clIEnt.execute(post); } catch (ClIEntProtocolException e) { // Todo auto-generated catch block Log.e(TAG,e.getMessage()); Log.e(TAG,e.toString()); e.printstacktrace(); } catch (IOException e) { // Todo auto-generated catch block Log.e(TAG,e.toString()); e.printstacktrace(); } catch (URISyntaxException e) { // Todo auto-generated catch block Log.e(TAG,e.toString()); e.printstacktrace(); } catch (KeyStoreException e) { // Todo auto-generated catch block Log.e(TAG,e.getMessage()); Log.e(TAG,e.toString()); e.printstacktrace(); } catch (NoSuchAlgorithmException e) { // Todo auto-generated catch block Log.e(TAG,e.toString()); e.printstacktrace(); } catch (CertificateException e) { // Todo auto-generated catch block e.printstacktrace(); Log.e(TAG,e.toString()); Log.e(TAG,e.getMessage()); } catch (KeyManagementException e) { // Todo auto-generated catch block Log.e(TAG,e.toString()); e.printstacktrace(); } catch (UnrecoverableKeyException e) { // Todo auto-generated catch block Log.e(TAG,e.toString()); e.printstacktrace(); } } 我已经尝试了我的域名和https://google.com.他们都返回相同.这是堆栈:
02-01 10:24:30.067: W/System.err(15560): javax.net.ssl.SSLPeerUnverifIEdException: No peer certificate02-01 10:24:30.088: W/System.err(15560): at org.apache.harmony.xnet.provIDer.Jsse.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:258)02-01 10:24:30.098: W/System.err(15560): at org.apache.http.conn.ssl.AbstractVerifIEr.verify(AbstractVerifIEr.java:93)02-01 10:24:30.098: W/System.err(15560): at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:381)02-01 10:24:30.108: W/System.err(15560): at org.apache.http.impl.conn.DefaultClIEntConnectionoperator.openConnection(DefaultClIEntConnectionoperator.java:164)02-01 10:24:30.108: W/System.err(15560): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)02-01 10:24:30.128: W/System.err(15560): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)02-01 10:24:30.138: W/System.err(15560): at org.apache.http.impl.clIEnt.DefaultRequestDirector.execute(DefaultRequestDirector.java:359)02-01 10:24:30.148: W/System.err(15560): at org.apache.http.impl.clIEnt.AbstracthttpClIEnt.execute(AbstracthttpClIEnt.java:555)02-01 10:24:30.158: W/System.err(15560): at org.apache.http.impl.clIEnt.AbstracthttpClIEnt.execute(AbstracthttpClIEnt.java:487)02-01 10:24:30.158: W/System.err(15560): at org.apache.http.impl.clIEnt.AbstracthttpClIEnt.execute(AbstracthttpClIEnt.java:465)02-01 10:24:30.178: W/System.err(15560): at com.example.Preferences.postData(Preferences.java:103)02-01 10:24:30.178: W/System.err(15560): at com.example.Preferences.onCreate(Preferences.java:52)02-01 10:24:30.178: W/System.err(15560): at androID.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)02-01 10:24:30.178: W/System.err(15560): at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:1836)02-01 10:24:30.178: W/System.err(15560): at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)02-01 10:24:30.178: W/System.err(15560): at androID.app.ActivityThread.access00(ActivityThread.java:135)02-01 10:24:30.178: W/System.err(15560): at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)02-01 10:24:30.178: W/System.err(15560): at androID.os.Handler.dispatchMessage(Handler.java:99)02-01 10:24:30.178: W/System.err(15560): at androID.os.Looper.loop(Looper.java:150)02-01 10:24:30.178: W/System.err(15560): at androID.app.ActivityThread.main(ActivityThread.java:4385)02-01 10:24:30.188: W/System.err(15560): at java.lang.reflect.Method.invokeNative(Native Method)02-01 10:24:30.188: W/System.err(15560): at java.lang.reflect.Method.invoke(Method.java:507)02-01 10:24:30.188: W/System.err(15560): at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)02-01 10:24:30.188: W/System.err(15560): at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:607)
此外,在查看日志时,我发现,我认为是导致此错误的错误:
02-01 10:44:13.122: W/System.err(15746): Catch exception while startHandshake: javax.net.ssl.SSLHandshakeException: java.s@R_502_4722@.InvalIDAlgorithmParameterException: trustAnchors.isEmpty()02-01 10:44:13.122: W/System.err(15746): return an invalID session with invalID cipher suite of SSL_NulL_WITH_NulL_NulL
在这两天中,我阅读了大量文章,解释了如何连接到自签名SSL保护的网站.我也找到了this问题,这是我得到代码的地方,但我不知道我的生活中弄清楚使用默认的AndroID验证机制意味着什么以及如何实现它.
有人可以提供一段修复或实现连接到REAL证书的代码吗?
谢谢!
解决方法 我做错了什么,没有将TrustManager提供给SSLContextFactory.关于 my blog的更全面的解释.这里发布的时间太长了. 总结以上是内存溢出为你收集整理的在Android上创建SSL连接时出现SSLPeerUnverifiedException全部内容,希望文章能够帮你解决在Android上创建SSL连接时出现SSLPeerUnverifiedException所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)