TLS session caching during subsequent HTTPS calls

2019-06-03 15:47发布

问题:

My iOS app authenticates a user with a login screen upon initial entry into the app and after login success the credentials are stored in keychain. Unless the user goes and logs out of the app, the rest of the times the user opens the app they are authenticated against stored credentials.

When the user logs out the app is reset to its initial ViewController and the keychain and any stored data is wiped out. There is a sequence that will make NSURLConnection use the TLS session cache and not call canAuthenticateAgainstProtectionSpace and that is if a user logs in from the main login screen (not from stored creds) then without closing the app goes and logs out and tries to login again.

What I have tried/done so far:

  1. I have used this: https://developer.apple.com/library/ios/qa/qa1727/_index.html to solve part of the problem. I should note that I do not have control over the server so I can not adjust ports or set up the server to route wild card domain names.
  2. I have implemented the "." at the end of the host name for the login screen authentication call and no "." on the host name for the stored credentials authentication call.
  3. I also tested to see if the server was setup to route wildcard domain names by appending a random number to the beginning of the host name and that did not work.

I am looking for a solution other than the "." at the end of the host name to trigger canAuthenticateAgainstProtectionSpace delegate method every time that API call is made.