0
votes

I have a problem establishing a connection to my server with a self signed certificate. In RestKit 0.10.3 everything works fine with the certificate.

I initialize RestKit like this:

   AFHTTPClient * client = [AFHTTPClient clientWithBaseURL:baseURl];
    [client setDefaultHeader:@"Accept" value:RKMIMETypeJSON]; 
    client.defaultSSLPinningMode = AFSSLPinningModeCertificate; 
    client.allowsInvalidSSLCertificate = YES; 

    RKObjectManager *objectManager = [[RKObjectManager alloc] initWithHTTPClient:client]; 
    objectManager.managedObjectStore = managedObjectStore;

but the SSL-Certificate gets ignored - it doesn't get loaded by AFNetworking.

When I'm create an Request like this

NSMutableURLRequest *request = [[RKObjectManager sharedManager] requestWithObject:nil method:RKRequestMethodGET path:[@"/myResource"] parameters:nil];

RKHTTPRequestOperation *httpRequestOperation = [[RKHTTPRequestOperation alloc] initWithRequest:request];
httpRequestOperation.SSLPinningMode = AFSSLPinningModeCertificate;

RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithHTTPRequestOperation:httpRequestOperation
responseDescriptors:[RKObjectManager sharedManager].responseDescriptors];

The certificate gets loaded but the request fails anyway with this message:

2013-10-31 11:52:12.920 myApp[87552:651b] E restkit.network:RKObjectRequestOperation.m:576 Object request failed: Underlying HTTP request operation failed with error: Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)" UserInfo=0x9470aa0 {NSErrorFailingURLKey=https://myDomain.com/myRessource NSErrorFailingURLStringKey=https://myDomain.com/myRessource} 2013-10-31 11:52:12.921 myApp[87552:651b] E restkit.network:RKObjectRequestOperation.m:238 GET 'https://myDomain.com/myRessource' (0 / 0 objects) [request=0.2065s mapping=0.0000s total=0.2130s]: error=Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)" UserInfo=0x9470aa0 {NSErrorFailingURLKey=https://myDomain.com/myRessource, NSErrorFailingURLStringKey=https://myDomain.com/myRessource} response.body=(null)

Questions:

  1. Is it the correct way to initialize RestKit? I don't want to specify the SSL-stuff in every request. It should be set globaly.
  2. Any idea why the request fails? body=null looks suspicious.
1
Hi, I have the same error code 1012 in 0.20.3, but after I update RestKit to 0.22.0, it works fine.Puttin

1 Answers

1
votes

In RKObjectManager you will find:

#ifdef AFNETWORKING_PIN_SSL_CERTIFICATES
operation.SSLPinningMode = self.HTTPClient.defaultSSLPinningMode;
#endif

So you need to set that define if using the object manager directly.