简体   繁体   English

AlamoFire:公钥固定不起作用

[英]AlamoFire: public key pinning not working

I am creating a Session manager using a shared instance as below: 我正在使用共享实例创建会话管理器,如下所示:

class Session {
static let sharedInstance = Session()

private var manager : SessionManager?

func ApiManager()->SessionManager{
    if let m = self.manager{
        return m
    }else{

        let serverTrustPolicies: [String: ServerTrustPolicy] = [
            "https:api-cat.example.com": .pinPublicKeys(
                publicKeys:savePublicKeys(),
                validateCertificateChain:true,
                validateHost:true
            )]
        self.manager = SessionManager(
            serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies))
        return self.manager!
    }
}}

where savePublicKeys returns [SecKey] . 其中savePublicKeys返回[SecKey]

Even after setting the new ServerTrustPolicy with an empty public key array, I am still able to make successful calls and get data. 即使使用空的公共密钥数组设置了新的ServerTrustPolicy之后,我仍然能够成功调用并获取数据。 Any ideas if I am making any mistake here? 如果我在这里犯了任何错误,有什么想法吗?

Your "https:api-cat.payeezy.com" looks fishy. 您的"https:api-cat.payeezy.com"看起来像鱼。

Either remove the https: -part or add the missing double slash https:// . 删除https: -part或添加缺少的双斜杠https:// The ServerTrustPolicyManager only applies the policy when its host property matches the request's host, if those don't match, Apple's standard behavior is used (See Alamofire Documentation ). ServerTrustPolicyManager仅在其host属性与请求的主机匹配时才应用策略,如果不匹配,则使用Apple的标准行为(请参阅Alamofire文档 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM