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

246 Commits

Author SHA1 Message Date
Vladislav Vaintroub
8804593283 CONC-767 Improve SSL verification performance on Windows
Fixes slow SSL handshakes in network-restricted environments. On Windows,
the verification process uses the CertGetCertificateChain API, which
may attempt to refresh the CA list or fetch CRLs/OCSP data from the
network. This can trigger slow network lookups when no CA or CRL is
explicitly specified.

This patch disables these unnecessary network calls by using flags
like CERT_CHAIN_CACHE_ONLY_URL_RETRIEVAL to prevent external requests
during certificate chain validation. Additionally, it applies
Microsoft-recommended optimizations to speed up certificate handling
and avoid delays in SSL handshakes.

Also, unless explicitly requested(via ca_cert or crl_file or similar),
do not bother to verify name, CA or CRL for local connections. It saves
time. The failures in verification were previously discarded anyway.
2025-04-17 19:55:17 +02:00
Georg Richter
29c0f5d317 Merge branch '3.3' into 3.4 2024-12-10 05:50:11 +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
fb0eea663a Merge branch '3.3' into 3.4 2024-12-08 12:01:20 +01:00
Marko Mäkelä
1093c22e35 Actually fix the build with clang < 16
Fixes up commit b77543a9d9
2024-12-04 09:11:44 +02:00
Marko Mäkelä
b77543a9d9 Fix the build with clang < 16
The #pragma in commit af4498b776
is only recognized starting with clang 16:
https://reviews.llvm.org/D134831
2024-12-03 15:31:15 +02:00
Marko Mäkelä
f64d977210 MSVC does not know _Static_assert
The C11 keyword _Static_assert that is deprecated in C23
is not recognized by MSVC. The C++11 and C23 keyword static_assert is,
at least starting with Visual Studio 16.0.

This fixes up efb0d9ac8b
2024-12-02 17:47:50 +02:00
Marko Mäkelä
af4498b776 Disable clang -Wcast-function-type-strict for 3rd party code 2024-12-02 15:40:46 +02:00
Georg Richter
7556d8ede3 CONC-743: Enable parsec by default
Parsec plugin will be built by default as a
dynamic plugin.
2024-11-27 17:26:21 +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
Markus Mäkelä
721103eba1 Fix zstd compression level bytes
The MySQL protocol documentation as well as the comments in code state
that the compression level is stored in one byte. The code, however,
used four bytes.
2024-11-07 06:49:41 +02:00
Oleksandr Byelkin
efb0d9ac8b Make it ccording C11 standard 2024-10-30 15:10:00 +01:00
Sergei Golubchik
4aebdb600b fix certificate verification for GnuTLS
* don't verify trust unless requested
* don't error about host of untrusted certificates
* auto-verification replaces both TRUST and HOST
2024-10-28 15:06:31 +01:00
Georg Richter
a66f3fc302 Merge branch '3.3' into 3.4 2024-10-22 13:50:24 +02:00
Sergei Golubchik
61ef765c43 change plugin TYPE in the REGISTER_PLUGIN to something useful
it's currently unused
2024-10-17 10:00:31 +02:00
Georg Richter
4e83946ecb ed25519: Remove server/client definition
Since server and client have their own ed25519 ref10 implementation
in source tree definitions for server were removed.
2024-09-25 19:54:02 +02:00
Georg Richter
ef59082021 Build fix:
Build ref10 library with position_independent_code property.
2024-09-25 17:18:04 +02:00
Georg Richter
d358547dd0 TLS test fix:
We always need to set verification flag in tls test, to avoid
failing tests if Connector/C was built with option
DEFAULT_SSL_VERIFY_SERVER_CERT=OFF
2024-09-25 08:28:56 +02:00
Georg Richter
968b5f0aa2 Fix for CONC-731: wrong error message (incorrect fp)
- moved fingerprint verification to ma_tls.c
- don't verify cert again if fingerprint check
  succeeded.
- Disable self signed check in fingerprint tests
  (Schannel only).
2024-09-24 12:08:42 +02:00
Georg Richter
3973fb84bb Merge branch '3.3' into 3.4 2024-09-20 08:38:52 +02:00
Georg Richter
f705f346c7 Merge branch '3.1' into 3.3 2024-09-20 08:35:24 +02:00
Sergei Golubchik
c4153aa833 CONC-730 Undefined behavior in the reference Ed25519 implementation
Apply the fix from MXS-4686 and MDEV-31379

