I have an issue connecting my Delphi application to my MariaDB server via SSL. For that i'm using MyDAC with the SSL settings. Here my code:
// Method to establish a connection to the database with SSL support
procedure TSQLHelper.Connect(const Host, Database, User, Password: string; const SSLConnect: Boolean);
begin
// Set connection parameters
FHost := Host; // Hostname or IP address of the database server
FDatabase := Database; // Name of the database to connect to
FUsername := User; // Database username
FPassword := Password; // Database password
FSSLConnect := SSLConnect;
try
// Uses an SSL Connection if set to true
if SSLConnect then
begin
// Set the protocol to SSL for secure connection
FConnection.Options.Protocol := TMyProtocol.mpSSL;
FConnection.SSLOptions.CipherList := 'All'; // Enable all cipher suites
end;
// Assign connection parameters to the MyDAC connection object
FConnection.Server := FHost;
FConnection.Database := FDatabase;
FConnection.Username := FUsername;
FConnection.Password := FPassword;
FConnection.Options.UseUnicode := True; // Ensure Unicode support is enabled
// Attempt to connect to the database
FConnection.Connected := True;
except
on E: Exception do
begin
// Handle connection errors
FLastErrNo := 1001; // General error code for connection issues
FLastError := 'Error connecting to Server ' + FHost + ' with User ' + FUsername + ': ' + E.Message; // Detailed error message
end;
end;
end;
I enforced the SSL connection with "REQUIRED" in my MariaDB server so the SSL connection is established via the server. I get the following error trying to connect: "Could not connect to the database: Error connecting to Server 192.168.184.130 with User testuser: SSL_do_handshake = -1 SSL_get_error(..., r2) = 1 r2 = -1"
What i did test:
- Checked if the certs on the server are valid
- Connected to the server via NaviCat and HeidiSQL (Enabeling SSL but not providing any certificates). Both worked and are showing "Ssl_cipher ECDHE-RSA-AES256-GCM-SHA384"
- Changed "FConnection.SSLOptions.CipherList := 'All';" to 'ECDHE-RSA-AES256-GCM-SHA384'
- Checked if the credentials are handed over to the FConnection.
- Set up an SQL User with ALL Priviliges.
- Used Google and ChatGPT to research the error codes but both weren't helpful
- Checked if SSLConnect is set to true (which it is).
- I have switched the libeay32.dll and ssleay32.dll to the ones in the NaviCat installation folder.
I have run out of ideas. Any tips are appreciated!