【发布时间】:2019-09-23 21:34:30
【问题描述】:
我正在 Android 8(26 API,Oreo)上开发,我在我的应用中使用 android.webkit.WebView。
当我使用WebView 加载页面时,我会实施“安全网络连接”(换句话说,我会避免中间人问题和自签名证书)
为此,我使用了网络安全配置(在 Android 上从 7.0 N 版本开始,24 API)
所以:
在res>xml>network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config>
<domain includeSubdomains="true">MY_DOMAIN.com</domain>
<pin-set>
<pin digest="SHA-256">MY_PIN</pin>
</pin-set>
</domain-config>
</network-security-config>
我发现MY_PIN 在此处插入MY_DOMAIN.com:https://report-uri.com/home/pkp_hash
在manifest>AndoridManifest.xml
...
<application
android:networkSecurityConfig="@xml/network_security_config"
...
</application>
在我的应用程序的 onCreate 中,我只是这样做:
WebView webView = new WebView(this);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedSslError(..)..
@Override
public void onPageFinished()..
...});
webView.loadUrl(MY_DOMAIN.com);
根据 Android 文档,我做得对,但我有一个问题:就像 network_security_config.xml 从未检查过,因为我可以为 pin 设置每个“随机”和“错误”值并且它可以正常工作(URL @ 987654332@ 正常加载,没有阻塞行为)。
这意味着如果某个中间人返回我在res>xml>network_security_config.xml 中编写的那些不同的引脚,则应用程序将继续运行良好并且没有安全行为。
它也不会执行WebViewClient 的覆盖错误方法之一。
请帮助我无法理解我的错误。
【问题讨论】:
标签: android android-webview android-network-security-config