【问题标题】:Pre-installed PdfViewerActivity does not work with SelfSigned trusted user certificate Android 11 ver 2预装的 PdfViewerActivity 不适用于 SelfSigned 可信用户证书 Android 11 版本 2
【发布时间】: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


    【解决方案1】:

    是 PdfViewerActivity 内部的错误还是我做错了什么?

    两者都没有。 Intent 可能会启动许多可能的 PDF 查看器应用程序。它们都不是您的应用程序,因此它们都不受您的网络安全配置的影响。在较新版本的 Android 上,默认情况下会忽略用户安装的证书。

    您需要自己下载 PDF 文件,然后使用FileProvider 及其getUriForFile() 方法获取Uri 以与您的Intent 一起使用。

    或者,如果适合您的情况,您可以切换服务器以使用常规 SSL 证书(例如 Let's Encrypt)而不是自签名证书。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-24
      • 1970-01-01
      • 1970-01-01
      • 2021-07-13
      • 2019-06-24
      • 2013-03-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多