+// returns true if the provided certificate contains a wildcard in either
+// its common name or subject alternative name.
+//
+static
+bool hasWildcardDNSName(SecCertificateRef certRef)
+{
+ OSStatus status = errSecSuccess;
+ CFArrayRef dnsNames = NULL;
+
+ BEGIN_SECAPI_INTERNAL_CALL
+ Required(&dnsNames) = Certificate::required(certRef)->copyDNSNames();
+ END_SECAPI_INTERNAL_CALL
+ if (status || !dnsNames)
+ return false;
+
+ bool hasWildcard = false;
+ const CFStringRef wildcard = CFSTR("*");
+ CFIndex index, count = CFArrayGetCount(dnsNames);
+ for (index = 0; index < count; index ++) {
+ CFStringRef name = (CFStringRef) CFArrayGetValueAtIndex(dnsNames, index);
+ if (name) {
+ CFRange foundRange = CFStringFind(name, wildcard, 0);
+ if (foundRange.length != 0 && foundRange.location != kCFNotFound) {
+ hasWildcard = true;
+ break;
+ }
+ }
+ }
+ CFRelease(dnsNames);
+ return hasWildcard;
+}
+