Skip to content

Commit 31de04a

Browse files
committed
Fix broken keychain access with SSH on 10.6 (fixes #2268)
(From the department of commits to be rolled back soon)
1 parent d4641ec commit 31de04a

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

Source/SPKeychain.m

+22-17
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#import "SPKeychain.h"
3333
#import "SPAlertSheets.h"
34+
#import "SPOSInfo.h"
3435

3536
#import <Security/Security.h>
3637
#import <CoreFoundation/CoreFoundation.h>
@@ -212,33 +213,38 @@ - (void)deletePasswordForName:(NSString *)name account:(NSString *)account
212213
- (BOOL)passwordExistsForName:(NSString *)name account:(NSString *)account
213214
{
214215
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
215-
NSMutableDictionary *query = [NSMutableDictionary dictionary];
216-
217-
[query setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass];
218-
[query setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnAttributes];
219-
[query setObject:(id)kSecMatchLimitOne forKey:(id)kSecMatchLimit];
220-
221-
[query setObject:account forKey:(id)kSecAttrAccount];
222-
[query setObject:name forKey:(id)kSecAttrService];
223-
224-
CFDictionaryRef result = NULL;
225-
226-
return SecItemCopyMatching((CFDictionaryRef)query, (CFTypeRef *)&result) == errSecSuccess;
227-
#else
216+
// "kSecClassGenericPassword" was introduced with the 10.7 SDK.
217+
// It won't work on 10.6 either (meaning this code never matches properly there).
218+
// (That's why there are compile time and runtime checks here)
219+
if([SPOSInfo isOSVersionAtLeastMajor:10 minor:7 patch:0]) {
220+
NSMutableDictionary *query = [NSMutableDictionary dictionary];
221+
222+
[query setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass];
223+
[query setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnAttributes];
224+
[query setObject:(id)kSecMatchLimitOne forKey:(id)kSecMatchLimit];
225+
226+
[query setObject:account forKey:(id)kSecAttrAccount];
227+
[query setObject:name forKey:(id)kSecAttrService];
228+
229+
CFDictionaryRef result = NULL;
230+
231+
return SecItemCopyMatching((CFDictionaryRef)query, (CFTypeRef *)&result) == errSecSuccess;
232+
}
233+
#endif
228234
SecKeychainItemRef item;
229235
SecKeychainSearchRef search = NULL;
230236
NSInteger numberOfItemsFound = 0;
231237
SecKeychainAttributeList list;
232238
SecKeychainAttribute attributes[2];
233-
239+
234240
// Check supplied variables and replaces nils with empty strings
235241
if (!name) name = @"";
236242
if (!account) account = @"";
237-
243+
238244
attributes[0].tag = kSecAccountItemAttr;
239245
attributes[0].data = (void *)[account UTF8String]; // Account name
240246
attributes[0].length = (UInt32)strlen([account UTF8String]); // Length of account name (bytes)
241-
247+
242248
attributes[1].tag = kSecServiceItemAttr;
243249
attributes[1].data = (void *)[name UTF8String]; // Service name
244250
attributes[1].length = (UInt32)strlen([name UTF8String]); // Length of service name (bytes)
@@ -257,7 +263,6 @@ - (BOOL)passwordExistsForName:(NSString *)name account:(NSString *)account
257263
if (search) CFRelease(search);
258264

259265
return (numberOfItemsFound > 0);
260-
#endif
261266
}
262267

263268
/**

Source/SPOSInfo.m

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030

3131
#import "SPOSInfo.h"
3232

33+
// Needed because this class is also compiled with SequelProTunnelAssistant which can't access SPConstants.h
34+
#ifndef __MAC_10_10
35+
#define __MAC_10_10 101000
36+
#endif
37+
3338
#if __MAC_OS_X_VERSION_MAX_ALLOWED < __MAC_10_10
3439
// This code is available since 10.8 but public only since 10.10
3540
typedef struct {

sequel-pro.xcodeproj/project.pbxproj

+2
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
506CE9311A311C6C0039F736 /* SPTableContentFilterController.m in Sources */ = {isa = PBXBuildFile; fileRef = 506CE9301A311C6C0039F736 /* SPTableContentFilterController.m */; };
192192
507FF1121BBCC57600104523 /* SPFunctions.m in Sources */ = {isa = PBXBuildFile; fileRef = 507FF1111BBCC57600104523 /* SPFunctions.m */; };
193193
507FF1621BBF0D5000104523 /* SPTableCopyTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 112730551180788A000737FD /* SPTableCopyTest.m */; };
194+
507FF2421BC33BBC00104523 /* SPOSInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 50EAB5B71A8FBB08008F627A /* SPOSInfo.m */; };
194195
50A9F8B119EAD4B90053E571 /* SPGotoDatabaseController.m in Sources */ = {isa = PBXBuildFile; fileRef = 50A9F8B019EAD4B90053E571 /* SPGotoDatabaseController.m */; };
195196
50D3C3491A75B8A800B5429C /* GotoDatabaseDialog.xib in Resources */ = {isa = PBXBuildFile; fileRef = 50D3C34B1A75B8A800B5429C /* GotoDatabaseDialog.xib */; };
196197
50D3C3521A77135F00B5429C /* SPParserUtils.c in Sources */ = {isa = PBXBuildFile; fileRef = 50D3C3501A77135F00B5429C /* SPParserUtils.c */; };
@@ -3140,6 +3141,7 @@
31403141
isa = PBXSourcesBuildPhase;
31413142
buildActionMask = 2147483647;
31423143
files = (
3144+
507FF2421BC33BBC00104523 /* SPOSInfo.m in Sources */,
31433145
586F457B0FDB269E00B428D7 /* RegexKitLite.m in Sources */,
31443146
58CDB3410FCE141900F8ACA3 /* SequelProTunnelAssistant.m in Sources */,
31453147
58CDB3420FCE142500F8ACA3 /* SPKeychain.m in Sources */,

0 commit comments

Comments
 (0)