On my project, we are using a closed source framework (Backbase, if you wanna know). This is an hybrid application framework that offers many security options "out of the box". One of them is certificate pinning, and I am quite intrigued by its implementation.
We only have to set a property in a configuration file and that's it. Every request done through URLSession.shared is processed through the framework and the pinning is effective. However If I instantiate my own URLSession, then the pinning is not effective. But I can also make the pinning effective on a new URLSession by instantiating it with the framework's NSURLSessionConfiguration.
For those who only read code:
// Pinning effective
URLSession.shared.dataTask(with: request, completionHandler: completion)
// Pinning not effective
URLSession(configuration: .default).dataTask(with: request, completionHandler: completion)
// Pinning effective
URLSession(configuration: ShinnyFramework.getConfiguration()).dataTask(with: request, completionHandler: completion)
For me, URLSession.shared is immutable, so it was not possible to alter its working. And to implement pinning, the only way was to create a new URLSession with a custom URLSessionDelegate.
My question is : What did they do to get this behavior ? Method swizzling, Isa swizzling, something else ?
Edit: I am not looking for a detailed explanation about how to implement certificate pinning. What interests me more is how to edit a supposedly immutable static property and how to configure the behavior of an URLSession object without using a delegate.