ios - NSURLConnection: Use all CA certificates installed on device -


i want access web ressources using https in custom ios 6 app. target servers using certificate signed ca not default included in ios, manually added keychain of device. therefore urls can opened in safari without warning or error.

what want achieve same behavior safari: want load websites if safari have trusted them, or deny load them in case of error. installed certificates can change case case not want manually include certificates in application ressources, many questions here @ about.

my problem not sectrustevaluate return ksectrustresultproceed. have idea can do?

if canauthenticateagainstprotectionspace returns no, ios handles server certificate check on itself, not seem check additionally installed certificates (as safari does).

here code try , understand got far:

- (void)viewdidload {     [super viewdidload];     [self loadurlwithstring:@"https://myserver.com"]; }  + (bool) ischallenge: (nsurlauthenticationchallenge*) challenge validforconnection: (nsurlconnection*)conn{     sectrustref servertrust=[[challenge protectionspace] servertrust];      //some magic here?      // check server certificate     sectrustresulttype evalresult;     if(sectrustevaluate(servertrust,&evalresult) != errsecsuccess){         nslog(@"call sectrustevaluate failed");         return no;     }     if(evalresult != ksectrustresultproceed){         nslog(@"server certificate invalid");         return no;     }     nslog(@"server certificate valid");     return yes; }  - (void)loadurlwithstring: (nsstring*)str{     nsurlconnection *conn =         [nsurlconnection connectionwithrequest:[nsurlrequest requestwithurl:[nsurl urlwithstring:str]] delegate:self];     [conn start]; }   - (void)connection:(nsurlconnection *)connection didreceiveauthenticationchallenge:(nsurlauthenticationchallenge *)challenge{     if([[self class] ischallenge:challenge validforconnection:connection])         [challenge.sender continuewithoutcredentialforauthenticationchallenge:challenge];     else         [challenge.sender cancelauthenticationchallenge:challenge]; }  - (bool)connection:(nsurlconnection *)connection canauthenticateagainstprotectionspace:(nsurlprotectionspace *)protectionspace{     return [protectionspace.authenticationmethod isequaltostring:nsurlauthenticationmethodservertrust]; }  - (void)connection:(nsurlconnection *)connection didfailwitherror:(nserror *)error{     nslog(@"failed error: %@",error); }  - (void)connectiondidfinishloading:(nsurlconnection *)connection{     nslog(@"loading complete"); }  - (void)connection:(nsurlconnection *)connection didreceiveresponse:(nsurlresponse *)response{  }   - (void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data{  } 

what you're trying not permitted. more info, see thread in apple developer forums:

https://devforums.apple.com/message/660579#660579


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -