title: Problems with SSL Pinning and AFNetworking 2.5.0 (NSURLErrorDomain error -1012.)
body: <p>We’ve been having a hard time securing our app’s network connections with SSL using AFNetworking 2.5.0.</p>
  
  <p>We use a self-signed certificate authority and implemented a custom security policy using pinned certificates.</p>
  
  <p>We’ve tested quite a few configurations provided by AFNetworking but have not been lucky so far. The error message we receive is:</p>
  
  <blockquote>
    <p>2015-01-05 19:03:07.191 AppName[9301:319051] Error updating user
    journey. Error: Error Domain=NSURLErrorDomain Code=-1012 "The
    operation couldn’t be completed. (NSURLErrorDomain error -1012.)"
    UserInfo=0x7ae056b0
    {NSErrorFailingURLKey=<a href="https://api.XXX.com/XXX/XXX/">https://api.XXX.com/XXX/XXX/</a>,
    NSErrorFailingURLStringKey=<a href="https://api.XXX.com/XXX/XXX/">https://api.XXX.com/XXX/XXX/</a>}</p>
  </blockquote>
  
  <p>Our certificate works fine on other clients such as cURL and Android. When using HTTP, our implementation works perfectly fine too.</p>
  
  <p>Is anyone aware of any issues related to pinned certificates and AFNetworking? If yes, we’d appreciate any pointers you may have.</p>
  
  <p>Here's part of the implementation:</p>
  
  <pre><code>+ (AFSecurityPolicy*)customSecurityPolicy {
     AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
     NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"der"];
     NSData *certData = [NSData dataWithContentsOfFile:cerPath];
     [securityPolicy setAllowInvalidCertificates:NO];
     [securityPolicy setValidatesCertificateChain:NO];
     [securityPolicy setPinnedCertificates:@[certData]];
     return securityPolicy;
  }
  
  + (AFHTTPRequestOperationManager*)customHttpRequestOperationManager {
     AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
     manager.securityPolicy = [self customSecurityPolicy]; // SSL
     return manager;
  }
  
  +(void)getRequestWithUrl:(NSString*)url success:(void(^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void(^) (AFHTTPRequestOperation *operation, NSError *error))failure {
     [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
     AFHTTPRequestOperationManager *manager = [HttpClient customHttpRequestOperationManager];
     manager.responseSerializer = [AFHTTPResponseSerializer serializer];
     [manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
         [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
         success(operation, responseObject);
     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
         [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
         failure(operation, error);
     }];
  }
  </code></pre>
  
  <p>Thank you!</p>