Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TrustKit is not working #330

Open
PawanEnp opened this issue May 15, 2024 · 0 comments
Open

TrustKit is not working #330

PawanEnp opened this issue May 15, 2024 · 0 comments

Comments

@PawanEnp
Copy link

PawanEnp commented May 15, 2024

Hello,

Below is the code we have written

`
public override func urlSession(_ session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
// Call into TrustKit here to do pinning validation
if NetworkUtil.isTrustKitInitialized {
if TrustKit.sharedInstance().pinningValidator.handle(challenge, completionHandler: completionHandler) == false {
// TrustKit did not handle this challenge: perhaps it was not for server trust
// or the domain was not pinned. Fall back to the default behavior
completionHandler(.performDefaultHandling, nil)
} else {
// TrustKit did successfully handled this challenge and took decision based on trust chain
DDLogDebug("SSL Pinning handled successfully")
}
} else {
completionHandler(.performDefaultHandling, nil)
}
}

//FILE: NetworkUtil.swift
static func initializeTrustKit(urlStr: String) {

    //urlStr is passed here as an argument based on the user's selection of environment
    if let sslKeys = Constants.SSLKeys(),
       let url = URL(string: urlStr),
       let domain = url.host {
        let trustKitConfig = [
            kTSKSwizzleNetworkDelegates: false,
            kTSKPinnedDomains: [
                domain: [
                    kTSKEnforcePinning: true,
                    kTSKIncludeSubdomains: true,
                    kTSKPublicKeyHashes: sslKeys
                ]
            ]
        ] as [String: Any]
        TrustKit.initSharedInstance(withConfiguration: trustKitConfig)
        isTrustKitInitialized = true
    }
}

`

We are using BurpSuite to trace the network (setting up a proxy server and routing iPhone to use a proxy) and we can read all communication in plaintext.

This code was working but looks like on the latest iOS it is not working. I request help here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant