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

23 Commits

Author SHA1 Message Date
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
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
63df45ce3d CONC-447 ERROR 2026 (HY000): SSL connection error: Certificate signature check failed
Implement proper verification for server certificate chain,
with refactoring of the certificate stuff.

If custom CA and CRL certs are given, load them into in-memory store, and
use CertVerifyCertificateChainPolicy() to verify the certificate chain.

There are minor errors fixed, such as
- now there is a support for private keys encoded as BEGIN/END PRIVATE KEY
in PEM, instead of only BEGIN/END RSA PRIVATE KEY
- memory leak around CryptAcquireContext() is fixed i.e when client loads
private key, it previously did never released it, not even when connection
ended.

The handling of certificates moved into schannel_certs.c from various places
2019-12-08 18:07:48 +01:00
Sergei Golubchik
ab4d09dd8d fix compilation falire on windows 2019-06-05 18:21:55 +02:00
Georg Richter
b0411b731f CONC-386:
Added support for pem files which contain certificate and private key.
In case the file will contain more than one certificate or key, the first
certificate or key found will be used.
2019-06-02 13:39:27 +02:00
Georg Richter
abee401956 Use lowercase names for windows include files 2018-12-01 10:59:50 +01:00
Vladislav Vaintroub
db1a1a1d31 more clang fixes 2018-02-12 09:29:27 +00:00
Georg Richter
02f57a9c14 Fix for CONC-276: client library crashes on Windows after TLS reconnect:
The connection pointer mysql is now no longer part (and doesn't need to be updated) of schannel security context, since it can be obtained directly from tls container.
2017-08-24 18:09:50 +02:00
Georg Richter
967b2830d8 renamed ma_errmsg.h back to errmsg.h 2016-11-16 18:13:59 +01:00
Vladislav Vaintroub
93af3ae693 Simplify and fix ma_schannel_read_decrypt() to cache state
between the calls.

State can be unread buffer  from DecryptMessage (SECBUFFER_EXTRA)
or decrypted data that did not fit into callers buffer

- Fix error handling - SEC_I_RENEGOTIATE is handled as error,
we're not doing it yet. Stop reading at SEC_I_CONTEXT_EXPIRED.

- Fix buffer sizes  pased to SSPI ( so that large buffers can be read or written
"SELECT REPEAT('a', 20000)"

- Fix unchecked memcpy into the output buffer (size of the output buffer
was not checked, so it is a potential memory overrun)
2016-10-14 17:49:30 +00:00
Vladislav Vaintroub
629ec64630 Fix PVIO to return number of bytes read/written as "signed" integer
since there is a lot of checks for return code being < 0 or -1.
2016-10-13 17:42:03 +00:00
Sergei Golubchik
f95877dc5f Merge branch 'master' into serg-integr 2016-09-15 09:21:30 +02:00
Vladislav Vaintroub
2157642849 Cleanup/fix schannel TLS implementation
- remove global variables
- remove in memory certificate stores that cache all CRL and all CA
- verify certificate against ssl_ca and ssl_crl  specified in
connection options (not against all CRL/CA in store)
2016-09-09 20:17:30 +00:00
Vladislav Vaintroub
38b5e400da C/C integration : Fix mysql_test_client test
- #include <stdlib.h> for strtod and other prototypes
- remove ma_config_win.h as it  redefines things from ma_config.h
- fix compile warnings
2016-09-07 17:14:02 +00:00
Georg Richter
4b1e94bccc Since we use TLS and not SSL functions and structures were renamed
from SSL to TLS
2016-03-16 18:20:08 +01:00
Georg Richter
85525c2ba7 Merge remote-tracking branch 'origin/3.1' 2016-02-16 17:40:03 +01:00
Georg Richter
509b948e7d SSL fixes:
- added MARIADB_OPT_SSL_CIPHER_STRENGTH (value uint) for Schannel
- fixed mutes in all ssl variants
2016-02-16 13:04:16 +01:00
Georg Richter
4ca933bb81 Global cleanup:
removed global locks
  removed dead code and files
  removed dbug
2016-02-08 18:43:02 +01:00
Georg Richter
c5ca735dd3 Renamed prefixes for 10.2 integration 2016-02-02 12:12:04 +01:00
Georg Richter
72f7c4abf5 Windows 64-bit fixes:
changed type of length parameter in mysql_stmt_prepare,
mysql_real_query, mysql_stmt_send_long_data (incl. async _start
functions) from unsigned long to size_t.
Fixed warnings
2015-11-05 11:52:50 +01:00
Georg Richter
7500f37150 - Renamed cio to pvio (pluggable virtual IO)
- minor fixes in windows schannel
2015-10-27 10:24:48 +01:00
Georg Richter
4597cd6a80 Various ssl and schannel fixes 2015-09-10 17:16:21 +02:00
Georg Richter
df8f6225f7 schannel is no longer plugin 2015-08-16 12:00:59 +02:00