From 6a9a22f81e053de5793b0a1d75e1f7f3c0f18bcc Mon Sep 17 00:00:00 2001 From: Jaroslav Pavlicek Date: Tue, 14 Sep 2021 11:42:01 +0200 Subject: [PATCH] Added support for intermediate certificates on iOS --- src/ios/CordovaHttpPlugin.m | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ios/CordovaHttpPlugin.m b/src/ios/CordovaHttpPlugin.m index b4f04b4..5ff6ed6 100644 --- a/src/ios/CordovaHttpPlugin.m +++ b/src/ios/CordovaHttpPlugin.m @@ -404,8 +404,18 @@ } else { CFDictionaryRef identityDict = CFArrayGetValueAtIndex(items, 0); SecIdentityRef identity = (SecIdentityRef)CFDictionaryGetValue(identityDict, kSecImportItemIdentity); + SecTrustRef trust = (SecTrustRef)CFDictionaryGetValue(identityDict, kSecImportItemTrust); - self->x509Credential = [NSURLCredential credentialWithIdentity:identity certificates: nil persistence:NSURLCredentialPersistenceForSession]; + int count = (int)SecTrustGetCertificateCount(trust); + NSMutableArray* trustCertificates = nil; + if (count > 1) { + trustCertificates = [NSMutableArray arrayWithCapacity:SecTrustGetCertificateCount(trust)]; + for (int i=1;ix509Credential = [NSURLCredential credentialWithIdentity:identity certificates: trustCertificates persistence:NSURLCredentialPersistenceForSession]; CFRelease(items); pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];