Alamofire公钥固定不验证其他网址

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

我有一个3 baseURL这三个有不同的ssl证书,我已下载一个证书和硬编码在Xcode项目,即使我更改url请求应用程序不阻止请求。

我正在上课

class APIManager {

    static let sharedInstance = APIManager()
    private var manager : SessionManager?
    func sessionManager() -> SessionManager {

        if let manage = self.manager {
            return manage
        }
        else {
            let serverTrustpolicies: [ String: ServerTrustPolicy] = ["url" : .pinPublicKeys(publicKeys: ServerTrustPolicy.publicKeys(), validateCertificateChain: true, validateHost: true)
            ]

            self.manager = SessionManager(
                serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustpolicies)
            )
            let configuration = URLSessionConfiguration.default
            configuration.timeoutIntervalForRequest = 30
            self.manager = SessionManager(configuration: configuration)
            return self.manager!
        }

    }
}

APIManager.sharedInstance.sessionManager().upload(multipartFormData: { (multipartFormData)
}

谁能解释实施?

swift ssl-certificate alamofire certificate-pinning
1个回答
0
投票

您必须为要验证的每个主机显式设置ServerTrustPolicy值。因此,在创建策略字典时,需要传递每个主机。

let serverTrustPolicies: [String: ServerTrustPolicy] = ["url" : .pinPublicKeys(publicKeys: ServerTrustPolicy.publicKeys(), validateCertificateChain: true, validateHost: true)]

这应该添加您的其他基本URL,并使用适当的策略集。

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