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

211 Commits

Author SHA1 Message Date
Georg Richter
6d28fe89af Merge branch '3.1' into 3.3 2024-12-08 11:50:43 +01:00
Georg Richter
af44fc5c5e CONC-748: Allow to set TLSv1.3 ciphers in GnuTLS
- Added TLSv1.3 ciphers to cipher map.
- Fixed retrieval of cipher suite: Since gnutls_cipher_suite_get_name
  supports only TLSv1.2 (and lower) cipher suites, we have to call
  gnutls_ciphersuite_get() (requires GnuTLS 3.7.4 or newer).
2024-12-08 11:27:32 +01:00
Vladislav Vaintroub
76564675fc Merge 3.1 into 3.3 2024-11-07 08:47:12 +01:00
Vladislav Vaintroub
b1f1267805 CONC-527 post-fix.
Add fallback if CryptAcquireContext fails with ERROR_ACCESS_DENIED,
as seen in Jenkins CI.

The fallback, also suggested by https://stackoverflow.com/a/14053718/547065,
is to retry with machine-wide key container, if user-specific fails.
2024-11-07 08:30:59 +01: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
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
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
4d46ae76bc Merge branch '3.1' into 3.3 2024-05-08 11:43:18 +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
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
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
Sergei Golubchik
a99570c118 MDEV-31855 SSL cert validation protocol extension
* extend the client auth plugin API with a new callback
* relax the plugin version check to allow load a plugin with the
  same major version, even if the minor versions differ
* implement the protocol extension:
  - don't abort at once if the certificate is self signed and
    no CA was explicitly specified
  - allow it if it passes fingerprint check
  - allow it if plugin has hash_password_bin callback, password was
    non-empty and the control hash matches server's
2024-02-04 22:17:25 +01:00
Georg Richter
9aa15e72a7 TLS fingerprint
Beside SHA1 fingerprint hash, Connector/C now also supports
SHA224 (OpenSSL and GnuTLS only), SHA256, SHA384 and SHA512
fingerprint hashes.
2024-02-04 22:17:22 +01:00
Vladislav Vaintroub
4692e9cec1 CONC-645 : fix build with clang (v16), clang-cl(v16), and mingw-gcc(v12).
schannel_certs.c - conflicting headers, include winsock2.h before windows.h,

strerror_r is now defined also with mingw

do not build mariadb_config on Windows, getopt.h is missing
2023-09-22 00:59:48 +02:00
Vladislav Vaintroub
463a50e973 Merge remote-tracking branch 'origin/3.1' into 3.3
# Conflicts:
#	include/ma_crypt.h
#	libmariadb/mariadb_lib.c
2023-09-21 23:45:35 +02:00
Vladislav Vaintroub
1b3cf6b441 CONC-669 Cache bcrypt algorithm providers in win_crypt.c
CryptOpenAlgorithmProvider() documentation states:
"We recommend that you cache any algorithm provider handles that you will
use more than once, rather than opening and closing the algorithm providers
over and over."

This patch implements algorithm handle caching,
and also simplifies how hashes are handled in win_crypt.c

- MA_HASH_CTX* is now just BCrypt hash handle.
- We no longer allocate or free memory any memory outselves.

There are small change in the ma_hash API:
ma_hash_new() lost the second parameter, only used on Windows previously
2023-09-21 18:06:01 +02:00
Georg Richter
4e3905c20a Fix for bcrypt hash functions:
Using a global crypt provider is not thread safe, so we need to load
provider via BCryptOpenProvider in ma_hash_new().
2023-08-23 16:18:50 +02:00
Georg Richter
3a255ee3ea Merge branch '3.1' into 3.3 2023-07-24 11:07:05 +02:00
Georg Richter
45feebb99d Remove server certification verification
Since the server certification option is used by client
only, there is no need to have this flag in server and or
client capabilities. The server itself validates client
certificate depending on the user definition.
2023-07-13 09:30:33 +02:00
Georg Richter
d9af4fcbc6 Merge branch '3.1' into 3.3 2022-11-07 09:09:29 +01:00
Sergei Golubchik
ad43ed2965 better error on aborted connection
according to `man SSL_get_error`

  The SSL_ERROR_SYSCALL with errno value of 0 indicates unexpected EOF
  from the peer. This will be properly reported as SSL_ERROR_SSL with
  reason code SSL_R_UNEXPECTED_EOF_WHILE_READING in the OpenSSL 3.0
  release because it is truly a TLS protocol error to terminate the
  connection without a SSL_shutdown().

