From 2735e15bf5d4b3a976435ebb29ca9073de0e5071 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 4 Jan 2015 03:57:26 +0100 Subject: Formalize [x release], x = nil; convention Take this commit as a proposal to formalize our existing "[x release], x = nil;" convention by introducing a macro for it. Feel free to revert this commit if you see issues with the approch or implementation. --- Source/SPConnectionHandler.m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Source/SPConnectionHandler.m') diff --git a/Source/SPConnectionHandler.m b/Source/SPConnectionHandler.m index 12b868f5..bac0c680 100644 --- a/Source/SPConnectionHandler.m +++ b/Source/SPConnectionHandler.m @@ -208,9 +208,9 @@ static NSString *SPLocalhostAddress = @"127.0.0.1"; // Tidy up isConnecting = NO; - if (sshTunnel) [sshTunnel disconnect], [sshTunnel release], sshTunnel = nil; + if (sshTunnel) [sshTunnel disconnect], SPClear(sshTunnel); - [mySQLConnection release], mySQLConnection = nil; + SPClear(mySQLConnection); #ifndef SP_CODA if (!cancellingConnection) [self _restoreConnectionInterface]; #endif @@ -229,9 +229,9 @@ static NSString *SPLocalhostAddress = @"127.0.0.1"; // Tidy up isConnecting = NO; - if (sshTunnel) [sshTunnel release], sshTunnel = nil; + if (sshTunnel) SPClear(sshTunnel); - [mySQLConnection release], mySQLConnection = nil; + SPClear(mySQLConnection); [self _restoreConnectionInterface]; if (isTestingConnection) { [self _showConnectionTestResult:NSLocalizedString(@"Invalid database", @"Invalid database very short status message")]; @@ -352,7 +352,7 @@ static NSString *SPLocalhostAddress = @"127.0.0.1"; #endif // Release the tunnel if set - will now be retained by the connection - if (sshTunnel) [sshTunnel release], sshTunnel = nil; + if (sshTunnel) SPClear(sshTunnel); // Pass the connection to the document and clean up the interface [self addConnectionToDocument]; @@ -436,7 +436,7 @@ static NSString *SPLocalhostAddress = @"127.0.0.1"; // Release as appropriate if (sshTunnel) { - [sshTunnel disconnect], [sshTunnel release], sshTunnel = nil; + [sshTunnel disconnect], SPClear(sshTunnel); // If the SSH tunnel connection failed because the port it was trying to bind to was already in use take note // of it so we can give the user the option of connecting via standard connection and use the existing tunnel. -- cgit v1.2.3 From 1b6248d6a256ad774d092151227fdd5f40247c02 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 21 Mar 2015 02:25:59 +0100 Subject: Add code for using custom SSL cipher list in SP --- Source/SPConnectionHandler.m | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'Source/SPConnectionHandler.m') diff --git a/Source/SPConnectionHandler.m b/Source/SPConnectionHandler.m index bac0c680..80e9c3f5 100644 --- a/Source/SPConnectionHandler.m +++ b/Source/SPConnectionHandler.m @@ -145,6 +145,16 @@ static NSString *SPLocalhostAddress = @"127.0.0.1"; if ([self sslCACertFileLocationEnabled]) { [mySQLConnection setSslCACertificatePath:[self sslCACertFileLocation]]; } + + NSString *userSSLCipherList = [prefs stringForKey:SPSSLCipherListKey]; + if(userSSLCipherList) { + //strip out disabled ciphers (e.g. in "foo:bar:--:baz") + NSRange markerPos = [userSSLCipherList rangeOfRegex:@":?--"]; + if(markerPos.location != NSNotFound) { + userSSLCipherList = [userSSLCipherList substringToIndex:markerPos.location]; + } + [mySQLConnection setSslCipherList:userSSLCipherList]; + } } // Connection delegate must be set before actual connection attempt is made -- cgit v1.2.3 From 80a2088f43bd3a901fb20d714318d4b5d3dc60a9 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 1 May 2015 02:08:48 +0200 Subject: Significantly reduce risk of a race condition in a certain setup (see #2107) * Replaced a run loop sleep with a thread sleep as it was on a background thread where a) a regular sleep is fine, b) the run loop sleep did not seem to have any effect * While we are at it, cut done some duplicate code * Removed a redundant if() --- Source/SPConnectionHandler.m | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'Source/SPConnectionHandler.m') diff --git a/Source/SPConnectionHandler.m b/Source/SPConnectionHandler.m index 80e9c3f5..c216142f 100644 --- a/Source/SPConnectionHandler.m +++ b/Source/SPConnectionHandler.m @@ -174,8 +174,12 @@ static NSString *SPLocalhostAddress = @"127.0.0.1"; if (![mySQLConnection isConnected]) { if (sshTunnel && !cancellingConnection) { - // If an SSH tunnel is running, temporarily block to allow the tunnel to register changes in state - [[NSRunLoop currentRunLoop] runMode:NSModalPanelRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.2]]; + // This is a race condition we cannot fix "properly": + // For meaningful error handling we need to also consider the debug output from the SSH connection. + // The SSH debug output might be sligthly delayed though (flush, delegates, ...) or + // there might not even by any output at all (when it is purely a libmysql issue). + // TL;DR: No guaranteed events we could wait for, just trying our luck. + [NSThread sleepForTimeInterval:0.1]; // 100ms // If the state is connection refused, attempt the MySQL connection again with the host using the hostfield value. if ([sshTunnel state] == SPMySQLProxyForwardingFailed) { @@ -184,7 +188,7 @@ static NSString *SPLocalhostAddress = @"127.0.0.1"; [mySQLConnection connect]; if (![mySQLConnection isConnected]) { - [[NSRunLoop currentRunLoop] runMode:NSModalPanelRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.2]]; + [NSThread sleepForTimeInterval:0.1]; //100ms } } } -- cgit v1.2.3