在我的应用程序中,当用户手动清除应用程序缓存时,他们将开始收到错误"未找到证书路径的信任锚"。
我的设置如下:应用程序具有中央服务器的硬编码URL。此中央服务器将告知应用程序可以登录的API的URL。连接到中央服务器时,该应用会创建一个同步帐户,并将此网址存储为同步帐户中的UserData。
当用户清除缓存后,登录后,他们将开始获取此异常,即使重启设备,该异常也会持续存在。
但是,当他们删除同步帐户并再次通过中央服务器登录时,问题就会消失。这是URLConnectionHelper
中触发问题和堆栈跟踪的代码。 (我的代码是com.my.package)
public static InputStream getInputStream(AppUser appUser, String fullpath, Map<String, ?> params, Method method) throws IOException
{
URL url = new URL(fullpath + getQuery(params));
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
if (appUser != null)
conn.setRequestProperty("X-AuthToken", appUser.getToken());
if (method == Method.POST || method == Method.PUT)
conn.setDoOutput(true);
conn.setRequestMethod(method.toString());
conn.connect(); // <-- line 69
return new BufferedInputStream(conn.getInputStream(), 8192);
}
06-01 12:04:52.441 26902-27032/com.my.package W/System.err: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
06-01 12:04:52.441 26902-27032/com.my.package W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:409)
06-01 12:04:52.441 26902-27032/com.my.package W/System.err: at com.android.okhttp.Connection.upgradeToTls(Connection.java:146)
06-01 12:04:52.441 26902-27032/com.my.package W/System.err: at com.android.okhttp.Connection.connect(Connection.java:107)
06-01 12:04:52.441 26902-27032/com.my.package W/System.err: at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:294)
06-01 12:04:52.441 26902-27032/com.my.package W/System.err: at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
06-01 12:04:52.441 26902-27032/com.my.package W/System.err: at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at com.android.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:161)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at com.my.package.util.URLConnectionHelper.getInputStream(URLConnectionHelper.java:69)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at com.my.package.util.URLConnectionHelper.getString(URLConnectionHelper.java:103)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at com.my.package.util.URLConnectionHelper.getJSONObject(URLConnectionHelper.java:117)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at com.my.package.task.LoginExistingAccountTask.doInBackground(LoginExistingAccountTask.java:59)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at com.my.package.task.LoginExistingAccountTask.doInBackground(LoginExistingAccountTask.java:23)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:288)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at java.lang.Thread.run(Thread.java:841)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:282)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at com.android.org.conscrypt.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:202)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:611)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:405)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: ... 19 more
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: ... 24 more
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:409)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at com.android.okhttp.Connection.upgradeToTls(Connection.java:146)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at com.android.okhttp.Connection.connect(Connection.java:107)
06-01 12:04:52.446 26902-27032/com.my.package W/System.err: at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:294)
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89)
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: at com.android.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:161)
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: at com.my.package.util.URLConnectionHelper.getInputStream(URLConnectionHelper.java:69)
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: at com.my.package.util.URLConnectionHelper.getString(URLConnectionHelper.java:103)
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: at com.my.package.util.URLConnectionHelper.getJSONObject(URLConnectionHelper.java:117)
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: at com.my.package.task.LoginExistingAccountTask.doInBackground(LoginExistingAccountTask.java:59)
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: at com.my.package.task.LoginExistingAccountTask.doInBackground(LoginExistingAccountTask.java:23)
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:288)
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: at java.lang.Thread.run(Thread.java:841)
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:282)
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: at com.android.org.conscrypt.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:202)
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:611)
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:405)
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: ... 19 more
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
06-01 12:04:52.451 26902-27032/com.my.package W/System.err: ... 24 more