1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-09-16 19:22:13 +03:00
Commit Graph

2309 Commits

Author SHA1 Message Date
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
c5ce23d340 Fix compiler warnings (schannel.c) 2024-08-30 07:39:46 +02:00
Georg Richter
c2ce7e55ba CONC-722: Fix parsec build (OpenSSL)
Check if the include file openssl/evp.h exists (Added in
OpenSSL 1.1.0) and set HAVE_evp_pkey.
2024-08-29 08:19:22 +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
Daniel Bartholomew
e3c64b59ad bump the VERSION 2024-08-20 20:38:30 -04:00
Georg Richter
312b7eab4d Folow up of CONC-567 Schannel:
Added TLSv1.3 in ma_tls_get_protocol_version
2024-08-06 13:48:14 +02:00
Vladislav Vaintroub
7df01d4bac Merge branch '3.3-wlad-schannel' into 3.3 2024-08-05 13:26:36 +02:00
Sergei Golubchik
de6305915f Merge remote-tracking branch 'origin/3.4' into HEAD v3.4.1 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
1e8e1f4f38 Fix "set but not used" warnings. 2024-07-31 20:48:44 +02:00
Vladislav Vaintroub
3ceb310ebe CONC-567 Schannel : support TLSv1.3
Use SCH_CREDENTIAL structure, to support TLSv1.3
Allow TLSv1.3 starting with Windows 11 / Server 2022, which are
first Windows releases to officially support latest TLS version
2024-07-31 20:48:34 +02:00
Vladislav Vaintroub
d15c73859c CONC-567 Schannel - handle SEC_I_RENEGOTIATE, prepare for TLSv1.3
There is no real renegotiation in TLSv1.3 protocol, so it is
some internal schannel thing, that makes DecryptMessage() to return
SEC_I_RENEGOTIATE, to replay a handshake step.

This pops up when TLSv1.3 is enabled.
2024-07-31 20:48:08 +02:00
Marko Mäkelä
4681372f9c CONC-700: Fix gcc-14 -Wcalloc-transposed-args 2024-07-31 10:05:00 +03:00
Georg Richter
95d5623da3 Bump version number -> 3.3.12 2024-07-31 06:01:21 +02:00
Vladislav Vaintroub
72116a30ab Merge branch '3.1' into 3.3 2024-07-29 11:53:15 +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.
v3.3.11
2024-07-28 09:38:52 +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
Oleksandr Byelkin
2888c180e4 bump version 2024-07-24 09:53:26 +02:00
Georg Richter
01b6b3214f Travis fix: use export instead of set command 2024-07-19 10:16:56 +02:00
Georg Richter
32c39a9ce3 travis fix:
Fixed env variables for windows test
2024-07-18 10:56:50 +02:00
Georg Richter
db43d63817 removed x509 test from connection
x509 tests are in tls test already
2024-07-18 09:58:05 +02:00
Georg Richter
e308fae99b tls test fix:
Skip tests with passwords using self signed certificate
when running against servers < 11.4
2024-07-18 09:40:56 +02:00
Georg Richter
109ec58608 tls test fixes:
Always specify port and socketname (otherwise
we can't test against external servers)
2024-07-18 08:38:17 +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
efbc562477 tls test fix:
- Don't skip ca test when running with schannel.
- Load new self signed cert after expiration test
2024-07-17 11:56:44 +02:00
Georg Richter
ea307b8d6e Travis fixes for windows 2024-07-17 11:06: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
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
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
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
Daniel Bartholomew
6dfc071d35 bump the VERSION 2024-06-18 11:01:17 -04: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
f97bb2e92e Fix failing tests when server runs on a different machine 2024-06-10 13:19:49 +02:00
Vladislav Vaintroub
2daa7b289a Windows, OpenSSL - HAVE_OPENSSL_APPLINK_C is not set, when compiling with /WX
CHECK_INCLUDE_FILES failed during configuration phase, as applink.c
compiles with "warning C4996: 'fopen' was declared deprecated",
hence warning == error makes compile time check fail.

This happens at least when using OpenSSL 3.2, but not with older versions.

The consequence is that in some cases(e.g using SSL with client
certificates), client would exit with "Applink not found" at runtime.

Fix by defining HAVE_OPENSSL_APPLINK_C, if
${OPENSSL_INCLUDE_DIR}/include/openssl/applink.c merely exists, without
attempting to compile.
2024-05-28 00:40:48 +02:00
Georg Richter
5efe1e61e2 Merge branch '3.4' of https://github.com/mariadb-corporation/mariadb-connector-c into 3.4 v3.4.0 2024-05-27 16:19:29 +02:00
Georg Richter
8b1019fc28 Travis: remove 10.6 and 11.3 unit testing 2024-05-27 16:18:48 +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
551e1e3971 travis: removed skysql 2024-05-14 13:58:20 +02:00
Georg Richter
4623d104e8 Merge branch '3.3' into 3.4 2024-05-14 09:54:50 +02:00