let's use a conventional CR_SERVER_LOST in this case instead of
"TLS/SSL error: Success(0)"
2022-09-13 16:07:25 +02:00
Haidong Ji
020ed982b6 More robust call to X509_check_host using strlen not 0
Based on its interpretation of RFC 6125 section 6.4.2[^1], OpenSSL's
implementation[^2] of `X509_check_host` treats the `namelen` parameter
in a peculiar way:

- If `namelen` is non-zero, use it;
- Otherwise, use `strlen(name)` instead

There are now many forks of OpenSSL. Implementer of the forks may
interpret RFC 6125 section 6.4.2 a little differently. They may always
expect `strlen(name)` and NOT `0`. We have come across that with
AWS-LC[^3].  AWS-LC has agreed to make an adjustment so it is consistent
with OpenSSL in this matter. But other forks may not.

To make MariaDB connector C more robust, I think it's better that we
always pass `strlen(name)` instead of `0`. Unless there are compelling
reasons not doing so.

All new code of the whole pull request, including one or several files
that are either new files or modified ones, are contributed under the
BSD-new license. I am contributing on behalf of my employer Amazon Web
Services, Inc.

[^1]: https://www.rfc-editor.org/rfc/rfc6125.html#section-6.4.2
[^2]: https://www.openssl.org/docs/man3.0/man3/X509_check_host.html
[^3]: https://github.com/awslabs/aws-lc
2022-09-05 19:43:57 +00:00
Georg Richter
dcb14e3c5d erge branch '3.1' into 3.3 2022-08-01 12:26:27 +02:00
Georg Richter
12722e3131 Error message fix:
Since TLS errors might happen not only when connecting and SSL protocol
is not longer used, errormessage for CR_SSL_CONNECTION_ERROR was replaced
by TLS/SSL error.
2022-07-27 14:52:20 +02:00
Georg Richter
6dbd953420 Merge branch '3.1' into 3.3 2022-07-24 10:52:52 +02:00
Georg Richter
8e8d175a64 Fix gnutls error message:
When using default error string (2026), a zero ptr
for error message needs to be specified.
2022-07-22 08:16:25 +02:00
Georg Richter
6700ee4a7c Make TLS/SSL more verbose:
Added TLS/SSL prefixes for error strings
Report Error string for errno
2022-07-21 09:47:23 +02:00
Georg Richter
e8e356e355 Merge branch '3.1' into 3.3 2022-07-18 11:48:33 +02:00
Georg Richter
9a572bc548 Fix for CONC-604 and CONC-605:
This patch fixes a crash when reconnectiong via TLS.
2022-07-18 11:41:46 +02:00
Georg Richter
dac298de61 CONC-605: Disable sigpipe
Added option GNUTLS_NO_SIGNAL in gnutls_init options to disable
SIGPIPE errors on platforms which support MSG_NOSIGNAL.
2022-07-11 07:53:31 +02:00
Georg Richter
5565de132d Merge branch '3.1' into 3.3 2022-07-08 07:49:24 +02:00
Georg Richter
f1b08b8369 Partial fix for MDEV-27405:
The return value of SSL_read indicates an error if it is <= 0, not
if it is < 0.
2022-07-08 07:46:00 +02:00
Georg Richter
3ba4c4a613 Merge branch '3.1' into 3.2 2022-04-20 18:55:05 +02:00
Georg Richter
3ce51b0b3e Fix for CONC-587:
Since alerts may happen after handshake (for example with described
test in CONC-587 using TLSv1.3 protocol or by renegotiation) the
tls error message needs to be retrieved if error is a protocol error
(SSL_ERROR_SSL) and/or if errno was not set.
2022-04-20 18:48:54 +02:00
Georg Richter
e730df7aaf Merge branch '3.1' into 3.2 2021-11-03 16:35:27 +01:00
Georg Richter
b2bb1b213c Fix for CONC-570:
Removed callback function for crypto threads, since the callback function
cannot be cleared. For OpenSSL <= 1.0.2 the default implementation will be used:
address of errno (Posix) or GetCurrentThreadId (Windows).
2021-11-03 16:29:45 +01:00
Vladislav Vaintroub
15c7004022 Fix clang-cl warnings "variable initialized but unused"
Fix some comments.
2021-10-11 20:06:35 +02:00
Marko Mäkelä
fc25d79083 Merge 3.1 into 3.2 2021-08-31 10:28:30 +03:00
Vladislav Vaintroub
cc56a1ced5 Fix MSVC/ASAN error
Apparently, it complains about wild pointer freed in when using
ASAN_OPTIONS= windows_hook_rtl_allocators=true

