Public key pinning is a great step for apps to reduce MITM vulnerabilities. The current instantiation of the Apollo Client allows a parameter for the URLSession configuration. In order to implement SSL pinning, however, an entire URLSession object should be able to be passed in. This would allows the URLSession object to register a delegate that handles the pinning by implementing
optional public func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Swift.Void)
This can be done simply by adding another constructor to the HttpNetworkTransport object that accepts the URLSession object instead of just it's configuration.
After that, injecting the session object with the appropriate delegate is simple.
let configuration = URLSessionConfiguration.default
let networkTransport = HTTPNetworkTransport(url: "https://some-gql-endpoint/graphql",
session: URLSession(configuration: configuration,
delegate: NSURLSessionPinningDelegate(),
delegateQueue: nil))
let client = ApolloClient(networkTransport: networkTransport)
Public key pinning is a great step for apps to reduce MITM vulnerabilities. The current instantiation of the Apollo Client allows a parameter for the URLSession configuration. In order to implement SSL pinning, however, an entire URLSession object should be able to be passed in. This would allows the URLSession object to register a delegate that handles the pinning by implementing
This can be done simply by adding another constructor to the HttpNetworkTransport object that accepts the URLSession object instead of just it's configuration.
After that, injecting the session object with the appropriate delegate is simple.