flutter - 如何在颤振中通过自生成的签名证书进行 SSL 固定?
问题描述
我正在寻找 SSL pinning 并使用自生成的证书来运行我们的 api。
解决方案
问题中没有足够的细节,所以这个答案是基于一些假设:
- 您的 API 是 HTTPS
- 您正在谈论验证服务器端自签名 HTTPS 证书
- 您正在
package:http
用作 http 客户端 - 没有客户端证书
package:http
dart:io HttpClient
在引擎盖下使用,并HttpClient
具有多个允许证书验证的功能。由于客户端不信任自签名服务器证书,因此客户端将调用badCertificateCallback
允许您自己验证服务器证书,例如:
HttpClient httpClient = new HttpClient()
..badCertificateCallback =
((X509Certificate cert, String host, int port) {
// tests that cert is self signed, correct subject and correct date(s)
return (cert.issuer == cert.subject &&
cert.subject == 'MySelfSignedCertCN' &&
cert.endValidity.millisecondsSinceEpoch == 1234567890);
});
IOClient ioClient = new IOClient(httpClient);
// use ioClient to perform get/post operations from package:http
// don't forget to call ioClient.close() when done
// note, this also closes the underlying HttpClient
推荐阅读
- java - C# Bouncy Castle 中的 RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING - 输入对于 RSA 密码来说太大
- bootstrap-4 - 在引导模式弹出窗口上使用鼠标进行标记选择问题
- python - Django 不提供静态文件,也不对任何东西进行样式化
- selenium - Selenium 并行执行
- python - 如何在数据框中找到两个未知值?查找值求解器
- python - 如何为 protobuf 中的可选消息字段赋值?
- python - 根据数据成员将对象从队列中拉出
- r - 自动将多项式转换为 R 中 ggplot 图例的表达式
- angular - 类型'可观察的
' 不可分配给类型 'Observable ' - python - 从元组列表中返回有组织的列表