while it seems like a false positive, take it as a good opportunity to
remove allocators from Win3.1 times, and replace with simple malloc/free
2021-08-13 08:15:40 +02:00
Georg Richter
903c3ef3fc Merge branch '3.1' into 3.2 2021-06-29 10:10:01 +02:00
Georg Richter
07a15f23a2 Fix for CONC-558:
Allow all curves when specifiying a cipher suite.
2021-06-29 10:07:51 +02:00
Vladislav Vaintroub
b9a4719fca Merge branch '3.1' into 3.2 2021-06-15 00:44:13 +02:00
Vladislav Vaintroub
802ce584a2 CONC-555 appverifier error in schannel_free_cert_context
It looks like CertFreeCertificateContext() would try to access
freed memory.

Fix it by using CERT_STORE_NO_CRYPT_RELEASE_FLAG when setting private key
in certificate, i.e avoid releasing the crypto provider when certificate
is freed.

Note:
My attempts to fix with less code , i.e just omit CryptReleaseContext(),
failed, there was a small memory leak left after freeing each SSL
connection.
2021-06-14 22:45:19 +02:00
Georg Richter
971489fa44 Reverted remove of TLSv1.0 protocol
TLSv1.0 protocol was removed by mistake
in commit e4e5b28452
2021-06-08 10:13:02 +02:00
Georg Richter
e4e5b28452 CONC-533: Support for asynchronous statements (binary protocol)
Added a new option MARIADB_OPT_SKIP_READ_RESPONSE which skips automatic
reading of server response after sending a command to the server.

Server packets have to be retrieved by calling the corresponding methods,
e.g:

Send command                         Read method
mysql_real_query/mysql_send_query    db_read_query_result
mysql_stmt_prepare                   db_read_prepare_response
mysql_stmt_execute,
mariadb_stmt_execute_direct          db_read_execute_response
2021-05-13 21:21:43 +02:00
Georg Richter
132c5b51c1 CONC-433: Add CRL support for GnuTLS
Added support for certificate revocation list (CRL) in GnuTLS.
2021-04-15 18:19:45 +02:00
Georg Richter
13bcf7cfdf Fix for CONC-539
Added cipher suites ECDHE-RSA-AES128-SHA256 (0xC027) and
ECDHE-RSA-AES256-SHA384 (0xC028) to the cipher map which maps
cipher suite names to the corresponding algorithm ids.

Since this list is still incomplete, and additional list containing
the cipher suite ids and openssl cipher suite names was added. This
list will be used now to detect the cipher suite for the current
connection.
2021-04-01 07:15:29 +02:00