我正在使用 Twitter 的新 Fabric SDK对于安卓。我已经设置了Charles作为我 Mac 上的代理,这样我就可以分析 API 响应中的 JSON 负载。
Charles 中的 SSL 代理已启用,并已为我的测试设备授予访问权限。
但是,Charles 向我显示了对 Twitter 的任何请求的以下错误:
Status Failed
Failure SSLHandshake: Received fatal alert: certificate_unknown
Logcat 向我显示:
retrofit.RetrofitError: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:306)
at com.squareup.okhttp.Connection.upgradeToTls(Connection.java:241)
at com.squareup.okhttp.Connection.connect(Connection.java:158)
at com.squareup.okhttp.Connection.connectAndSetOwner(Connection.java:174)
at com.squareup.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:120)
Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:318)
at com.android.org.conscrypt.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:209)
at io.fabric.sdk.android.services.network.PinningTrustManager.checkSystemTrust(PinningTrustManager.java:117)
at io.fabric.sdk.android.services.network.PinningTrustManager.checkServerTrusted(PinningTrustManager.java:160)
在我看来我需要信任一些证书... 有什么想法吗?
最佳答案
Fabric SDK 使用 SSL 证书固定来确保它们直接与 Twitter 服务器对话。不幸的是,这意味着您将无法查看 Fabric 和 Twitter 后端之间的流量。
通常,标准 SSL 仅要求给定的证书是“可信的”。这就是为什么您可以在模拟器或测试设备上信任 Charles 证书,然后网络堆栈就不会提示。但是,当库使用 SSL 证书固定时,它不会只信任任何 受信任的证书,而只会信任一组特定的证书。因此,即使您的模拟器看到的是受信任的 Charles 证书,Twitter 库也会失败,除非它看到实际的 Twitter API 证书。查看更多https://www.infinum.co/the-capsized-eight/articles/securing-mobile-banking-on-android-with-ssl-certificate-pinning
如果您需要查看流量,则需要使用不使用 SSL 证书固定的 Twitter 库。
关于android - 如何代理对 api.twitter.com 的请求,包括 SSL 证书?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28180063/