Update README.md

This commit is contained in:
Jungpyo Hong 2021-06-04 11:48:31 -05:00 committed by GitHub
parent 8be8a10638
commit 0e3ebae8dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1104,6 +1104,8 @@ When a mobile app communicates with a server, it uses SSL(Secure Socket Layer) p
### Implement SSL Pinning
**Using URLSession**
```swift
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
if (challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust) {
@ -1135,6 +1137,28 @@ func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationCh
}
```
**Using Alamofire**
```swift
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)
)
```
### Relative Stuff
TrustKit makes it easy to deploy SSL public key pinning