AFNetworking/AFNetworking — pull request #1186 by kcharwood (2013-07-31 21:42:23+00:00)
Title: [2.0] Bringing Pinning Over / Refactor

I've taken a stab at refactoring SSL pinning to make it easier to maintain, more testable, and able to support tasks and operations.

There may a bit of controversy with this patch since it adds a new class (`AFSecurity`), but if we are going to support both NSURLConnection and NSURL[redacted] in the same HTTP client, we need to have this code in a common place and used by both implementation.

I took this opportunity to refactor the actual implementation of pinning, and break it down into compartmentalized methods that can be tested specifically. These can be found in AFSecurity.m. In the header, we have two methods, one to return the default pinned certificates in the main bundle, and the other to apply logic based on the pinning parameters to determine if we actually trust the server trust.

This also has the bonus of now having a pinnedCertificates property on both the `AFHTTPClient`, and the `AFURLConnectionOperation`, giving us some better testable options since we wouldn't have to swizzle anymore.

I know @OliverLetterer is working on some trust chain improvements in the master branch, but with this new architecture in this patch is should easy to bring them over.

I also believe this makes it a bit more maintainable and less scary, as it breaks down the process of pinning into very easy to understand steps.

Would love to get @OliverLetterer's take on this approach. I do feel its much cleaner for us going forward.