diff options
author | Max <post@wickenrode.com> | 2018-02-23 20:56:44 +0100 |
---|---|---|
committer | Max <post@wickenrode.com> | 2018-02-23 20:56:44 +0100 |
commit | ca864a1f887feaf7ac6d35eeb55b265f3e630a09 (patch) | |
tree | 8746370d8785d9030a52383c5dfbef48bfc05d2c | |
parent | 770c18901f82696d1233e0139e9bb3c4fbbcb90b (diff) | |
download | sequelpro-ca864a1f887feaf7ac6d35eeb55b265f3e630a09.tar.gz sequelpro-ca864a1f887feaf7ac6d35eeb55b265f3e630a09.tar.bz2 sequelpro-ca864a1f887feaf7ac6d35eeb55b265f3e630a09.zip |
Remove the keychain id stuff from SPDatabaseDocument. It was only proxying SPConnectionController anyway
-rw-r--r-- | Source/SPConnectionController.h | 2 | ||||
-rw-r--r-- | Source/SPConnectionController.m | 20 | ||||
-rw-r--r-- | Source/SPDatabaseDocument.h | 3 | ||||
-rw-r--r-- | Source/SPDatabaseDocument.m | 37 |
4 files changed, 27 insertions, 35 deletions
diff --git a/Source/SPConnectionController.h b/Source/SPConnectionController.h index 03f8fc3b..9da0d996 100644 --- a/Source/SPConnectionController.h +++ b/Source/SPConnectionController.h @@ -208,6 +208,7 @@ @property (readwrite, assign) NSInteger sshKeyLocationEnabled; @property (readwrite, retain) NSString *sshKeyLocation; @property (readwrite, retain) NSString *sshPort; +@property (readwrite, copy, nonatomic) NSString *connectionKeychainID; @property (readwrite, retain) NSString *connectionKeychainItemName; @property (readwrite, retain) NSString *connectionKeychainItemAccount; @property (readwrite, retain) NSString *connectionSSHKeychainItemName; @@ -222,6 +223,7 @@ @property (readonly, assign) BOOL isEditingConnection; - (NSString *)keychainPassword; +- (NSString *)keychainPasswordForSSH; // Connection processes - (IBAction)initiateConnection:(id)sender; diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index 02f68b06..467aa303 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -168,6 +168,7 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, @synthesize dbDocument; #endif +@synthesize connectionKeychainID = connectionKeychainID; @synthesize connectionKeychainItemName; @synthesize connectionKeychainItemAccount; @synthesize connectionSSHKeychainItemName; @@ -188,6 +189,16 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, return kcPassword; } +- (NSString *)keychainPasswordForSSH +{ + if (![self connectionKeychainItemName]) return nil; + + // Otherwise, pull the password from the keychain using the details from this connection + NSString *kcSSHPassword = [keychain getPasswordForName:connectionSSHKeychainItemName account:connectionSSHKeychainItemAccount]; + + return kcSSHPassword; +} + #pragma mark - #pragma mark Connection processes @@ -749,7 +760,7 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, #ifndef SP_CODA // Clear the keychain referral items as appropriate - if (connectionKeychainID) SPClear(connectionKeychainID); + [self setConnectionKeychainID:nil]; if (connectionKeychainItemName) SPClear(connectionKeychainItemName); if (connectionKeychainItemAccount) SPClear(connectionKeychainItemAccount); if (connectionSSHKeychainItemName) SPClear(connectionSSHKeychainItemName); @@ -816,7 +827,7 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, } // Store the selected favorite ID for use with the document on connection - if ([fav objectForKey:SPFavoriteIDKey]) connectionKeychainID = [[[fav objectForKey:SPFavoriteIDKey] stringValue] retain]; + if ([fav objectForKey:SPFavoriteIDKey]) [self setConnectionKeychainID:[[fav objectForKey:SPFavoriteIDKey] stringValue]]; // And the same for the SSH password connectionSSHKeychainItemName = [[keychain nameForSSHForFavoriteName:[fav objectForKey:SPFavoriteNameKey] id:[fav objectForKey:SPFavoriteIDKey]] retain]; @@ -2384,8 +2395,6 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, for (NSUInteger i = 0; i < [toolbarItems count]; i++) [[toolbarItems objectAtIndex:i] setEnabled:YES]; #endif - if (connectionKeychainID) [dbDocument setKeychainID:connectionKeychainID]; - // Pass the connection to the table document, allowing it to set // up the other classes and the rest of the interface. [dbDocument setConnection:mySQLConnection]; @@ -3179,7 +3188,6 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, #endif // Keychain references - connectionKeychainID = nil; connectionKeychainItemName = nil; connectionKeychainItemAccount = nil; connectionSSHKeychainItemName = nil; @@ -3633,7 +3641,7 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2, SPClear(nibObjectsToRelease); - if (connectionKeychainID) SPClear(connectionKeychainID); + [self setConnectionKeychainID:nil]; if (connectionKeychainItemName) SPClear(connectionKeychainItemName); if (connectionKeychainItemAccount) SPClear(connectionKeychainItemAccount); if (connectionSSHKeychainItemName) SPClear(connectionSSHKeychainItemName); diff --git a/Source/SPDatabaseDocument.h b/Source/SPDatabaseDocument.h index 36269e73..c89f7847 100644 --- a/Source/SPDatabaseDocument.h +++ b/Source/SPDatabaseDocument.h @@ -262,8 +262,6 @@ NSMutableArray *runningActivitiesArray; #endif - NSString *keychainID; - #ifndef SP_CODA /* ivars */ NSThread *printThread; @@ -342,7 +340,6 @@ #endif - (void)setConnection:(SPMySQLConnection *)theConnection; - (SPMySQLConnection *)getConnection; -@property(readwrite, copy, nonatomic) NSString *keychainID; // Database methods - (IBAction)setDatabases:(id)sender; diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 39687de1..db404eb1 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -135,7 +135,6 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; @synthesize processID; @synthesize instanceId; @synthesize dbTablesTableView = dbTablesTableView; -@synthesize keychainID = keychainID; #pragma mark - @@ -4659,7 +4658,8 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; } [connection setObject:connectionType forKey:@"type"]; - if ([[self keychainID] length]) [connection setObject:[self keychainID] forKey:@"kcid"]; + NSString *kcid = [connectionController connectionKeychainID]; + if ([kcid length]) [connection setObject:kcid forKey:@"kcid"]; [connection setObject:[self name] forKey:@"name"]; [connection setObject:[self host] forKey:@"host"]; [connection setObject:[self user] forKey:@"user"]; @@ -4860,9 +4860,10 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; [connectionController setSslCACertFileLocation:[connection objectForKey:@"sslCACertFileLocation"]]; // Set the keychain details if available - if ([connection objectForKey:@"kcid"] && [(NSString *)[connection objectForKey:@"kcid"] length]) { - [self setKeychainID:[connection objectForKey:@"kcid"]]; - [connectionController setConnectionKeychainItemName:[keychain nameForFavoriteName:[connectionController name] id:[self keychainID]]]; + NSString *kcid = (NSString *)[connection objectForKey:@"kcid"]; + if ([kcid length]) { + [connectionController setConnectionKeychainID:kcid]; + [connectionController setConnectionKeychainItemName:[keychain nameForFavoriteName:[connectionController name] id:kcid]]; [connectionController setConnectionKeychainItemAccount:[keychain accountForUser:[connectionController user] host:[connectionController host] database:[connection objectForKey:@"database"]]]; } @@ -4894,8 +4895,8 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; if ([connection objectForKey:@"ssh_password"]) [connectionController setSshPassword:[connection objectForKey:@"ssh_password"]]; else { - if ([connection objectForKey:@"kcid"] && [(NSString *)[connection objectForKey:@"kcid"] length]) { - [connectionController setConnectionSSHKeychainItemName:[keychain nameForSSHForFavoriteName:[connectionController name] id:[self keychainID]]]; + if ([kcid length]) { + [connectionController setConnectionSSHKeychainItemName:[keychain nameForSSHForFavoriteName:[connectionController name] id:kcid]]; [connectionController setConnectionSSHKeychainItemAccount:[keychain accountForSSHUser:[connectionController sshUser] sshHost:[connectionController sshHost]]]; } NSString *sshpw = [self keychainPasswordForSSHConnection:nil]; @@ -7148,25 +7149,10 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; - (NSString *)keychainPasswordForSSHConnection:(SPMySQLConnection *)connection { // If no keychain item is available, return an empty password - if (![connectionController connectionKeychainItemName]) return @""; + NSString *password = [connectionController keychainPasswordForSSH]; + if (!password) return @""; - // Otherwise, pull the password from the keychain using the details from this connection - SPKeychain *keychain = [[SPKeychain alloc] init]; - - NSString *connectionSSHKeychainItemName = [[keychain nameForSSHForFavoriteName:[connectionController name] id:[self keychainID]] retain]; - NSString *connectionSSHKeychainItemAccount = [[keychain accountForSSHUser:[connectionController sshUser] sshHost:[connectionController sshHost]] retain]; - NSString *sshPassword = [keychain getPasswordForName:connectionSSHKeychainItemName account:connectionSSHKeychainItemAccount]; - - if (!sshPassword || ![sshPassword length]) { - sshPassword = @""; - } - - if (connectionSSHKeychainItemName) [connectionSSHKeychainItemName release]; - if (connectionSSHKeychainItemAccount) [connectionSSHKeychainItemAccount release]; - - [keychain release]; - - return sshPassword; + return password; } /** @@ -7729,7 +7715,6 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; if (spfPreferences) SPClear(spfPreferences); if (spfSession) SPClear(spfSession); if (spfDocData) SPClear(spfDocData); - [self setKeychainID:nil]; if (mainToolbar) SPClear(mainToolbar); if (titleAccessoryView) SPClear(titleAccessoryView); if (taskProgressWindow) SPClear(taskProgressWindow); |