1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-09-11 08:30:59 +03:00

1089 Commits

Author SHA1 Message Date
Vladislav Vaintroub
72116a30ab Merge branch '3.1' into 3.3 2024-07-29 11:53:15 +02:00
Vladislav Vaintroub
6a67a34f47 CONC-527 "SEC_E_ALGORITHM_MISMATCH" connecting Windows client to Ubuntu
The bug happens only when connecting with SSL with client certificates.

Apparently if client certificates are used in TLS handshake,
private keys for cert should be loaded into named persistent
container.This is because AcquireCredentialsHandle is done partically
out-of-process in lsass.exe, and lsass wants to read private keys from disk

See discussion in https://github.com/dotnet/runtime/issues/23749

Schannel has legacy behavior for ephemeral keys, not involving lsass,
and this is why it worked for us so far, however there are limitations.

It appears to only use rsa_sha1 for signature verification, and newer
OpenSSL no longer allows SHA1 for it, and this ends up in
"algorithm mismatch" message from schannel.

The above is just my understanding of how it works, because there is no
real documentation, the conclusion is based on discussion in
https://github.com/dotnet/runtime/issues/23749

The fix:
So storing the key in persistent named container evidently fixes it,
and this is what is done in this patch. Care is takes to destroy
key container after key is no longer needed, to
avoid filling  %AppData%\Roaming\Microsoft\Crypto\RSA with tiny encrypted
key files. Thus the "persistency window" of the key in container on disk
is only for duration of AcquireCredentialsHandle
2024-07-28 03:46:50 +02:00
Georg Richter
c5d2a0ebb3 TLS (schannel) fixes:
- don't verify fingerprint twice
- pci->dwVersion (certificate version) needs to be increased by 1
- use MARIADB_TLS_VERIFY_UNKNOWN for unknown tls verification errors
2024-07-18 05:44:50 +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
Azat Khuzhin
b8a93c4519 Fix usage of wait_io_or_timeout from TLS layers
wait_io_or_timeout() accepts milliseconds, while options has seconds,
since this is just plain MYSQL_OPT_READ_TIMEOUT/...

The one that has milliseconds are pvio->timeout[PVIO_*_TIMEOUT], so use
them.

Usually this is not a problem, but, in case of interrupt (i.e. signal -
EINTR) SSL_read() will return SSL_ERROR_WANT_READ/SSL_ERROR_WANT_WRITE,
and then wait_io_or_timeout() will be called, and timeout will be wrong,
may cause a failure.
2024-07-01 15:36:52 +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
7498d30a07 CONC-698: certificate info is read on every connect
Read and store peer certificate information only if
mariadb_get_options was called.
2024-06-21 16:14:36 +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
Sergei Golubchik
cc985fab30 fix the memory leak with gnutls (~11K per connection) 2024-05-26 15:45:54 +02:00
Sergei Golubchik
875ef5ad64 fix the memory leak with openssl (~8K per connection) 2024-05-26 15:45:33 +02:00
Sergei Golubchik
d9a50aceac ASN1_TIME_to_tm was added in OpenSSL 1.1.1 2024-05-16 13:53:14 +02:00
Sergei Golubchik
deb38a3e1c fix the code for OpenSSL 1.0 2024-05-16 11:47:00 +02:00
Sergei Golubchik
e52197420e TLS fingerprint is returned in hex! 2024-05-15 16:39:18 +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
Sergei Golubchik
def5dee9d5 Merge remote-tracking branch 'origin/3.3' into 3.4-serg 2024-05-13 16:00:45 +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
fc33778492 Added new utf8 general1400_as_ci collations
The following collations from 11.5 were added:

579: utf8mb3_general1400_as_ci
611: utf8mb4_general1400_as_ci
2024-05-10 11:06:37 +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
4d46ae76bc Merge branch '3.1' into 3.3 2024-05-08 11:43:18 +02:00
Georg Richter
3228ed2ea3 Fix copy/paste error 2024-05-07 15:13:15 +02:00
Georg Richter
dc1606781f Fix build for OpenSSL < 1.1 2024-05-07 11:40:29 +02:00
Georg Richter
989bd88546 Fix compile error (misleading-indentation) 2024-05-07 07:23:32 +02:00
Georg Richter
ba137a4f5c Exclude server side cursors when checking for pending results 2024-05-06 14:32:31 +02:00
Georg Richter
3f47c15241 Added missing support for restricted_auth in conf files 2024-05-06 14:31:49 +02:00
Georg Richter
f7eab7d2e3 Merge branch '3.1' into 3.4 2024-04-29 14:18:54 +02:00
Josh Hunt
4c1c7f37d6 Fix SSL_read/write return value checking in ma_tls_async_check_result
SSL_{read,write}'s return values == 0 signify the operation was
unsuccessful, but here it's being treated as success. Other calls of
these functions already properly checks the return value.

