swift - Swift AlamoFire 中的 SSL 固定

标签 swift ssl certificate alamofire pinning

我是这里的新手,但我有一个应用程序受到 MITM 攻击。

经过一些研究,听起来我需要进行 SSL Pining,即保留一份我的服务器公钥/证书的副本,以便确定响应是否来自它。

我不知道该怎么做,我在 Swift 中使用 AlamoFire 来处理网络。

最佳答案

Alamofire 现在实现了证书固定。 您需要的文档在 Readme.md 中

https://github.com/Alamofire/Alamofire

查看他们的示例实现:

let serverTrustPolicies: [String: ServerTrustPolicy] = [
    "test.example.com": .PinCertificates(
        certificates: ServerTrustPolicy.certificatesInBundle(),
        validateCertificateChain: true,
        validateHost: true
    ),
    "insecure.expired-apis.com": .DisableEvaluation
]

let manager = Manager(
    serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies)
)

关于swift - Swift AlamoFire 中的 SSL 固定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28572321/

相关文章:

swift - 如何使用完成处理程序编写自定义函数?

ssl - TLS 终止 : reencrypt using a destinationCACertificate

asp.net - IIS - 需要特定 MVC Controller 的 SSL 客户端证书

windows - 我不能使用我的代码证书来签署我的 .exe 文件(EKU 过滤器)

ssl - 在 Windows Server 2012 R2 上通过 SSL 的 AD LDS

swift - 在异步函数在 Swift 中完成执行后,在尾随闭包之外获取一个完全填充的数组

ios - Swift - 向上滚动时表格为空白

android - 证书签发: SSL page brings up "you need to set a lock screen pin or password before you can use credential storage" on Android

ios - 了解 CATransform3DRotate/CATransform3DMakeRotation