HTTPS request on old iphone 3g
Asked Answered
J

2

5

Anyone else having issues with getting a https request working on the old iphone.

From connection did fail with error the error message is as follows.

ERROR with theConnection:Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “www.ourwesbite.co.uk” which could put your confidential information at risk."

The "ourwebsite" has a valid certificate and also this problem does not arise in any new iphone/ipod touch or ipads just the oldest iphones.

This is affecting my login from working by throwing a connection error after user clicks ok to the connection error alert the login process runs through fine. But the problem is its affecting the UI after the login.

So pretty much want to know if anyone else is having issues like this with the old iphone. There is no problem with my code as it works perfectly fine on simulator & ipad/4gen ipod touch.

Thanks

Jurist answered 1/2, 2011 at 9:54 Comment(1)
What iOS version is the iPhone 3G running? Are you performing an async NSURLConnection?Sandrasandro
J
2

Ok so even tho the certificate is valid it will throws the error. So using the following delegate method for NSURLConnection solved this problem.

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

it gets called when there is a challenge to the authentication. The the following bit of code allow's it to continue with the https connection.

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

And then that allows the connection through if it feels it is untrusted

Jurist answered 2/2, 2011 at 9:55 Comment(0)
H
8

We had this error and the iPhone 3g in question had an incorrect date and time set. This meant all SSL transactions would fail.

We assumed that this iOS bug is an apple problem not ours and so hacking the SSL certificate to be ignored is not the solution!

Huneycutt answered 1/9, 2011 at 12:28 Comment(0)
J
2

Ok so even tho the certificate is valid it will throws the error. So using the following delegate method for NSURLConnection solved this problem.

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

it gets called when there is a challenge to the authentication. The the following bit of code allow's it to continue with the https connection.

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

And then that allows the connection through if it feels it is untrusted

Jurist answered 2/2, 2011 at 9:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.