1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-07 02:42:49 +03:00
Commit Graph

282 Commits

Author SHA1 Message Date
Vladislav Vaintroub
fa56a25fae Remove workaround after MDEV-13492 was fixed.
SSL connection on Windows used retry logic initially, to "fix" MDEV-13492
This actual bug is now understood, and was fixed a while ago.
Remove the workaround now.
2025-04-17 19:53:21 +02:00
Georg Richter
13c693f28b Merge branch '3.3' into 3.4 2025-02-27 07:56:47 +01:00
Georg Richter
4c9bc2b0f6 Merge branch '3.1' into 3.3 2025-02-27 07:52:35 +01:00
Georg Richter
aa240cd181 CONC-760: valid named pipe connection is closed
Fixed different behavior of pvio_is_alive (which was first used
with fix of CONC-589). Both for sockets and named pipe the function
now returns true if the connection is alive, otherwise false.
2025-02-27 07:48:58 +01:00
Georg Richter
3780dc432c Merge branch '3.3' into 3.4 2025-02-11 11:45:53 +01:00
Georg Richter
4877093937 Workaround for MDEV-35935
If the server returns an error packet without error number
(and message) we set errno=CR_ERR_MISSING_ERROR_INFO (5026)
2025-02-11 11:28:56 +01:00
Kristian Nielsen
2381127b11 CONC-473: mysql_real_connect_start() stack overrun with mdns hostname
Increase the default stack size for co-routines to 256 kByte. It was 60
kByte, which was too small for glibc getaddrinfo() when using mdns.

Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
2025-02-06 00:24:28 +01:00
Sergei Golubchik
a99205eb36 Merge branch '3.3' into 3.4 2025-01-25 18:06:27 +01:00
Sergei Golubchik
2d56f340c4 Merge branch '3.1' into 3.3 2025-01-24 14:52:35 +01:00
Sergei Golubchik
836db56372 memory leaks after CONC-589, e09e24e8
we cannot just set `mysql->net.pvio= NULL`
we need to free(net->pvio) first.
And not protect `free(net->buff)` with `if (mysql->net.pvio)`.
2025-01-24 14:42:37 +01:00
Georg Richter
ba64123b45 Merge branch '3.3' into 3.4 2025-01-20 09:58:34 +01:00
Georg Richter
57ce0ce3c7 Merge branch '3.1' into 3.3 2025-01-15 08:00:19 +01:00
Georg Richter
e09e24e890 CONC-589: First query fails after reconnect
If automatic reconnect is enabled (MYSQL_OPT_RECONNECT) it is
mandatory to check if the connection/socket is still alive before
sending a command to the server (unless the command is COM_QUIT).
2025-01-15 07:26:18 +01:00
Georg Richter
12a7054194 Partial revert of 1a2ed3f67a
Since Item_result enumerations are also used by MariaDB server, we
moved them back to mariadb_com.h.
Item_result is not used in Connector/C 3.3 and above for replication
api.
2024-12-22 11:00:12 +01:00
Georg Richter
4039e5c18c Merge branch '3.3' into 3.4 2024-12-21 08:10:04 +01:00
Georg Richter
19495f1cdd Fix logical error in parse_connection_string
removed dead code (in_curly_brace is always true)
2024-12-19 11:14:19 +01:00
Georg Richter
3794a86544 CONC-691: Obtain sql statement from statement handle
Added an option STMT_ATTR_SQL_STATEMENT in API function
mariadb_stmt_attr_get which returns a MARIADB_CONST_STRING
structure which contains SQL statement from last
mysql_stmt_prepare() call.
2024-12-12 12:07:34 +01:00
Georg Richter
6ca0574b7b Merge branch '3.3' into 3.4 2024-12-12 10:44:34 +01:00
Georg Richter
d90e911ef6 Merge branch '3.1' into 3.3 2024-12-12 10:43:07 +01:00
Georg Richter
6bf9557d00 CONC-709: Fix crash when sending NULL_LENGTH in field description
Instead of checking the lengths given by two offsets, we have to
check if NULL_LENGTH was sent before (and return an error).
2024-12-12 10:40:30 +01:00
Georg Richter
294b933606 CONC-708: buffer over-/underflow in ma_read_ok_packet
Added a helper function ma_check_buffer_bounaaries which
checks possible boffer over- or underflows when processing
ok packet.^
2024-12-10 08:01:37 +01:00
Georg Richter
29c0f5d317 Merge branch '3.3' into 3.4 2024-12-10 05:50:11 +01:00
Georg Richter
16e5b88bab MYSQL_OPT_ZSTD_COMPRESSION_LEVEL fixes:
Follow up for commit e633858c9e:
- Fixed ASAN bug (int to char conversion)
- Allow to retrieve zstd compression level via mysql_get_optionv()
2024-12-10 05:18:08 +01:00
Georg Richter
e633858c9e Merge pull request #261 from markus456/3.3-zstd-compression-level
Add configurable zstd compression level
2024-12-09 22:22:08 +01:00
Georg Richter
813a13e860 Merge branch '3.3' into 3.4 2024-12-09 19:32:30 +01:00
Georg Richter
136d295d02 Merge branch '3.1' into 3.3 2024-12-09 19:32:13 +01:00
Georg Richter
554893c269 CONC-711: Ubsan and ASAN fixes
- fixed write functions in my_auth.c
- fixed misalignment error when obtaining data via
  option MARIADB_OPT_USERDATA (mysql_get_optionv).
