aronbalog / Vox

Swift JSON:API client framework
http://jsonapi.org
MIT License
46 stars 19 forks source link

ssl pinning in vox #30

Open ZahraAsgharzadeh opened 4 years ago

ZahraAsgharzadeh commented 4 years ago

I want to implement ssl pinning in Vox , Could you please help me how to do it ?

ZahraAsgharzadeh commented 4 years ago

I found out by my self , it's good to support it when you publish a framework ... some body should waste his time to edit library .

markturnip commented 4 years ago

I found out by my self , it's good to support it when you publish a framework ... some body should waste his time to edit library .

Perhaps you can provide some example code on your approach?

ZahraAsgharzadeh commented 4 years ago

I found out by my self , it's good to support it when you publish a framework ... some body should waste his time to edit library .

Perhaps you can provide some example code on your approach?

of course. I'll put example in next comment 👍

ZahraAsgharzadeh commented 4 years ago

In your project Go to Pods folder, open Vox. Open JSONAPIClient_Alamofire.swift which module that all requests handles there . In function executeRequest(...) add this part of code :

/// Configure the trust policy manager let serverTrustPolicy = ServerTrustPolicy.pinCertificates( certificates: ServerTrustPolicy.certificates(), validateCertificateChain: false, validateHost: true)

let serverTrustPolicies = ["yourhost.com": serverTrustPolicy] let serverTrustPolicyManager = ServerTrustPolicyManager(policies: serverTrustPolicies) let url = baseURL.appendingPathComponent(path) let headers: HTTPHeaders = [ "Content-Type": "application/vnd.api+json", "Accept": "application/vnd.api+json", "Authorization": "token"]

/// using certificate pinning let sessionManager = SessionManager(configuration: URLSessionConfiguration.default,serverTrustPolicyManager: serverTrustPolicyManager) let request = multiEncodedURLRequest(url: url, method: method, queryItems: queryItems, bodyParameters: bodyParameters, headers: headers)

And when request sent, in responseData call back do let _ = sessionManager base on this link : https://stackoverflow.com/questions/39984880/alamofire-result-failure-error-domain-nsurlerrordomain-code-999-cancelled