ios - Is there a way to let the user chose whether or not trust the site when we try to use NSURLConnection to connect with SSL for an untrusted cert? -


there similar question on stack overflow.

here code accept untrusted server certificate anyway.

- (bool)connection:(nsurlconnection *)connection canauthenticateagainstprotectionspace:(nsurlprotectionspace *)space {     //we can attempt authenticate...     return yes; }  - (void)connection:(nsurlconnection *)connection didreceiveauthenticationchallenge:(nsurlauthenticationchallenge *)challenge {     if ([[challenge protectionspace] authenticationmethod] == nsurlauthenticationmethodservertrust) {         [[challenge sender] usecredential:[nsurlcredential credentialfortrust:[[challenge protectionspace] servertrust]] forauthenticationchallenge:challenge];     } else {       // other situation     } } 

however, want present alter view let user chose whether or not trust site.

uialertview *alert = [[uialertview alloc] initwithtitle: [[challenge protectionspace]host] message:@"do trust site?"  delegate:self cancelbuttontitle:@"no"  otherbuttontitles:@"yes", @"just once", nil];  [alert show]; 

how can that?

as example can save challenge object property , implement alertview:clickedbuttonatindex: delegate method (this "trust once"):

- (void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex {     if(buttonindex == alertview.cancelbuttonindex)     {         [[self.challenge sender] cancelauthenticationchallenge:self.challenge];     }     else     {         [self.challenge.sender usecredential:[nsurlcredential credentialfortrust:self.challenge.protectionspace.servertrust] forauthenticationchallenge:self.challenge];         self.challenge = nil;     } } 

if want trust need more complex things save , compare server certificate data. or make simple , unsafe saving server url should trusted, makes vulnerable man in middle attacks.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -