mirror of
https://github.com/jphong1111/awesome-ios-developer.git
synced 2024-12-22 22:15:43 +07:00
Update README.md
This commit is contained in:
parent
8be8a10638
commit
0e3ebae8dc
24
README.md
24
README.md
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user