最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

MyDAC in Delphi cannot connect to MariaDB Server SSL handshake failed - Stack Overflow

programmeradmin1浏览0评论

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:

  1. Checked if the certs on the server are valid
  2. 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"
  3. Changed "FConnection.SSLOptions.CipherList := 'All';" to 'ECDHE-RSA-AES256-GCM-SHA384'
  4. Checked if the credentials are handed over to the FConnection.
  5. Set up an SQL User with ALL Priviliges.
  6. Used Google and ChatGPT to research the error codes but both weren't helpful
  7. Checked if SSLConnect is set to true (which it is).
  8. 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!

发布评论

评论列表(0)

  1. 暂无评论