2024-12-09 19:28:10 +01:00
Georg Richter
9541bd0e90 CONC-747: Change behaviour of MARIADB_TLS_DISABLE_PEER_VERIFICATION
Instead of skipping the verification during handshake,
tls_allow_invalid_server_certificate will be unset during
initialization of the connection handle if environment varible
MARIADB_TLS_DISABLE_PEER_VERIFICATION was set.

This will allow drivers and applications which don't have an API
option to enable/disable peer server certificate verification
to start without TLS/SSL.
2024-12-02 17:05:58 +01:00
Georg Richter
3590fe6e8b Merge branch '3.3' into 3.4 2024-11-27 16:17:12 +01:00
Georg Richter
bdc66d6b8f Fix for CONC-703:
If connect failed and no error was set (apparently this happens
sometimes on Mac) we now set error to CR_SERVER_LOST.
2024-11-27 07:48:27 +01:00
Markus Mäkelä
a2213b89d4 Add MYSQL_OPT_ZSTD_COMPRESSION_LEVEL
The compression level was always hard-coded to 3.
2024-11-07 06:51:57 +02:00
Georg Richter
000ed6281f Fix for CONC-740:
Moved the initialization of server verification callback from
mysql_init to mysql_real_connect to avoid memory leak in case
of a reconnect.
2024-11-05 12:51:51 +01:00
Georg Richter
53243b8a7a Follow up of d4a8ca9209
Last commit was incomplete
2024-10-23 13:08:42 +02:00
Georg Richter
a66f3fc302 Merge branch '3.3' into 3.4 2024-10-22 13:50:24 +02:00
Georg Richter
6635e4bdd6 Fix for CONC-735
If a reconnect occurs, we need to check if mysql->options.host was
already set and pass NULL instead of the previous host name.
2024-10-22 13:26:50 +02:00
Georg Richter
e7b6adfbf9 Simplify tls_verification_callback 2024-09-10 07:19:12 +02:00
Georg Richter
b481c0a494 CONC-724: Added TLS verification callback support
For testing purposes (the python3 dummy server can't handle
further communication after TLS handshake succeeded) support
for verification callback was added.

my_bool callback(MYSQL *mysql, unsigned int *flags, my_bool verified)

Parameter:
  - mysql     connection handle for current connection
  - flags     verification flags
  - verified  true if callback was called after verification,
              otherwise false

Return value:
  - False (0) to continue
  - True  (1) to abort tls connection

The callback function can be registered via
mysql_optionsv(mysql, MARIADB_OPT_TLS_VERIFICATION_CALLBACK, callback);
2024-09-09 10:36:45 +02:00
Georg Richter
57f38cf87f Save the result of peer certificate verification
Since the MARIADB_TLS_VERIFY_TRUST flag might be cleared in my_auth,
we store the original result of peer certificate verification in
mysql->extension->tls_validation.
This value can be obtained via mariadb_get_infov API function
using option MARIADB_TLS_VERIFY_STATUS.
2024-08-31 07:53:46 +02:00
Georg Richter
1287c901dc TLS/SSL changes (major rework)
Peer certificate validation:

Since version 3.4 peer certificate verification is enabled by default.
It can be disabled via `mysql_optionsv`, using option
MYSQL_OPT_SSL_VERIFY_SERVER_CERT:

    my_bool verify= 0;
    mysql_options(mariadb, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &verify);

Self signed certificates

If the client obtained a self signed peer certificate from MariaDB server
the verification will fail, with the following exceptions:

