Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On ios, in ionic hybrid app, how to bypass certificate check (using self-signed certificates)

My ionic/cordova app now gives errors when used with HTTPS backend

`The certificate for this server is invalid`

I am in my development environment, use self-signed certificates, and use IP address to connect with the backend.

I examined the certificate using openssl s_client and it looks valid. As a matter of fact I am able to use the same backend with android version of this hybrid app.

Is there some plist or other Xcode setting to accept a self-signed certificate or ignore this test all together - similar to NSAppTransportSecurity::NSAllowsArbitraryLoads setting?

--EDIT

I have <access origin="*"/> in my config.xml file.

Thanks a lot

like image 285
Dinesh Avatar asked Jan 14 '16 01:01

Dinesh


People also ask

How do I trust a self-signed certificate 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. Apple recommends deploying certificates via Apple Configurator or Mobile Device Management (MDM).

How do you check if a certificate is self-signed or not?

A certificate is self-signed if the subject and issuer match. A certificate is signed by a Certificate Authority (CA) if they are different. To validate a CA-signed certificate, you also need a CA certificate.


1 Answers

You can add this at the end of AppDelegate.m, but just for testing purposes, you should remove it before releasing the app, apple might not approve the app if it contains that code

@implementation NSURLRequest(DataController)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
{
    return YES;
}
@end
like image 190
jcesarmobile Avatar answered Oct 13 '22 00:10

jcesarmobile