1
0
mirror of https://github.com/moparisthebest/curl synced 2024-08-13 17:03:50 -04:00

darwinssl: fix build error in crypto authentication under Snow Leopard

It turns out Snow Leopard not only has SecItemCopyMatching() defined in
a header not included by the omnibus header, but it won't work for our
purposes, because searching for SecIdentityRef objects wasn't added
to that API until Lion. So we now use the old SecKeychainSearch API
instead if the user is building under, or running under, Snow Leopard.

Bug: http://sourceforge.net/p/curl/bugs/1255/
Reported by: Edward Rudd
This commit is contained in:
Nick Zitzmann 2013-07-30 20:25:38 -06:00
parent c3e7210548
commit 537ffc4c69

View File

@ -74,12 +74,10 @@
#define CURL_BUILD_MAC_10_6 0 #define CURL_BUILD_MAC_10_6 0
#define CURL_BUILD_MAC_10_7 0 #define CURL_BUILD_MAC_10_7 0
#define CURL_BUILD_MAC_10_8 0 #define CURL_BUILD_MAC_10_8 0
#define CURL_BUILD_MAC_10_9 0
#define CURL_SUPPORT_MAC_10_5 0 #define CURL_SUPPORT_MAC_10_5 0
#define CURL_SUPPORT_MAC_10_6 0 #define CURL_SUPPORT_MAC_10_6 0
#define CURL_SUPPORT_MAC_10_7 0 #define CURL_SUPPORT_MAC_10_7 0
#define CURL_SUPPORT_MAC_10_8 0 #define CURL_SUPPORT_MAC_10_8 0
#define CURL_SUPPORT_MAC_10_9 0
#else #else
#error "The darwinssl back-end requires iOS or OS X." #error "The darwinssl back-end requires iOS or OS X."
@ -728,7 +726,7 @@ CF_INLINE CFStringRef CopyCertSubject(SecCertificateRef cert)
return server_cert_summary; return server_cert_summary;
} }
#if CURL_SUPPORT_MAC_10_6 #if CURL_SUPPORT_MAC_10_7
/* The SecKeychainSearch API was deprecated in Lion, and using it will raise /* The SecKeychainSearch API was deprecated in Lion, and using it will raise
deprecation warnings, so let's not compile this unless it's necessary: */ deprecation warnings, so let's not compile this unless it's necessary: */
static OSStatus CopyIdentityWithLabelOldSchool(char *label, static OSStatus CopyIdentityWithLabelOldSchool(char *label,
@ -768,17 +766,18 @@ static OSStatus CopyIdentityWithLabelOldSchool(char *label,
CFRelease(search); CFRelease(search);
return status; return status;
} }
#endif /* CURL_SUPPORT_MAC_10_6 */ #endif /* CURL_SUPPORT_MAC_10_7 */
static OSStatus CopyIdentityWithLabel(char *label, static OSStatus CopyIdentityWithLabel(char *label,
SecIdentityRef *out_cert_and_key) SecIdentityRef *out_cert_and_key)
{ {
OSStatus status = errSecItemNotFound; OSStatus status = errSecItemNotFound;
#if CURL_BUILD_MAC_10_6 || CURL_BUILD_IOS #if CURL_BUILD_MAC_10_7 || CURL_BUILD_IOS
/* SecItemCopyMatching() was introduced in iOS and Snow Leopard. If it /* SecItemCopyMatching() was introduced in iOS and Snow Leopard.
exists, let's use that to find the certificate. */ kSecClassIdentity was introduced in Lion. If both exist, let's use them
if(SecItemCopyMatching != NULL) { to find the certificate. */
if(SecItemCopyMatching != NULL && kSecClassIdentity != NULL) {
CFTypeRef keys[4]; CFTypeRef keys[4];
CFTypeRef values[4]; CFTypeRef values[4];
CFDictionaryRef query_dict; CFDictionaryRef query_dict;
@ -807,15 +806,16 @@ static OSStatus CopyIdentityWithLabel(char *label,
CFRelease(query_dict); CFRelease(query_dict);
} }
else { else {
#if CURL_SUPPORT_MAC_10_6 #if CURL_SUPPORT_MAC_10_7
/* On Leopard, fall back to SecKeychainSearch. */ /* On Leopard and Snow Leopard, fall back to SecKeychainSearch. */
status = CopyIdentityWithLabelOldSchool(label, out_cert_and_key); status = CopyIdentityWithLabelOldSchool(label, out_cert_and_key);
#endif /* CURL_SUPPORT_MAC_10_6 */ #endif /* CURL_SUPPORT_MAC_10_7 */
} }
#elif CURL_SUPPORT_MAC_10_6 #elif CURL_SUPPORT_MAC_10_7
/* For developers building on Leopard, we have no choice but to fall back. */ /* For developers building on older cats, we have no choice but to fall back
to SecKeychainSearch. */
status = CopyIdentityWithLabelOldSchool(label, out_cert_and_key); status = CopyIdentityWithLabelOldSchool(label, out_cert_and_key);
#endif /* CURL_BUILD_MAC_10_6 || CURL_BUILD_IOS */ #endif /* CURL_BUILD_MAC_10_7 || CURL_BUILD_IOS */
return status; return status;
} }