Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS NSURLConnection with SSL: Accepting an expired self-signed certificate
    primarykey
    data
    text
    <p>I have a shipped app that uses the following code to secure an SSL connection using a self-signed certificate that is shipped with the app.</p> <pre><code>- (void) connection:(NSURLConnection *)conn willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { NSLog(@"didReceiveAuthenticationChallenge %@ FAILURES=%d", [[challenge protectionSpace] authenticationMethod], (int)[challenge previousFailureCount]); /* Setup */ NSURLProtectionSpace *protectionSpace = [challenge protectionSpace]; assert(protectionSpace); SecTrustRef trust = [protectionSpace serverTrust]; assert(trust); CFRetain(trust); // Make sure this thing stays around until we're done with it NSURLCredential *credential = [NSURLCredential credentialForTrust:trust]; /* Build up the trust anchor using our root cert */ int err; SecTrustResultType trustResult = 0; err = SecTrustSetAnchorCertificates(trust, certs); if (err == noErr) { err = SecTrustEvaluate(trust,&amp;trustResult); } CFRelease(trust); // OK, now we're done with it // http://developer.apple.com/library/mac/#qa/qa1360/_index.html BOOL trusted = (err == noErr) &amp;&amp; ((trustResult == kSecTrustResultProceed) || (trustResult == kSecTrustResultConfirm) || (trustResult == kSecTrustResultUnspecified)); // Return based on whether we decided to trust or not if (trusted) { [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge]; } else { NSLog(@"Trust evaluation failed for service root certificate"); [[challenge sender] cancelAuthenticationChallenge:challenge]; } } </code></pre> <p>Unfortunately, I made a huge oversight. SSL certificates expire. So when the expiry date passes I'm assuming the app is going to stop working properly! There's nothing I can do for the current version of the app - that's going to stop working soon.</p> <p>I need to release an update and in order to avoid this in the future I would like to allow the self-signed certificate even if it has expired. </p> <p>How do I modify my code above to trust the certificate even if it has expired?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload