【发布时间】:2021-04-06 23:43:27
【问题描述】:
我有一台带有自签名证书的服务器。此证书已添加到 Android 11 设备上的受信任凭据/用户列表中。我的应用程序和浏览器可以正常工作:我可以通过 Chrome 浏览器从 MyServer 下载 pdf 文件。
我的网络安全配置.xml
<network-security-config xmlns:tools="http://schemas.android.com/tools">
<base-config cleartextTrafficPermitted="true">
<trust-anchors tools:ignore="AcceptsUserCertificates">
<!-- Trust preinstalled CAs -->
<certificates src="system" />
<!-- Additionally trust user added CAs -->
<certificates src="user" />
</trust-anchors>
</base-config>
</network-security-config>
但是,当我尝试打开 pdf 文件时,我从 PdfViewerActivity 收到 SSLHandshakeException。 我的代码:
Intent pdfIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.myserver.com/example.pdf"));
startActivity(pdfIntent);
错误日志:
I/ActivityTaskManager:显示 com.google.android.apps.docs/com.google.android.apps.viewer.PdfViewerActivity:+163 毫秒
E/HttpUriOpener: 一般 IOException: SSLHandshakeException
E/PdfViewerActivity: fetchFile:https: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: 找不到证书路径的信任锚。
是 PdfViewerActivity 内部的错误还是我做错了什么? 我将不胜感激如何解决此问题。
UPD:Trust Anchor not found for Android SSL Connection 不是我问题的答案。它不包含有关在 Android 11 上使用 SelfTrusted 证书的信息。
【问题讨论】:
标签: android ssl self-signed sslhandshakeexception pdf-viewer