1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-09-21 05:02:39 +03:00
Commit Graph

2087 Commits

Author SHA1 Message Date
Vladislav Vaintroub
536d9e2b9e MDEV-33430 Fix unexpected "SSL certificate self-signed" errors on Windows
These errors stem from generating self-signed certificates, and enabling
SSL + SSL certificate validation in clients.

This was done without considering Windows specifics, such as
- TCP connections by default
- non-password based plugin, auth_gssapi, in every installation

To provide some relief, consider local TCP connections to be secure
transport and skip self-signed errors for them at least.
2024-02-09 02:09:38 +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
fcef411ecb MDEV-31855 hash_password_bin for native_password and ed25519 2024-02-04 22:17:25 +01:00
Sergei Golubchik
79a746f290 unix socket and named pipes are secure
as in --require-secure-transport
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
Sergei Golubchik
50f65db279 compilation warning
ps_bugs.c:3275:5: note: ‘sprintf’ output between 9 and 19 bytes into a destination of size 12
2024-02-04 22:17:25 +01:00
Sergei Golubchik
5c9eab55f0 remove a redundant duplicate of plugin_auth.h 2024-02-04 22:17:25 +01:00
Sergei Golubchik
2f6b5a523c typo in the fp commit, cert_fp unused
also rename fp->f to avoid shadowing a variable
2024-02-04 22:17:25 +01:00
Sergei Golubchik
830d137387 don't use the output printf buffer as a %s parameter
followup for ebcb9eca29
2024-02-04 22:17:24 +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
Georg Richter
4da7d9d466 Merge branch '3.3' of https://github.com/mariadb-corporation/mariadb-connector-c into 3.3 2024-02-04 11:12:25 +01:00
Georg Richter
6466cabd08 Bump version to 3.3.10 2024-02-04 11:11:49 +01:00
Vladislav Vaintroub
9155b19b46 MDEV-26579 - fix resource.rc.in 2024-01-26 10:40:03 +01:00
Vladislav Vaintroub
12f3b29c14 MDEV-26579 - post-fix, fix standalone C/C build 2024-01-26 10:17:04 +01:00
Vladislav Vaintroub
12cc91ab6d MDEV-26579 - support minor upgrades of the server MSI
Connector library version resource should contain the server's numeric
version as FileVersion, when connector will be included into server
installation. Otherwise, file version will match the connectors CPACK
variables.

Prior to this patch, all libraries produced by connector, had a hardcoded
file version 3.0.0.7, which was neither the server's , nor the client's.

Also fix the Translation info in the version resource so it has valid LCID
2024-01-26 10:16:48 +01:00
Vladislav Vaintroub
395641549a Do not use own warning-as-error logic, if standard CMake flag is in us.
If CMAKE_COMPILE_WARNING_AS_ERROR is set, ígnore DIY logic.
CMAKE_COMPILE_WARNING_AS_ERROR is available since CMake 3.24

-DCMAKE_COMPILE_WARNING_AS_ERROR=0 will also help to avoid currently
unconditional "warning is error" when building standalone or via
ExternalProject_Add
2024-01-24 11:55:21 +01:00
Vladislav Vaintroub
83951feec9 CONC-686 Error 2026 TLS error messages truncated
Do not truncate error message to arbitrary length. TLS messages can be long
2024-01-24 11:10:50 +01:00
Oleksandr Byelkin
e714a67482 Bump version to 3.3.9 v3.3.9 2024-01-22 15:50:17 +01:00
Georg Richter
26cef16b25 Merge pull request #239 from uilianries/hotfix/find-zstd
Add support to ZSTD as static library
2023-12-22 09:43:36 +01:00
Sergei Golubchik
77a2e6ac5d don't warn about the authenticity of client-side errors
they cannot be sent by the server (ma_net_safe_read() guarantees that)
so they all should be safe and not forged

also, use existing macros to check for error ranges, they are
sufficiently parenthesized to avoid compiler warnings (errors with -Werror)
about "you might want to add parentheses here"
2023-12-21 19:00:35 +01:00
Daniel Lenski
bd87353512 Remove unreachable code section
Based on Sergei Golubchik's question about this code section in
https://github.com/mariadb-corporation/mariadb-connector-c/pull/223#issuecomment-1773728383,
eventually culminating in the conclusion that it's literally impossible to
reach this code section based on the types and signedess of the variables
involved:
https://github.com/mariadb-corporation/mariadb-connector-c/pull/223#issuecomment-1854720364

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.
2023-12-21 18:38:12 +01:00
Daniel Lenski
ebcb9eca29 [CONC-648] Do not trust error packets received prior to TLS handshake completion
MariaDB Connector/C does not distinguish [application-layer error
packets](https://mariadb.com/kb/en/err_packet) that it receives prior to TLS
handshake completion from those that it receives immediately after.

(A trivially modified server built from
https://github.com/dlenski/mariadb-server/commit/demonstration_of_CONC-648_vulnerability
can easily be used to demonstrate this.)

Pre-TLS error packet received from this trivially modified server. This packet
should NOT be trusted to actually originate from the server:

    $ mariadb --ssl --ssl-verify-server-cert -uUsername -pVerySecretPassword -h CONC-648.vuln.demo.server.com
    ERROR 1815 (HY000): Internal error: Client will accept this error as genuine even if running with --ssl --ssl-verify-server-cert, and even though this error is sent in plaintext PRIOR TO TLS HANDSHAKE.

Post-(TLS handshake) error packet received from a normal MariaDB server upon
an attempt to connect with incorrect credentials.  This error packet CAN be
trusted to actually originate from the server, assuming transitive trust in
the TLS protocol implementation and PKI-based certificate validation:

    $ mariadb --ssl --ssl-verify-server-cert -uUsername -pWrongPassword -h $NORMAL_MARIADB10.6.14_SERVER
    ERROR 1045 (28000): Access denied for user 'Username'@'A.B.C.D' (using password: YES)

This client behavior opens up MariaDB Connector/C clients to an extremely
straightforward [downgrade attack](https://en.wikipedia.org/wiki/Downgrade_attack).

An on-path or pervasive attacker can inject errors into MariaDB
client→server connections that are intended to be protected by TLS, and the
client has no clear mechanism to distinguish such errors from errors that
actually come from the server.

An attacker could easily use this to DOS a client, or even influence its
behavior.  For example, consider a client application which is configured…

1. To use TLS with server certificate validation
   (`--ssl --ssl-verify-server-cert`), and
2. To wait for a back-off period and then *retry* connection attempts if the server
   responds with `ER_CON_COUNT_ERROR` ("Too many connections") from the
   server, and
3. To give up and shut down if its connection attempts fail with
   `ER_ACCESS_DENIED_ERROR` ("Access denied for user"), on the assumption
   that this is due to an incorrect or expired password, and cannot be
   resolved without human intervention.

An attacker could completely disable the retry mechanism of this application
by intercepting connection attempts and replying with
`ER_ACCESS_DENIED_ERROR` packets.

This patch modifies MariaDB Connector/C so that if the client is configured
to use TLS, error packets received prior to the completion of the TLS
handshake are untrusted, and are changed to a generic `CR_CONNECTION_ERROR`.

    $ mariadb --ssl --ssl-verify-server-cert -uUsername -pVerySecretPassword -h CONC-648.vuln.demo.server.com
    ERROR 2002 (HY000): Received error packet before completion of TLS handshake. The authenticity of the following error cannot be verified:
    1815 - Internal error: Client will accept this error as genuine even if running with --ssl --ssl-verify-server-cert, and even though this error is sent in plaintext PRIOR TO TLS HANDSHAKE.

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.
2023-12-21 18:38:12 +01:00
Daniel Lenski
4419abe71a Client should reject CLIENT-only error codes sent by the server
Per @vuvova in
https://github.com/mariadb-corporation/mariadb-connector-c/pull/223#issuecomment-1854720364:

> I don't think the client should accept client-side errors from the server
> at all.

If the server sends an error packet with error codes in the ranges
`CR_{MIN,MAX}_ERROR` (codes [2000, 2999]) or `CER_{MIN,MAX}_ERROR` (codes
[5000, 5999]), we will replace these with `CR_MALFORMED_PACKET`, rather than
propagating them to the client user.
2023-12-21 18:38:12 +01:00
Georg Richter
00fb2062b9 Test fix for MaxScale:
Skip character set tests which set character set
during handshake, since MaxScale sends utf8mb4 via
session_track information in handshake OK packet.
(https://jira.mariadb.org/browse/MXS-4898).
2023-12-14 09:07:44 +01:00
Georg Richter
b0a2f65f55 Character set test:
Added diagnostic output.
2023-12-14 08:01:46 +01:00
Georg Richter
ba55b5b78f Test fix:
Append terminating 0 in status_callback_function.
2023-12-13 18:46:55 +01:00
rusher
f621f6bf41 [misc] using common default servers test suite 2023-12-12 23:56:06 +01:00
Georg Richter
f1a72768d4 Bump version to 3.1.23 v3.1.23 2023-11-23 07:11:13 +01:00
Vladislav Vaintroub
75ab6fb174 Allow named pipe connection handle to be used with IO completion port
Client programs can use pipe handle via mysql_get_socket().
They also might want to use IO completion ports with this handle.

Prevent IOCP notifications to be sent to completion port, for internal
read and write with timeout.
2023-11-19 16:46:36 +01:00
Uilian Ries
389876a01a Add support to ZSTD static library
Signed-off-by: Uilian Ries <uilianries@gmail.com>
2023-11-03 15:24:56 +01:00
Sergei Golubchik
458a4396b4 don't force -Werror if a subproject
use superproject settings instead

also, remove useless caching of WARNING_AS_ERROR
v3.3.8
2023-11-01 11:28:04 +01:00
rusher
eb6cad1e30 [misc] correcting CI testing label with ps-protocol 2023-10-24 10:07:27 +02:00
rusher
7293150908 [misc] CI testing changes
* adding 10.6/10.11/11.3 server testing
* removing skysql test
2023-10-23 17:59:33 +02:00
Oleksandr Byelkin
64f9d88f30 Merge branch '3.1' into 3.3 2023-10-23 13:36:05 +02:00
Oleksandr Byelkin
ae565eea90 Use safer snprintf call. 2023-10-23 13:32:45 +02:00
Georg Richter
4f5950b4b6 Merge branch '3.1' into 3.3 2023-10-21 19:46:00 +02:00
Georg Richter
8320f0d54d Fix error on 32-bit systems
Problem was introduced with fix for CONC-668.
2023-10-21 19:43:42 +02:00
Georg Richter
642bc31ed2 Follow up of PR-236 (update ma_context):
Since there is no way in the ISO C standard to specify a
non-obsolescent function prototype indicating that a
function will be called with an arbitrary number (including
zero) of arguments of arbitrary types, we have to cast the
callback function in makecontext() call to avoid compiler
warnings/errors.

See also:
https://pubs.opengroup.org/onlinepubs/009695399/functions/makecontext.html
2023-10-21 08:09:40 +02:00
Georg Richter
26b2eddbf4 Merge branch '3.1' into 3.3 2023-10-20 06:53:07 +02:00
Tildeslash
808312f1e4 Update ma_context.c
Old K&R function declaration is no longer supported when compiling on macOS 13.5.2
2023-10-20 06:52:21 +02:00
Georg Richter
acc0b05774 Merge pull request #236 from tildeslash/patch-1
Update ma_context.c
2023-10-20 06:50:43 +02:00
Georg Richter
35cd69beb4 Fix for CONC-672:
To avoid a false positive GCC warning about possible string
truncation strncpy was replaced by memcpy.
2023-10-20 06:44:38 +02:00
Georg Richter
ab38a07b03 Fix for CONC-670:
Initialize time struct in pvio_socket_set_timeout.
2023-10-11 10:43:25 +02:00
Georg Richter
b323b5462d Windows installation fix:
MSI package didn't install include/mariadb.
2023-09-27 10:19:23 +02:00
Georg Richter
5d51d160d8 Merge branch '3.3' of https://github.com/mariadb-corporation/mariadb-connector-c into 3.3 2023-09-27 09:58:22 +02:00
Georg Richter
0e7082f159 Fix include file path for ma_io.h 2023-09-27 09:57:55 +02:00
Tildeslash
249d838bc0 Update ma_context.c
Old K&R function declaration is no longer supported when compiling on macOS 13.5.2
2023-09-23 02:33:37 +02: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