Permalink
Browse files

Remove the keychain id stuff from SPDatabaseDocument. It was only pro…

…xying SPConnectionController anyway
  • Loading branch information...
dmoagx committed Feb 23, 2018
1 parent 770c189 commit ca864a1f887feaf7ac6d35eeb55b265f3e630a09
Showing with 27 additions and 35 deletions.
  1. +2 −0 Source/SPConnectionController.h
  2. +14 −6 Source/SPConnectionController.m
  3. +0 −3 Source/SPDatabaseDocument.h
  4. +11 −26 Source/SPDatabaseDocument.m
@@ -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;
@@ -168,6 +168,7 @@ @implementation SPConnectionController
@synthesize dbDocument;
#endif
@synthesize connectionKeychainID = connectionKeychainID;
@synthesize connectionKeychainItemName;
@synthesize connectionKeychainItemAccount;
@synthesize connectionSSHKeychainItemName;
@@ -188,6 +189,16 @@ - (NSString *)keychainPassword
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 @@ - (void)updateFavoriteSelection:(id)sender
#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 @@ - (void)updateFavoriteSelection:(id)sender
}
// 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 @@ - (void)addConnectionToDocument
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 @@ - (id)initWithDocument:(SPDatabaseDocument *)document
#endif
// Keychain references
connectionKeychainID = nil;
connectionKeychainItemName = nil;
connectionKeychainItemAccount = nil;
connectionSSHKeychainItemName = nil;
@@ -3633,7 +3641,7 @@ - (void)dealloc
SPClear(nibObjectsToRelease);
if (connectionKeychainID) SPClear(connectionKeychainID);
[self setConnectionKeychainID:nil];
if (connectionKeychainItemName) SPClear(connectionKeychainItemName);
if (connectionKeychainItemAccount) SPClear(connectionKeychainItemAccount);
if (connectionSSHKeychainItemName) SPClear(connectionSSHKeychainItemName);
@@ -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;
@@ -135,7 +135,6 @@ @implementation SPDatabaseDocument
@synthesize processID;
@synthesize instanceId;
@synthesize dbTablesTableView = dbTablesTableView;
@synthesize keychainID = keychainID;
#pragma mark -
@@ -4659,7 +4658,8 @@ - (NSDictionary *) stateIncludingDetails:(NSDictionary *)detailsToReturn
}
[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 @@ - (BOOL)setState:(NSDictionary *)stateDetails fromFile:(BOOL)spfBased
[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 @@ - (BOOL)setState:(NSDictionary *)stateDetails fromFile:(BOOL)spfBased
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 @@ - (NSString *)keychainPasswordForConnection:(SPMySQLConnection *)connection auth
- (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 @@ - (void)dealloc
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);

0 comments on commit ca864a1

Please sign in to comment.