K
K
KurazhBambei2014-06-08 17:46:38
Objective-C
KurazhBambei, 2014-06-08 17:46:38

Problem when authorizing with a client certificate on iOS?

Good day, friends. Faced a strange problem. The iOS app requires you to sign the request with the certificate you received earlier. I am using MKNetworkKit.

- (void)startConnection {
    NSString *serverURL = @"host.ru/method";
    MKNetworkEngine *engine = [[MKNetworkEngine alloc] initWithHostName:serverURL customHeaderFields:nil];
    MKNetworkOperation *op = [engine operationWithPath:nil params:nil httpMethod:@"GET" ssl:YES];
    
    NSString *thePath = [[NSBundle mainBundle] pathForResource:@"client" ofType:@"p12"];
    [op setShouldContinueWithInvalidCertificate:YES];
    op.clientCertificate = thePath;
    op.clientCertificatePassword = @"1234qwerty";
    
    [op addCompletionHandler:^(MKNetworkOperation *operation) {
        NSLog(@"[operation responseData]-->>%@", [operation responseString]);
    }errorHandler:^(MKNetworkOperation *errorOp, NSError* err) {
        NSLog(@"MKNetwork request error : %@", [err localizedDescription]);
    }];
    
    [engine enqueueOperation:op];   
}

falls into the log error:
Moscow Standard Time
Request
-------
curl -X GET 'https://host.ru/method', [The operation couldn’t be completed. (NSURLErrorDomain error -1012.)]

If you make such a request through an extension to the Google Chrome Advanced REST Client that allows you to use the same certificate, then everything works correctly.
I can't figure out what the problem is.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question