Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSL Error in Connection to Server through iPhone

I am trying to establish a HTTPS connection to a server using my app. But the connection fails due to following error

Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo=0x612eb30 {NSErrorFailingURLStringKey=https:myURL.com/signup, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, NSErrorFailingURLKey=https:myURL.com/signup, NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSUnderlyingError=0x612eb70 "An SSL error has occurred and a secure connection to the server cannot be made."}

The code to connect to server is

-(IBAction) handleEvents:(id)sender  {     if ((UIButton*)sender == submit) {      [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;       NSLog(@"Begin");     NSData *urlData;     NSURLResponse *response;     NSError *error;      NSString *url =[[NSString alloc]initWithFormat:@"%@signup",baseURL];     NSURL *theURL =[NSURL URLWithString:url];     NSMutableURLRequest *theRequest =[NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:0.0f];     [theRequest setHTTPMethod:@"POST"];     NSString *theBodyString = [NSString stringWithFormat:@"emailId=%@&mobileNumber=%@&appId=%@&password=%@&firstName=%@&lastName=%@"                                ,@"[email protected]",@"919879876780",@"bf1c7a6b3d266a7fe350fcfc4dda275211c13c23" ,@"qwerty" , @"Dev" , @"Sri"];     NSData *theBodyData = [theBodyString dataUsingEncoding:NSUTF8StringEncoding];      [theRequest setHTTPBody:theBodyData];     urlData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];     } } 

my delegate methods are

- (void)handleError:(NSError *)error { NSLog(@"----->%@",error); }  - (void)connectionDidFinishLoading:(NSURLConnection *)connection {   [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;      }  - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {     return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];    }  - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge (NSURLAuthenticationChallenge *)challenge {       NSLog(@"check auth");     [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];    } 

I am stuck over here and could not find any way out.

Any form of help would be greatly appreciated.

thanks in advance!!

like image 558
devsri Avatar asked Feb 18 '11 11:02

devsri


People also ask

How do I enable SSL on my iPhone?

If you want to turn on SSL/TLS trust for that certificate, go to Settings > General > About > Certificate Trust Settings. Under "Enable full trust for root certificates," turn on trust for the certificate.

Why does my phone keep saying SSL connection error?

Many times the reason for an SSL connection error is as simple as a mismatch between your device's and the web server's time & date. Especially when the dates are different. To fix this error all you need to do is to enable automatic time and date set up in the settings.

What does SSL mean on my iPhone?

The Secure Sockets Layer (SSL) provides encryption for TCP/IP connections as they transit the Internet and local networks between a client and a server. In the case of iPhone email, SSL encrypts all of the communication between your phone and your mail server.


2 Answers

Since it has been left unanswered for long time and my research and current development indicates that the code is perfectly fine for the connection, its the certificate at the server that was not signed by an authorized CA. so anyone having such kind of problem check that the certificate is valid at server end or not.

Hope this would help!!

like image 29
devsri Avatar answered Sep 18 '22 04:09

devsri


iOS 9 forces connections that are using HTTPS to be TLS 1.2 to avoid recent vulnerabilities. In iOS 8 even unencrypted HTTP connections were supported, so that older versions of TLS didn't make any problems either. As a workaround, you can add this code snippet to your Info.plist:

  <key>NSAppTransportSecurity</key>     <dict>     <key>NSAllowsArbitraryLoads</key>     <true/>     </dict>   

Thereby you're disabling the App Transport Security. Hope that's helpful.

like image 70
Voda Ion Avatar answered Sep 20 '22 04:09

Voda Ion