Signed-off-by: Josh Hunt <johunt@akamai.com>
2024-04-29 13:47:36 +02:00
Georg Richter
45179cffc4 Merge remote-tracking branch 'origin/3.1' into 3.4 2024-04-29 11:15:02 +02:00
Georg Richter
20fbb3c3b9 Avoid possible crash if connection was closed
Before checking pending result sets in prepared statements,
we need to check if the connection was already closed or
resetted by checking stmt->mysql. In case of NULL we return
false, since there are no more pending result sets.
2024-04-29 10:57:12 +02:00
Georg Richter
7d0edc3dfa Merge branch '3.4-work' into 3.4 2024-04-29 10:24:12 +02:00
Georg Richter
ffd0a0e4be Fix identation error. 2024-04-27 20:52:13 +02:00
Georg Richter
19dffea4dc CONC-692: Provide X509 peer certificate information
Added a new structure MARIADB_X509_INFO, which
contains information about servers certificate.
The information can be obtained via mysql_get_infov API
function:

MARIADB_X509_INFO *info;
mariadb_get_infov(mysql, MARIADB_TLS_PEER_CERT_INFO, &info);
2024-04-24 11:21:28 +02:00
Georg Richter
f4e8c085fc Fix compiler warnings 2024-04-24 11:05:26 +02:00
Georg Richter
fef3e4ed6d CONC-683: Check pending results when closing statement.
Similiar to fix for CONC-667 we need to check if other
statements have a pending result set before we can close
a statement handle.
2024-03-23 12:53:24 +01:00
Georg Richter
b64282a9dd CONC-667: Fix statement handling when unbuffered results are pending.
Resetting a statement will result in an error, if another (different)
statement has a pending unbuffered result set (CR_COMMANDS_OUT_OF_SYNC).

Freeing a statement result set will return an error, if the statement
has no result set or was not executed (CR_STMT_NO_RESULT).
2024-03-23 12:27:55 +01:00
Georg Richter
4a1c5ef53b CONC-688: mariadb_rpl_fetch() crashes if table is partitioned
Follow up fix of CONC-657 where we didn't set offset of event
content correctly. Thanks to Sruli Ganor!
2024-03-22 15:35:21 +01:00
Georg Richter
2fc64d791c CONC-689: Fix parsing of HEARTBEAT_LOG_EVENT:
The heartbeat log event now contains the filename,
instead of wrong header information (which was
already processed when reading event header).
2024-03-18 08:09:02 +01:00
Georg Richter
20737ac3ad Merge commit '86e2e87fa22ace6e46353c13a09fa4b8878b7992' into 3.4 2024-03-16 06:47:57 +01:00
Georg Richter
86e2e87fa2 Follow up of fix for CONC-680:
mysql_old_password is disabled by default (setting DISABLED YES),
but can be used if the plugin was added to the list of restricted
authentication plugins (via mysql_optionsv using option
MARIADB_OPT_RESTRICTED_AUTH).
2024-03-10 14:04:27 +01:00
rusher
abce07da2a [MDEV-30366] Bulk unitary result flag client implementation part.
With MDEV-30366, server now permit to send a result-set containing generated id and Affected rows for each bulk operation. This feature can be enabled with option MARIADB_OPT_BULK_UNIT_RESULTS when server supports it.
2024-03-06 16:03:55 +01:00
Georg Richter
8228164f85 Merge branch '3.1' into 3.3 2024-02-24 17:09:58 +01:00
Georg Richter
558ad7d68d CONC-677:
Fix possible memory leak: If get_default_configuration_dirs() function
fails, we need to release previously allocated memory for
configuration_dirs.
2024-02-24 17:06:03 +01:00
Georg Richter
ebe1949540 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-02-22 09:03:51 +01:00
Georg Richter
fe411bf336 CONC-403:
Remove support of TLSv1.0 protocol
2024-02-20 09:52:07 +01:00
Sergei Golubchik
f6e99af056 Revert "self-signed certificate verification", it's 3.4 feature
This reverts 395641549ac7..536d9e2b9e5b, in particular:

8dffd56936 MDEV-31857 enable MYSQL_OPT_SSL_VERIFY_SERVER_CERT by default
a99570c118 MDEV-31855 SSL cert validation protocol extension
9aa15e72a7 TLS fingerprint

and related commits
2024-02-19 11:16:26 +01:00
Sergei Golubchik
82983a30f4 make DEFAULT_SSL_VERIFY_SERVER_CERT a cmake option 2024-02-14 15:01:29 +01:00