0

I am creating the iOS app that uses rest API's that is hosted on HTTPS. This domain have valid CA approved certificate for SSL and TLS. But when I make a NSURL request from my app it works fine first time but after half an hour when I will make NSURL Request it returns NSURL Error -1012.

I also tried to handle Authentication Challenges and TLS Chain Validation using the below mentioned methods: - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge

The process I used that is mentioned on below link: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/URLLoadingSystem/Articles/AuthenticationChallenges.html#//apple_ref/doc/uid/TP40009507-SW3

When I debug the canAuthenticateAgainstProtectionSpace and checked the protectionspace value it displays request have NSURLAuthenticationMethodServerTrust problem.

I tried different different scenarios to handle the problem. 1. In canAuthenticateAgainstProtectionSpace method if I found NSURLAuthenticationMethodServerTrust validation then I returned NO, then didReceiveAuthenticationChallenge method never called but API returns blank string. 2. In canAuthenticateAgainstProtectionSpace method if I found NSURLAuthenticationMethodServerTrust validation then I returned YES, then didReceiveAuthenticationChallenge method called and when I used continueWithoutCredentialForAuthenticationChallenge, performDefaultHandlingForAuthenticationChallenge and cancelAuthenticationChallenge methods one by one but nothing happening always I am getting the same result blank string and on cancelAuthenticationChallenge I am getting the NSURL Error -1012.

Our API is hosted on http://uat-exchange.vrmco.com/

Please help me what I am missing or is any thing that we need to used to resolve this error.

Thanks in Advance.

1 Answers1

0

I don't think this is a TLS problem if it works the first time. IIRC, unless you're providing custom TLS handler methods (returning YES for the server trust protection space in your canAuthenticateAgainst... method), a 1012 error typically means a failure to authenticate the user to the server rather than the other way around. (There are other error codes for TLS failures—1202 in particular.)

My first guess would be that your server is requiring some kind of cookie-based authentication, and is returning an HTTP 401 error code when that cookie expires. If so, you should probably treat that as an indication that you need to redo the login process.

dgatwood
  • 10,129
  • 1
  • 28
  • 49