aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPKeychain.m
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2015-10-06 01:31:09 +0200
committerMax <post@wickenrode.com>2015-10-06 01:46:50 +0200
commit0f5ae461ea1f33cea1d7e7364a3f9e1574200755 (patch)
treed1326668e6d6c0baf0f08b4c608379442a64b31b /Source/SPKeychain.m
parent85853c0f4c6737fc7537e02b0ee1d8da123f0a3d (diff)
downloadsequelpro-0f5ae461ea1f33cea1d7e7364a3f9e1574200755.tar.gz
sequelpro-0f5ae461ea1f33cea1d7e7364a3f9e1574200755.tar.bz2
sequelpro-0f5ae461ea1f33cea1d7e7364a3f9e1574200755.zip
Fix broken keychain access with SSH on 10.6 (fixes #2268)
(From the department of commits to be rolled back soon) Conflicts: sequel-pro.xcodeproj/project.pbxproj
Diffstat (limited to 'Source/SPKeychain.m')
-rw-r--r--Source/SPKeychain.m39
1 files changed, 22 insertions, 17 deletions
diff --git a/Source/SPKeychain.m b/Source/SPKeychain.m
index ac7bd390..48283359 100644
--- a/Source/SPKeychain.m
+++ b/Source/SPKeychain.m
@@ -31,6 +31,7 @@
#import "SPKeychain.h"
#import "SPAlertSheets.h"
+#import "SPOSInfo.h"
#import <Security/Security.h>
#import <CoreFoundation/CoreFoundation.h>
@@ -212,33 +213,38 @@
- (BOOL)passwordExistsForName:(NSString *)name account:(NSString *)account
{
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
- NSMutableDictionary *query = [NSMutableDictionary dictionary];
-
- [query setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass];
- [query setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnAttributes];
- [query setObject:(id)kSecMatchLimitOne forKey:(id)kSecMatchLimit];
-
- [query setObject:account forKey:(id)kSecAttrAccount];
- [query setObject:name forKey:(id)kSecAttrService];
-
- CFDictionaryRef result = NULL;
-
- return SecItemCopyMatching((CFDictionaryRef)query, (CFTypeRef *)&result) == errSecSuccess;
-#else
+ // "kSecClassGenericPassword" was introduced with the 10.7 SDK.
+ // It won't work on 10.6 either (meaning this code never matches properly there).
+ // (That's why there are compile time and runtime checks here)
+ if([SPOSInfo isOSVersionAtLeastMajor:10 minor:7 patch:0]) {
+ NSMutableDictionary *query = [NSMutableDictionary dictionary];
+
+ [query setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass];
+ [query setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnAttributes];
+ [query setObject:(id)kSecMatchLimitOne forKey:(id)kSecMatchLimit];
+
+ [query setObject:account forKey:(id)kSecAttrAccount];
+ [query setObject:name forKey:(id)kSecAttrService];
+
+ CFDictionaryRef result = NULL;
+
+ return SecItemCopyMatching((CFDictionaryRef)query, (CFTypeRef *)&result) == errSecSuccess;
+ }
+#endif
SecKeychainItemRef item;
SecKeychainSearchRef search = NULL;
NSInteger numberOfItemsFound = 0;
SecKeychainAttributeList list;
SecKeychainAttribute attributes[2];
-
+
// Check supplied variables and replaces nils with empty strings
if (!name) name = @"";
if (!account) account = @"";
-
+
attributes[0].tag = kSecAccountItemAttr;
attributes[0].data = (void *)[account UTF8String]; // Account name
attributes[0].length = (UInt32)strlen([account UTF8String]); // Length of account name (bytes)
-
+
attributes[1].tag = kSecServiceItemAttr;
attributes[1].data = (void *)[name UTF8String]; // Service name
attributes[1].length = (UInt32)strlen([name UTF8String]); // Length of service name (bytes)
@@ -257,7 +263,6 @@
if (search) CFRelease(search);
return (numberOfItemsFound > 0);
-#endif
}
/**