Search code examples
iosmknetworkkit

Ignore ssl certification MKNetworkKit


So it seems that ASIHTTPRequest allows you to ignore the certificates on https:// endpoints. I'm currently using MKNetworkKit and have implemented all my calls. Unfortunately, our testing server is on https but does not have a SSL certificate.

I'm able to connect fine using a curl with the -k command. I've tried various things in MKNetworkKit to ignore the NSURLAuthenticationChallenge, but to no avail. The latest thing I tried was the following:

op.authHandler = ^(NSURLAuthenticationChallenge *challenge)
{
    NSURLCredential *credential = [NSURLCredential credentialWithUser:_userName password:password persistence:NSURLCredentialPersistenceNone];
    [challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
};

This allowed me to actually get a 401 error returned (instead of being blank). Looking at the curl string, MKNetworkKit strips my username/password when the above block hits. I'm not sure if that's progress or not.

Anyone know how to simply ignore the SSL certificate?

Edit:

I had to update MKNetwork kit to get the new method ShouldContinueWithInvalidCertificate on MKNetworkOperation and my testing server got the certError fixed.

However, now I'm having a weird error happening. I'm still unable to get any return from two specific endpoints on the server. I look at the request, copy it into the command as a curl, and it immediately returns results. I'm not getting an error either from the operation.

What's happening here?


Solution

  • The MKNetworkOperation class has a property called shouldContinueWithInvalidCertificate which is defaulted to NO. All you have to do is set it to YES, and it will ignore the certs.

    The comments:

    /*!
     *  @abstract Boolean variable that states whether the operation should continue if the certificate is invalid.
     *  @property shouldContinueWithInvalidCertificate
     *
     *  @discussion
     *  If you set this property to YES, the operation will continue as if the certificate was valid (if you use Server Trust Auth)
     *  The default value is NO. MKNetworkKit will not run an operation with a server that is not trusted.
     */