[android studio:不信任https自签名证书

问题描述 投票:1回答:1

试图通过android studio访问具有我自己的自签名证书的https://localhost:5000/(使用kotlin),并且不断收到错误:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚。

我已经通过openssl通过使用方法2找到的here指南获得了证书

我尝试添加如下所示的network_security_config.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config>
        <domain includeSubdomains="true">https://10.0.2.2:5000/</domain>
        <trust-anchors>
            <certificates src="@raw/my_ca"/>
            <certificates src="user"/>
            <certificates src="system"/>
        </trust-anchors>
    </domain-config>
</network-security-config>

并且我在res内部制作了一个名为raw的文件夹,并将其放入my_ca.pem,(我使用openssl x509 -in server.crt -out server.pem -outform PEM将其从crt转换为该文件夹,然后重命名为my_ca.pem)

[我还尝试在android studio设置上添加该证书,或允许所有不受信任的站点,将html请求中的代码像我发现的一样简单:

URL("https://10.0.2.2:5000/").readText()

,它在AsyncTask类内部,但该类所做的只是此请求

我访问10.0.2.2而不是127.0.0.1,因为据我了解,它是通过te仿真器访问本地机器的方式,而erver代码是一个非常简单的python-flask代码,它返回一个简单的字符串

android-studio ssl openssl ca
1个回答
0
投票

所以我想通了,虽然我确实在android studio上启用了自签名证书,但我没有在kotlin上启用它们,所以错误来自kotlin而不是android studio,这是this answer的快速复制粘贴

已经解决了,虽然我完全不了解,但是如果有人可以向我推荐某种移植物或教程,那会很棒。

© www.soinside.com 2019 - 2024. All rights reserved.