android-studio - android studio:https自签名证书不受信任
问题描述
尝试通过 android studio(使用 kotlin)访问具有我自己的自签名证书的https://localhost:5000/,但我不断收到错误消息:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚。
我通过使用方法 2在此处找到的指南使用 openssl 制作了证书
我尝试添加一个如下所示的 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,(我使用从 crt 转换openssl x509 -in server.crt -out server.pem -outform PEM
并重命名为 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 上启用了自签名证书,但我没有在 kotlin 上启用它们,所以错误来自 kotlin 而不是 android studio,从这个答案快速复制粘贴
已经解决了它,尽管我对此一无所知,如果有人可以给我发一份关于某种解释或教程的参考,那就太好了。
推荐阅读
- html - 我错过了一些关于响应式设计的东西
- asp.net - 如何让本地 IIS 使用不同的 Azure Active Directory 访问资源
- java - 如何证明两个孩子是兄弟姐妹?
- sass - 如何将 2 个 SCSS 规则之间的共同点保留为单个规则并创建一个具有差异的新规则
- python - 在字典列表中将一些 python 字典键重新分配为值,将其他值重新分配为键
- java - 如何在 Windows 操作系统上删除或禁用 Java 中的“制表符选择器”?
- python - 自动工作流服务来处理 Google Drive 文件?
- javascript - 如何对异步功能进行适当的单元测试?
- python - Openstack Python API novaclient - 带有描述的安全组规则列表
- javascript - 使用用户输入显示json的值