Why is an HTTPS NSURLSession connection requested only once per domain?

When connecting via HTTPS to the server, I implement a method NSURLSessionDelegate URLSession:didReceiveChallenge:completionHandler:for implementing some user-defined functions.

The problem is that this delegate method is called only on the first request (subsequent requests do not call this method). My custom functionality requires that the delegate method be called for the request each .

Here is an example:

- (IBAction)reload:(id)sender {
    NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration] delegate:self delegateQueue:nil];
    // Note that https://www.example.com is not the site I'm really connecting to.
    NSURL *URL = [NSURL URLWithString:@"https://www.example.com"];
    NSMutableURLRequest *URLRequest = [NSMutableURLRequest requestWithURL:URL];

    [[session dataTaskWithRequest:URLRequest
                completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                    // Response received here.
                }] resume];
}

#pragma NSURLSessionDelegate

- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler
{
    // Called only for the first request, subsequent requests do no invoke this method.
    completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
}

Since I need a URLCredential for the session or for each task, I checked NSURLCredentialwhich I pass on completionHandler, and found that it has persistenceof NSURLCredentialPersistenceForSession(which is immutable) which seems to be correct.

[NSURLCredentialStorage allCredentials], , .

, URL- HTTPS , , .

, ?

NSURLSessionTaskDelegate URLSession:task:didReceiveChallenge:completionHandler: .

- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler
{
    completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
}

EDIT

, , , Apple: 19072802

+4
1

, , - .

Technote 2232: HTTPS Server Trust Evaluation HTTP .

SSL/TLS, . ( ) , .

, , .

, - , . ! , , . iOS , .

() HTTP, , , Foundation API, NSURLConnection NSURLSession, . () , . , , .

SSL/TLS , URL- SecureTransport, . SecureTransport TLS . , , , , - TLS SecureTransport .

Q & A 1727: TLS Session Cache SecureTransport TLS (.. DNS).

API SecureTransport TLS. , .

TL; DR;

", ?" TLS SecureTransport .

.

HTTPS (, OpenSSL), YMMV.

+7

All Articles