* If the connection between client and server is considered to be secure:, e.g.
  * a unix_socket is used for client server communication
  * hostname is localhost (Windows operating system), 127.0.0.1 or ::1
* a specified fingerprint matches the fingerprint of the peer certificate (see below)
* a client can verify the certificate using account password, it's possible if
  * account has a password
  * authentication plugin is "secure without TLS", that is, one of
    mysql_native_password, ed25519 or parsec.

Fingerprint verification of the peer certificate

A fingerprint is a cryptographic hash (SHA-256, SHA-384 or SHA-512) of the peer
certificate's binary data. Even if the fingerprint matches, an expired or
revoked certificate will not be accepted.

For security reasons support for MD5 and SHA1 has been removed.

Technical details:
==================

- Peer certificate verification call was removed from ma_tls_connect, instead it
  will be called directly after the handshake succeeded (my_auth.c)

- mysql->net.tls_self_signed_error was replaced by mysql->net.tls_verify_status which
  contains the result of the peer certfificate verification:

  The verification status can be obtained with mariadb_get_infov using new parameter
  MARIADB_TLS_VERIFY_STATUS.

  unsigned int tls_verify_status;
  mariadb_get_infov(mysql, MARIADB_TLS_VERIFY_STATUS, &tls_verify_status);

  The result is a combination of the following flags:

  MARIADB_TLS_VERIFY_OK                  0
  MARIADB_TLS_VERIFY_TRUST               1
  MARIADB_TLS_VERIFY_HOST                2
  MARIADB_TLS_VERIFY_PERIOD              4
  MARIADB_TLS_VERIFY_FINGERPRINT         8
  MARIADB_TLS_VERIFY_REVOKED            16
  MARIADB_TLS_VERIFY_UNKNOWN            32

- GnuTLS peer certificate verification callback was removed and replaced by
  gnutls_verify_peers2() api function, so the peer certificate validation
  will happen after handshake.

- OpenSSL implementation will no longer use SSL_verify_result to check the
  validity of the peer certificate. Instead a callback function will be called
  during the handshake, which collects all certificate validation errors.

- If the peer certificate is not trusted, hostname verification will be
  skipped.

- Testing
  Added new test tls, which implements a python based dummy server, which allows
  to set different certificates and TLS options. Please note. that tests are
  expected to fail, since the server doesn't support further steps like user
  authentication etc. after the handshake. Prerequisite for running the tls test
  is Python3.
2024-07-16 13:12:26 +02:00
Georg Richter
5386f1a3f2 Merge remote-tracking branch 'origin/3.3' into 3.4-tls 2024-06-25 11:57:27 +02:00
Georg Richter
71fa44cff0 CONC-698: certificate info is read on every connect
Part 1: Fix for OpenSSL and Schannel
2024-06-20 08:34:19 +02:00
Georg Richter
486ce75d64 CONPY-704: parse_connection_string ignores empty string in last parameter
1) Fix check if end was reached (<= instead of <), so last parameter will
not be ignored in case it is an empty string.

2) Empty strings will be passed as NULL`in _mariadb_set_conf_option.
2024-06-11 16:00:22 +02:00
Georg Richter
4623d104e8 Merge branch '3.3' into 3.4 2024-05-14 09:54:50 +02:00
Georg Richter
e69af190c3 Merge branch '3.1' into 3.3 2024-05-14 09:48:52 +02:00
Georg Richter
6bd5b6746f Follow up fix for CONC-696
According to next_thread_id() in mysqld.cc the
thread id is limited to 4 bytes. Thanks to Vlad
for pointing out
2024-05-14 09:45:51 +02:00
Georg Richter
f578e359e5 Merge branch '3.1' into 3.3 2024-05-13 16:09:47 +02:00
Georg Richter
d5394838fd CONC-696: Replace COM_PROCESS_KILL by KILL command
Since COM_PROCESS_KILL isn't supported by newer MySQL
versions.
2024-05-13 15:57:39 +02:00
Georg Richter
55fe56fa42 Fix for CONC-505:
Don't allow to specify unsupported client flags (like
CLIENT_DEPRECATE_EOF) as client flag in mysql_real_connect
api function.
2024-05-08 14:22:13 +02:00
Georg Richter
923a0092e3 Added missing support for restricted_auth in conf files 2024-05-08 11:45:14 +02:00
Georg Richter
3f47c15241 Added missing support for restricted_auth in conf files 2024-05-06 14:31:49 +02:00