2014-09-18 10 views
14

La mia app si collega semplicemente a un server Web su un dispositivo domestico e legge alcuni html. Funziona bene quando si usa http, ma ora su iOS 8 quando si usa https non funziona.iOS 8 ha interrotto la connessione SSL nella mia app - CFNetwork SSLHandshake non riuscito (-9806)

Io uso AFNetworking v1 e sovrascrivo i controlli SSL utilizzando questi metodi di sovrascrittura (Sì, lo so in circostanze normali, questo non dovrebbe essere fatto ed è pericoloso ecc., Ma questo è un altro argomento).

[self setAuthenticationChallengeBlock:^(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge) { 
if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) { 
      [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge]; 
     } 
    }]; 

[self setAuthenticationAgainstProtectionSpaceBlock:^BOOL(NSURLConnection *connection, NSURLProtectionSpace *protectionSpace) { 
     if([[protectionSpace authenticationMethod] isEqualToString:NSURLAuthenticationMethodServerTrust]) { 
       return YES; // Self-signed cert will be accepted 
     } 
     // If no other authentication is required, return NO for everything else 
     // Otherwise maybe YES for NSURLAuthenticationMethodDefault and etc. 
     return NO; 
    }]; 

Ora con iOS 8 ottengo un errore come questo:

CFNetwork SSLHandshake failed (-9806)

CFNetwork SSLHandshake failed (-9806)

CFNetwork SSLHandshake failed (-9806)

NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9806)

Error during connection: Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo=0x7b66c110 {NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorCodeKey=-9806, NSErrorFailingURLStringKey= https://xxx.xxx.xxx.xxx:443/live.htm , _kCFStreamErrorDomainKey=3, NSUnderlyingError=0x7c0d8a20 "An SSL error has occurred and a secure connection to the server cannot be made.", NSErrorFailingURLKey= https://xxx.xxx.xxx.xxx:443/Info.live.htm }

Ho provato a cambiare verso FSNetworking, e sometimes opere quando si imposta questo:

- (void)connection:(NSURLConnection *)connection 
willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { 

    if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) 
    { 
     NSLog(@"Ignoring SSL"); 
     SecTrustRef trust = challenge.protectionSpace.serverTrust; 
     NSURLCredential *cred; 
     cred = [NSURLCredential credentialForTrust:trust]; 
     [challenge.sender useCredential:cred forAuthenticationChallenge:challenge]; 
     return; 
    } 
} 

Tuttavia fare 2 richieste simultanee, solo 1 avrà successo e una fallirà con un errore simile a quello sopra. Solo 1 richiesta sembra raggiungere il punto di override SSL.

Qualcuno può per favore fare un po 'di luce su questo e cosa è cambiato in iOS 8 per rompere questo, e come posso ripararlo?

Grazie

+1

Ecco un elenco di codici di errore che include il tuo: http://www.opensource.apple.it/source/libsecurity_ssl/libsecurity_ssl-32463/lib/SecureTransport.h – eremzeit

risposta

2

L'errore che state vedendo si possono trovare in SecureTransport.h. Si tratta di un errore a livello di trasporto: la connessione non è riuscita perché è stata interrotta.

Un numero di cose potrebbe essere la causa, sia sul client che sul server. È più probabile che ciò accada se il server chiede al cliente un certificato e il client non ne fornisce uno, a quel punto il server decide di rinunciare. Se il server richiede al client un certificato, il metodo delegato dovrebbe visualizzare un tentativo di autenticazione mediante un certificato client oltre al trust del server.

+1

Grazie. Non so cosa sia cambiato da iOS 7 a 8 per farlo smettere improvvisamente di funzionare. Mi sono aggiornato ad AFNetworking v2 e ho ricevuto le chiamate di richiamo di autenticazione e in pratica gli ho detto di ignorarlo e proseguire. Questo sembra funzionare a volte, ma non sempre. Mi chiedo se devo fare la coda di tutte le richieste così solo 1 va alla volta? – Darren

+0

Sembra che io abbia effettivamente il lato ssl delle cose che funzionano. Sebbene ottenga i messaggi SSLHandshake non riusciti, mi collego correttamente aggirando lo ssl come nella mia domanda. Il motivo per cui funziona solo a volte penso sia dovuto a questo https://github.com/AFNetworking/AFNetworking/issues/2314#issuecomment-56664366 – Darren

9

ho incontrato lo stesso tipo di problema con iOS 8.

Scenario:

  1. Le chiamate verso il nostro lavoro server HTTPS
  2. aprire un URL https dal nostro server in un UIWebView
  3. Tutti i futuri NSURLConnection s falliscono con un errore SSLHandshake

useCredential:forAuthenticationChallenge stava causando questo errore (ma solo dopo aver aperto una pagina in https ospitato sullo stesso server) quando abbiamo chiamato i metodi SecTrust * subito dopo.

Questo codice ha generato l'errore:

[challenge.sender useCredential:urlCredential forAuthenticationChallenge:challenge]; 
SecTrustRef trustRef = [[challenge protectionSpace] serverTrust]; 
CFIndex count = SecTrustGetCertificateCount(trustRef); 

Ma questo non lo fece:

SecTrustRef trustRef = [[challenge protectionSpace] serverTrust]; 
CFIndex count = SecTrustGetCertificateCount(trustRef); 
[challenge.sender useCredential:urlCredential forAuthenticationChallenge:challenge]; 

Non è chiaro per me perché questa è stata la causa del SSLHandshake a fallire su iOS 8, ma non iOS 7. Forse AFNetworking fa qualcosa dopo useCredential:forAuthenticationChallenge che sta causando lo stesso problema.

+1

Grazie. Questo è fondamentalmente lo stesso di quello che ho sopra. Penso che il codice alla base della mia domanda sia effettivamente funzionante e il motivo per cui a volte non ha a che fare con questo https://github.com/AFNetworking/AFNetworking/issues/2314#issuecomment-56664366 – Darren

Problemi correlati