aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/SPKeychain.m27
-rw-r--r--Source/TableDocument.m9
2 files changed, 28 insertions, 8 deletions
diff --git a/Source/SPKeychain.m b/Source/SPKeychain.m
index 9aea5248..0929317d 100644
--- a/Source/SPKeychain.m
+++ b/Source/SPKeychain.m
@@ -48,7 +48,12 @@
SecAccessRef passwordAccessRef;
SecKeychainAttribute attributes[4];
SecKeychainAttributeList attList;
-
+
+ // Check supplied variables and replaces nils with empty strings
+ if (!name) name = @"";
+ if (!account) account = @"";
+ if (!label) label = @"";
+
// Check if password already exists before adding
if (![self passwordExistsForName:name account:account]) {
@@ -109,7 +114,11 @@
UInt32 passwordLength;
SecKeychainItemRef itemRef;
NSString *password = @"";
-
+
+ // Check supplied variables and replaces nils with empty strings
+ if (!name) name = @"";
+ if (!account) account = @"";
+
status = SecKeychainFindGenericPassword(
NULL, // default keychain
strlen([name UTF8String]), // length of service name (bytes)
@@ -142,6 +151,10 @@
OSStatus status;
SecKeychainItemRef itemRef = nil;
+ // Check supplied variables and replaces nils with empty strings
+ if (!name) name = @"";
+ if (!account) account = @"";
+
// Check if password already exists before deleting
if ([self passwordExistsForName:name account:account]) {
status = SecKeychainFindGenericPassword(
@@ -177,7 +190,11 @@
int 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 = strlen([account UTF8String]); // Length of account name (bytes)
@@ -209,7 +226,7 @@
NSString *keychainItemName;
keychainItemName = [NSString stringWithFormat:@"Sequel Pro : %@ (%i)",
- theName,
+ theName?theName:@"",
[theID intValue]];
return keychainItemName;
@@ -238,7 +255,7 @@
NSString *sshKeychainItemName;
sshKeychainItemName = [NSString stringWithFormat:@"Sequel Pro SSHTunnel : %@ (%i)",
- theName,
+ theName?theName:@"",
[theID intValue]];
return sshKeychainItemName;
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index a7c0d176..c36a2e35 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -2426,11 +2426,14 @@
* Invoked when the current connection needs a password from the Keychain.
*/
- (NSString *)keychainPasswordForConnection:(MCPConnection *)connection
-{
- SPKeychain *keychain = [[SPKeychain alloc] init];
+{
+ // If no keychain item is available, return an empty password
+ if (![connectionController connectionKeychainItemName]) return @"";
+
+ // Otherwise, pull the password from the keychain using the details from this connection
+ SPKeychain *keychain = [[SPKeychain alloc] init];
NSString *password = [keychain getPasswordForName:[connectionController connectionKeychainItemName] account:[connectionController connectionKeychainItemAccount]];
-
[keychain release];
return password;