Android SSLPeerUnverifiedException->在无限循环中调用HostnameVerifier.verify

问题描述

我试图通过HTTPS连接和库KSOAP2连接到服务器,然后得到以下异常:

javax.net.ssl.SSLPeerUnverifiedException: Hostname 10.XXX.X.XXX not verified:
certificate: sha1/.../...=
DN: C=ES,CN=*.customername.es,O=XXX XXXX S.L.U\,OU=IT,2.5.4.5=#XXXXXXXXX,L=[location]
subjectAltNames: [*.customername.es]

然后我尝试通过调用以下命令来设置认的Custome HostnameVerifier:

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setoutputSoapObject(request);
    //HttpTransportSE androidHttpTransport = crearhttptransport();
    HttpsTransportSE androidHttpsTransport = new HttpsTransportSE("10.XXX.X.XXX",443,"/demo/webservice.asmx",MILLISECONDS_TIME_OUT);

    if (androidHttpsTransport != null) {

        //Fakex509trustmanager.allowAllSSL()
        HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {

            @Override
            public boolean verify(final String hostname,final SSLSession session) {
                HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier();
                return hv.verify("10.XXX.X.XXX",session);
                //return hv.verify("*.customername.es",session);
            }
        });
        androidHttpsTransport.call(NAMESPACE + request.getName(),envelope,generateHeaders());
        return envelope.bodyIn != null ? (SoapObject) envelope.bodyIn : null;
    }

但是然后我得到一个 StackOverFlowException ,因为 verify(...) 方法进入循环并被无限调用:>

E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #3
Process: myapp.androidv2,PID: 32471
java.lang.RuntimeException: An error occurred while executing doInBackground()
    at android.os.AsyncTask$4.done(AsyncTask.java:399)
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
    at java.util.concurrent.FutureTask.run(FutureTask.java:271)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:919)
 Caused by: java.lang.StackOverflowError: stack size 1039KB
    at myapp.androidv2.resourceaccess.WSManager$1.verify(WSManager.java:209)
    at myapp.androidv2.resourceaccess.WSManager$1.verify(WSManager.java:211)
    at myapp.androidv2.resourceaccess.WSManager$1.verify(WSManager.java:211)
    at myapp.androidv2.resourceaccess.WSManager$1.verify(WSManager.java:211)
    at myapp.androidv2.resourceaccess.WSManager$1.verify(WSManager.java:211)
...)

您还可以看到带有注释的 Fakex509trustmanager.allowAllSSL(),我也已经尝试使用它们,就像他们所说的here,但最终会出现相同的循环错误。>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)