CertificatePinner is a helper library for SSL pinning written in swift.
- Public key pinning
- Certificate file pinning
The CertificatePinner library is available to install using SPM, Cocoapods and Carthage dependency manager.
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift
compiler.
Once you have your Swift package set up, adding CertificatePinner as a dependency is as easy as adding it to the dependencies
value of your Package.swift
.
dependencies: [
.package(url: "https://github.com/micho233/certificate-pinner.git", .upToNextMajor(from: "1.0.0"))
]
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate CertificatePinner into your Xcode project using CocoaPods, specify it in your Podfile
:
pod 'CertificatePinner'
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate CertificatePinner into your Xcode project using Carthage, specify it in your Cartfile
:
github "micho233/certificate-pinner"
CertificatePinner provides an elegant way for certificate pinning (for now only public key pinning) in order to prevent man-in-the-middle attack.
CertificatePinner class can be declared anywhere in your networking class, or provided by data source.
var pinner = CertificatePinner(pins: ["PublicKeyhash", "AnyOtherPublicKeyHash"])
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge) async -> (URLSession.AuthChallengeDisposition, URLCredential?) {
return await pinner.checkCertificateValidity(for: challenge)
}
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
pinner.checkCertificateValidity(for: challenge, completion: completionHandler)
}