Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS - Install SSL certificate programmatically
    primarykey
    data
    text
    <p>I'm writing a phonegap plugin that installs both CA root certificate and user certificate in the app keychain.</p> <p>Here is the code used to install the certificate:</p> <pre><code>NSData *PKCS12Data = [[NSData alloc] initWithContentsOfFile:certpath]; CFDataRef inPKCS12Data = (CFDataRef)PKCS12Data; CFStringRef password = (CFStringRef)certPassword; const void *keys[] = { kSecImportExportPassphrase }; const void *values[] = { password }; CFDictionaryRef optionsDictionary = CFDictionaryCreate(NULL, keys, values, 1, NULL, NULL); CFArrayRef items = CFArrayCreate(NULL, 0, 0, NULL); OSStatus securityError = SecPKCS12Import(inPKCS12Data, optionsDictionary, &amp;items); if (securityError == 0) { NSLog(@" *** Certificate install Success ***"); } else { NSLog(@" *** Certificate install Failure ***"); } </code></pre> <p>The code above works fine (securityError equals 0). However, I'm obtaining those errors:</p> <pre><code>unknown apsd[59] &lt;Warning&gt;: &lt;APSCourier: 0xee1ba80&gt;: Stream error occurred for &lt;APSTCPStream: 0x126940&gt;: TLS Error Code=-9844 "peer dropped connection before responding" unknown securityd[638] &lt;Error&gt;: CFReadStream domain: 12 error: 8 </code></pre> <p>That indicates that the device does not accept the installed certificate, so i'm wondering that the certificate is not validated against the CA Root certificate installed on the device.</p> <p>Do I have to install the CA Root certificate for the app ?</p> <p>Any ideas ?</p> <p>P.S: I'm new to Objective-C and XCode environment.</p> <p><strong><em>EDIT:</em></strong></p> <p>The code below is used to store CA root certificat in keychain:</p> <pre><code>NSString *rootCertPath = [[NSBundle mainBundle] pathForResource:@"rootca" ofType:@"cer"]; NSData *rootCertData = [NSData dataWithContentsOfFile:rootCertPath]; OSStatus err = noErr; SecCertificateRef rootCert = SecCertificateCreateWithData(kCFAllocatorDefault, (CFDataRef) rootCertData); CFTypeRef result; NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys: (id)kSecClassCertificate, kSecClass, rootCert, kSecValueRef, nil]; err = SecItemAdd((CFDictionaryRef)dict, &amp;result); if( err == noErr) { NSLog(@"Install root certificate success"); } else if( err == errSecDuplicateItem ) { NSLog(@"duplicate root certificate entry"); } else { NSLog(@"install root certificate failure"); } </code></pre> <p><strong>EDIT</strong>:</p> <p>It seems that the certificate is not sent to server. I think that I have to send manually the certificate each time an https request is made... I'm looking for a way to catch every https call in phonegap.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload