Recent

Author Topic: non TLS connection to mySQL using fpc mysql55 wrapper  (Read 1300 times)

Triplex

  • Newbie
  • Posts: 4
non TLS connection to mySQL using fpc mysql55 wrapper
« on: August 27, 2025, 10:58:23 pm »
Hello guys

Lazarus 4.2 on openSUSE Linux 15.6
I created a sandbox database and am trying to connect using the Free Pascal mysql55.pp wrapper, which utilizes libmysqlclient.so (Linux) or libmysql.dll (Windows).

Code: Pascal  [Select][+][-]
  1. uses mysql55;
  2. var MySQL : PMYSQL;
  3. ......
  4. MySQL := mysql_init(MySQL);
  5. //  MySQL^.options.use_ssl := 0;
  6.  
  7. if mysql_real_connect(MySQL, 'sql7.freesqldatabase.com', 'sql7796276', 'g3SKXnkJ5R', 'sql7796276', 0, Nil, 0) = nil then
  8.   ShowMessage(IntToStr(mysql_errno(MySQL)) + ' ' + mysql_error(MySQL));
  9. ....
  10.  
Resutl is an error: 2026 TLS/SSL error: SSL is required, but the server does not support it

How to disable SSL/TLS ?
Tried setting MySQL^.Options.Use_SSL := 0;, but no luck.

Linux CLi mysql connected succesfully to database and STATUS show that TLS not in use
Code: [Select]
mysql -h sql7.freesqldatabase.com -u sql7796276 -p'g3SKXnkJ5R' sql7796276

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 99369004
Server version: 5.5.62-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [sql7796276]> status
--------------
mysql  Ver 15.1 Distrib 10.11.11-MariaDB, for Linux (x86_64) using  EditLine wrapper

Connection id:          99369004
Current database:       sql7796276
Current user:           sql7796276@mm-222-14-212-37.vitebsk.dynamic.pppoe.byfly.by
SSL:                    Not in use
Current pager:          less
Using outfile:          ''
Using delimiter:        ;
Server:                 MySQL
Server version:         5.5.62-0ubuntu0.14.04.1 (Ubuntu)
Protocol version:       10
Connection:             sql7.freesqldatabase.com via TCP/IP
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    utf8
Conn.  characterset:    utf8
TCP port:               3306
Uptime:                 6 days 9 hours 58 min 35 sec

Threads: 69  Questions: 9393157  Slow queries: 159  Opens: 274221  Flush tables: 1  Open tables: 400  Queries per second avg: 16.945
--------------

P.S. Checked on Windows with libmysql.dll in project folder and its connected succesfully...
« Last Edit: August 28, 2025, 12:23:54 am by Triplex »

Zvoni

  • Hero Member
  • *****
  • Posts: 3361
Re: non TLS connection to mySQL using fpc mysql55 wrapper
« Reply #1 on: August 28, 2025, 08:59:07 am »
1) connect with the commandline-client, and enter SHOW VARIABLES and look for TLS
Maybe it's activated via the my.inf
2) You connect to Port 0 ???? Seriously?
Quote
from MySQL.com:
Code: C  [Select][+][-]
  1. MYSQL *
  2. mysql_real_connect(MYSQL *mysql,
  3.                    const char *host,
  4.                    const char *user,
  5.                    const char *passwd,
  6.                    const char *db,
  7.                    unsigned int port,
  8.                    const char *unix_socket,
  9.                    unsigned long client_flag)


if mysql_real_connect(MySQL, 'sql7.freesqldatabase.com', 'sql7796276', 'g3SKXnkJ5R', 'sql7796276', 0, Nil, 0) = nil then
EDIT2: Forget what i wrote. Just realized you connect to an online Database, exposed by a webserver

EDIT: Found something:
https://dev.mysql.com/doc/c-api/8.4/en/mysql-real-connect.html
about half way down
Quote
CLIENT_SSL: Use SSL (encrypted protocol). Do not set this option within an application program; it is set internally in the client library. Instead, use mysql_options() before calling mysql_real_connect().

Maybe read out the options first:
https://dev.mysql.com/doc/c-api/8.4/en/mysql-get-option.html
« Last Edit: August 28, 2025, 09:15:58 am by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Triplex

  • Newbie
  • Posts: 4
Re: non TLS connection to mySQL using fpc mysql55 wrapper
« Reply #2 on: August 28, 2025, 02:41:36 pm »
Maybe read out the options first:
https://dev.mysql.com/doc/c-api/8.4/en/mysql-get-option.html
Thx for the link, here is a bit mess in fpc sources and mysql docs

1. less than mysql57dyn function mysql_options is not implemented. ok i moved to v5.7

2. mysql57dyn has outdated MYSQL_OPT_SSL_ENFORCE option. According to the docs - option is deprecated as of MySQL 5.7.11 and is removed in MySQL 8.0. But i tried
Code: Pascal  [Select][+][-]
  1. uses mysql57dyn;
  2. var
  3.   SSLFlag : Integer; //also tried my_bool
  4.   MySQL : PMYSQL;
  5. ...............
  6. begin
  7.   InitialiseMySQL; //load client library if dyn
  8.   SSLFlag := 0;
  9.   mysql_options(MySQL, MYSQL_OPT_SSL_ENFORCE, @SSLFlag);
  10.  
  11.   if mysql_real_connect(MySQL, 'sql7.freesqldatabase.com', 'sql7796276', 'g3SKXnkJ5R', 'sql7796276', 0, Nil, 0) = nil then
  12.     begin
  13.       Str := IntToStr(mysql_errno(MySQL)) + ' ' + mysql_error(MySQL);
  14.       moLog.Lines.Add(Str);
  15.     end;
  16.  
  17.   ReleaseMySQL;
  18. end.
  19.  
Still same result.

3. mysql80dyn has modern MYSQL_OPT_SSL_MODE ortion, but has no set of modes, required as option values  SSL_MODE_DISABLED, SSL_MODE_PREFERRED, SSL_MODE_REQUIRED etc. so i cant use it

Any other ideas?
Is it possible because my libmysqlclient.so is a symlink to libmariadb.so.3 ? Mayme i need setup MariaDB somehow?
« Last Edit: August 28, 2025, 03:07:23 pm by Triplex »

Triplex

  • Newbie
  • Posts: 4
Re: non TLS connection to mySQL using fpc mysql55 wrapper
« Reply #3 on: August 28, 2025, 03:01:51 pm »
Upd: Fount modes in c++ connector sources
Code: [Select]
enum ssl_mode
{
  SSL_MODE_DISABLED= 1, SSL_MODE_PREFERRED, SSL_MODE_REQUIRED,
  SSL_MODE_VERIFY_CA, SSL_MODE_VERIFY_IDENTITY
};
Have a try, but still no luck
Code: Pascal  [Select][+][-]
  1. uses mysql80dyn;
  2. type
  3.   TSSLMode = (
  4.     SSL_MODE_DISABLED = 1,
  5.     SSL_MODE_PREFERRED,
  6.     SSL_MODE_REQUIRED,
  7.     SSL_MODE_VERIFY_CA,
  8.     SSL_MODE_VERIFY_IDENTITY  );      
  9. var
  10.   SSLFlag : Integer;
  11.   SSLMode : TSSLMode;
  12.   MySQL : PMYSQL;
  13. ...............
  14. begin
  15.   InitialiseMySQL; //load client library if dyn
  16.   SSLFlag := 1;
  17.   SSLMode := SSL_MODE_DISABLED;
  18.  
  19.   mysql_options(MySQL, MYSQL_OPT_SSL_MODE, @SSLMode); //also tried mysql_options(MySQL, MYSQL_OPT_SSL_MODE, @SSLFlag);
  20.  
  21.   if mysql_real_connect(MySQL, 'sql7.freesqldatabase.com', 'sql7796276', 'g3SKXnkJ5R', 'sql7796276', 0, Nil, 0) = nil then
  22.     begin
  23.       Str := IntToStr(mysql_errno(MySQL)) + ' ' + mysql_error(MySQL);
  24.       moLog.Lines.Add(Str);
  25.     end;
  26.  
  27.   ReleaseMySQL;
  28. end.
  29.  
« Last Edit: August 28, 2025, 03:03:48 pm by Triplex »

Zvoni

  • Hero Member
  • *****
  • Posts: 3361
Re: non TLS connection to mySQL using fpc mysql55 wrapper
« Reply #4 on: August 28, 2025, 03:42:08 pm »
I've just lookd into the source of mysql.inc
and found this
Code: Pascal  [Select][+][-]
  1. //Line 1795
  2. function mysql_options(mysql:PMYSQL; option:mysql_option; arg:Pchar):cint;extdecl;external mysqllib name 'mysql_options';
  3.  
  4. //Line 1875
  5. mysql_options: function (mysql:PMYSQL; option:mysql_option; arg:Pchar):cint;extdecl;
  6.  
A PChar as 3rd parameter???

Try a hard cast to Integer-Pointer or raw pointer for 3rd Param

EDIT: Looks like a bug to me
« Last Edit: August 28, 2025, 03:44:50 pm by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Triplex

  • Newbie
  • Posts: 4
Re: non TLS connection to mySQL using fpc mysql55 wrapper
« Reply #5 on: August 28, 2025, 04:52:52 pm »
Solved. Issue was MariaDB. idk if its a bug or feature.
Got the package mysql-libs-8.0.42-2.fc42.x86_64.rpm for Fedora that provide libmysqlclient.so.21 and copy it to usr/lib64 folder as libmysqlclient.so

Txh alot

 

TinyPortal © 2005-2018