android - 预装的 PdfViewerActivity 不适用于 SelfSigned 可信用户证书 Android 11 版本 2

标签 android ssl self-signed sslhandshakeexception pdf-viewer

我有一台带有自签名证书的服务器。此证书已添加到 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: Displayed com.google.android.apps.docs/com.google.android.apps.viewer.PdfViewerActivity: +163ms


E/HttpUriOpener: general IOException: SSLHandshakeException


E/PdfViewerActivity: fetchFile:https: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.


是 PdfViewerActivity 中的错误还是我做错了什么?
我将不胜感激如何解决此问题。
更新:Trust Anchor not found for Android SSL Connection不是我问题的答案。它不包含有关在 Android 11 上使用 SelfTrusted 证书的信息。

最佳答案

Is it bug inside PdfViewerActivity or I have done something wrong?


两者都不。 Intent 可能会启动许多可能的 PDF 查看器应用程序。 .它们都不是您的应用程序,因此它们都不受您的网络安全配置的影响。在较新版本的 Android 上,默认情况下会忽略用户安装的证书。
您需要自己下载 PDF 文件,然后使用 FileProvider及其getUriForFile()获取 Uri 的方法与您的 Intent 一起使用.
或者,您可以切换服务器以使用常规 SSL 证书(例如 Let's Encrypt)而不是自签名证书,如果这对您的情况是可行的。

关于android - 预装的 PdfViewerActivity 不适用于 SelfSigned 可信用户证书 Android 11 版本 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65507490/

相关文章:

java - 使用 keytool 的 key 对和自签名证书之间的区别?

java - 解析收到的GCM消息

java - ArrayAdapter 构建 ArrayList 时未正确处理单击事件

java - Firebase 数据库复杂查询返回不正确的结果

android - MAP-API 如何在 ANDROID 中用于一个简单的用例

apache - Apache2 上安装了 SSL,但 HTTPS 不工作

c# - IIS 7 身份验证 - 仅允许智能卡登录证书

node.js - 主页未解析裸域 URL

apache-flex - 从 Flex 连接到自签名 HTTPS Web 服务

firefox - 使用相同的自签名 CA 编码多个证书?