Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

adriweb

macrumors newbie
Original poster
Oct 23, 2010
13
1
France
Hello,

I've been looking for a solution to connection to a self-signed certificate server (https://web-toulon.isen.fr) from a UIWebView. I still can't make it work, but I saw this stackoverflow topic : http://stackoverflow.com/questions/933331/how-to-use-nsurlconnection-to-connect-with-ssl-for-an-untrusted-cert and I don't know how to implement this on my project.

I'm kind of new to iPhone development, so can you tell me how and where I can write the piece of code given in the topic in order to make it work properly ?

Here is what I currently have for the loading part (so, it's pretty basic)

Code:
[moodle loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://web-toulon.isen.fr/moodle/"]]];
So, That doesn't work, unless I write this private API in the AppDelegate :

Code:
@implementation NSURLRequest(IgnoreSSL)

+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
{
		return YES;
}
@end


What I basically want to do is to avoid this private API call :
Code:
+(BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host


Is there anything 'simple' (well, if it's not simple but if it works, it's great too :) ) that can do what I'm looking for ?



Thanks a lot for your help !

Adrien Bertrand
 
Hi Adrien,

Yeah, Self Signed SSL Certificates require a little bit of work.

There is an iOS Sample that shows you how to do it. It even has code to remember self-signed certificates that the user has accepted -- probably more than you need for this.

The Sample is called "Advanced URL Connections". If you search the SDK Documentation you will find it.

Basically, you need to handle some NSURLConnection Delegate Calls:

Code:
- (BOOL)connection:(NSURLConnection *)connection 
canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)space

^--- return YES if the authenticationMethod is "NSURLAuthenticationMethodServerTrust"

and

Code:
- (void)connection:(NSURLConnection *)connection 
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge

^--- you need to respond to this using something like the call below:

Code:
[[challenge sender] useCredential:[NSURLCredential 
   credentialForTrust:challenge.protectionSpace.serverTrust]
   forAuthenticationChallenge:challenge];

You will want to look up these methods in the SDK Documentation to get a better idea of how they work.

Let us know if you get stuck on anything in particular.
 
Thanks a lot for replying.

I'll look more into that but I think I made the ASIHTTPRequest library working, so it might be easier with that :)
 
Thanks a lot for replying.

I'll look more into that but I think I made the ASIHTTPRequest library working, so it might be easier with that :)

The ASI library is very nice. It does have a method you can call to accept SSL Certificates.

Good luck with your project!

- Don
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.