Seems to originate from https://github.com/hyperledger/iroha-ed25519/pull/22
2024-09-18 17:20:58 +10:00
Georg Richter
e7b6adfbf9 Simplify tls_verification_callback 2024-09-10 07:19:12 +02:00
Georg Richter
dfdf3f7557 CONC-712: Don't verify hostname on local connection
Hostname verification is skipped if the connection
is a local connection and is considered secure
(127.0.0.1, localhost, ::1).
2024-09-09 11:12:56 +02:00
Georg Richter
b827743c27 Fix parsec build errors (posix) 2024-09-03 07:53:59 +02:00
Georg Richter
0b57bd225a Replaced _Thread_local by __thread
Following Wlad's suggestion we use __thread instead of
_Thread_local (see also server/include/my_compiler.h)
2024-09-03 07:33:57 +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
a19895efff CONC-717: Added parsec support for Windows
Parsec support for Windows uses bcrypt for deriving key from
hash value (using PBKDF2) and ma_crypto_sign from bundled ed25519
ref10 implementation for signing.

ed25519 ref10 implementation is now built as a separate object
library. Depending on the plugin configuration (dynamic or static)
it will be linked against plugin or against libmariadb.

This commit also fixes CONC-723 (CMake error when disabling
client_ed25519 plugin) and static build of client_ed25519
plugin.
2024-08-30 13:22:23 +02:00
Georg Richter
fb0496cd81 Fixed plugin header and added parsec test 2024-08-28 18:22:53 +02:00
Georg Richter
dd8df0c8ec Fix for CONC-719 and CONC-720
- Fixed parsec plugin declaration (CONC-719)
- When using gnutls crypto, also link against libnettle and
  libhogweed to avoid build error due to unresolved externals.
2024-08-28 15:04:15 +02:00
Sergei Golubchik
de6305915f Merge remote-tracking branch 'origin/3.4' into HEAD 2024-08-03 16:38:02 +02:00
Sergei Golubchik
05a1235dcc disable parsec by default 2024-08-03 16:37:59 +02:00
Nikita Malyavin
f95b7faa70 MDEV-34424 Replica server crashes when using PARSEC plugin
Replica server crashes with an invalid pointer when using a user created
with the PARSEC plugin for replication

realloc can't be done for mysql->passwd. There's also no pretty way to
pass the ext-salt into hash_password, so let's use _Thread_local instead.
2024-08-03 16:37:59 +02:00
Nikita Malyavin
e7316ff09a parsec auth plugin
Edited by: Sergei Golubchik
2024-08-03 16:37:59 +02:00
Sergei Golubchik
791741f38b cleanup: paths 2024-08-03 16:37:59 +02:00
Sergei Golubchik
0f3a41ec77 TLS post-fixes
* fix comments
* reorder errors to put hard errors on top
* report errors from openssl
* don't overwrite errors in C/C
* pass correct flags to gnutls_x509_crt_check_hostname2()
* use the same define name everywhere consistently
* don't recalculate fingerprint in openssl unnecessary
* misc
2024-08-03 16:37:57 +02:00
Vladislav Vaintroub
998a8da4b0 MDEV-33513 On Windows, build auth_gssapi_client statically and dynamically.
With normal client, statically linked plugin with be used
The DLL is for the obscure in-server client, which we never got rid off.

That client is used with mariabackup, replication, and some storage engines,
e.g connect and federated.
2024-07-28 09:38:52 +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
Nikita Malyavin
dddcf400af fix MDEV-34424 for ed255129
realloc can't be done for mysql->passwd. There's also no pretty way to
pass the ext-salt into hash_password, so let's use thread_local instead.

For GCC < 4.9 (SLES 12, CentOS 7), which don't support _Thread_local,
pk will be recalculated instead
2024-06-28 16:18:35 +02:00
Sergei Golubchik
f7373974d2 copy-paste error fixed, wrong plugin name 2024-03-15 14:42:27 +01:00
Georg Richter
d01d8c100a 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-15 14:41:53 +01:00
Vladislav Vaintroub
1437ff0470 MDEV-33513 On Windows, build auth_gssapi_client statically and dynamically.
With normal client, statically linked plugin with be used
The DLL is for the obscure in-server client, which we never got rid off.

That client is used with mariabackup, replication, and some storage engines,
e.g connect and federated.
2024-03-12 14:19:22 +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
66569ae9a2 CONC-680:
mysql_old_password authentication plugin is now disabled by
default.

It is still possible to build mysql_old_password plugin by
changing configuration in plugins/auth/CMakeLists.txt
2024-02-23 06:42:02 +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
1e2968ade7 Windows compilation warning
plugins\auth\ed25519.c(120): warning C4244: 'function': conversion from 'unsigned __int64' to 'size_t', possible loss of data
2024-02-14 15:01:29 +01:00
Sergei Golubchik
8dffd56936 MDEV-31857 enable MYSQL_OPT_SSL_VERIFY_SERVER_CERT by default
because the default value of every option is 0
(option and option.extension are bzero-ed to reset),
tls_verify_server_cert was renamed to tls_allow_invalid_server_cert
with the default value of 0, "do not allow".

API didn't change, it's still MYSQL_OPT_SSL_VERIFY_SERVER_CERT
2024-02-04 22:17:25 +01:00