Skip to content

Instantly share code, notes, and snippets.

@sagaya
Created July 16, 2019 11:15
Show Gist options
  • Save sagaya/35ad4972d1471342dfa21a5523a2eee3 to your computer and use it in GitHub Desktop.
Save sagaya/35ad4972d1471342dfa21a5523a2eee3 to your computer and use it in GitHub Desktop.
ssl_pining
let pathToCert = Bundle.main.path(forResource: "name-of-cert-file", ofType: "cer")
let localCertificate: NSData = NSData(contentsOfFile: pathToCert!)!
let serverTrustPolicy = ServerTrustPolicy.pinCertificates(
certificates: [SecCertificateCreateWithData(nil, localCertificate)!],
validateCertificateChain: true,
validateHost: true
)
let serverTrustPolicies = [
"my-server.com": serverTrustPolicy
]
let sessionManager = SessionManager(
serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment