+
+ /* "certs-only" CMS Message */
+ if (!parent) {
+ CFArrayRef certificates = NULL;
+ certificates = SecCMSCertificatesOnlyMessageCopyCertificates(data);
+ if (certificates && CFArrayGetCount(certificates) == 1) {
+ parent = (SecCertificateRef)CFRetainSafe(CFArrayGetValueAtIndex(certificates, 0));
+ }
+ CFReleaseNull(certificates);
+ }
+
+ /* Retry in case the certificate is in PEM format. Some CAs
+ incorrectly return a PEM encoded cert, despite RFC 5280 4.2.2.1 */
+ if (!parent) {
+ parent = SecCertificateCreateWithPEM(NULL, data);
+ }