You've already forked mariadb-connector-c
mirror of
https://github.com/mariadb-corporation/mariadb-connector-c.git
synced 2025-08-07 02:42:49 +03:00
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.
95 lines
2.8 KiB
C
95 lines
2.8 KiB
C
/************************************************************************************
|
|
Copyright (C) 2014 MariaDB Corporation Ab
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Library General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Library General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
License along with this library; if not see <http://www.gnu.org/licenses>
|
|
or write to the Free Software Foundation, Inc.,
|
|
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
|
|
|
|
Author: Georg Richter
|
|
|
|
*************************************************************************************/
|
|
#ifndef _ma_schannel_h_
|
|
#define _ma_schannel_h_
|
|
|
|
#define SECURITY_WIN32
|
|
#include <ma_global.h>
|
|
#include <ma_sys.h>
|
|
#include <ma_common.h>
|
|
#include <ma_pvio.h>
|
|
#include <errmsg.h>
|
|
#include <ma_hash.h>
|
|
|
|
|
|
#include <wincrypt.h>
|
|
#include <wintrust.h>
|
|
|
|
|
|
#include <security.h>
|
|
#include <ma_crypt.h>
|
|
|
|
#include <schnlsp.h>
|
|
#undef SECURITY_WIN32
|
|
#include <windows.h>
|
|
#include <sspi.h>
|
|
|
|
#include <ma_global.h>
|
|
#include <ma_sys.h>
|
|
#include <ma_pvio.h>
|
|
#include <ma_tls.h>
|
|
|
|
#define SC_IO_BUFFER_SIZE 0x4000
|
|
|
|
|
|
#include <ma_pthread.h>
|
|
|
|
struct st_DER {
|
|
char* der_buffer;
|
|
DWORD der_length;
|
|
};
|
|
|
|
struct st_schannel {
|
|
CredHandle CredHdl;
|
|
PUCHAR IoBuffer;
|
|
DWORD IoBufferSize;
|
|
SecPkgContext_StreamSizes Sizes;
|
|
CtxtHandle hCtxt;
|
|
BCRYPT_ALG_HANDLE HashProv[MA_MAX_HASH_SIZE];
|
|
/* Cached data from the last read/decrypt call.*/
|
|
SecBuffer extraBuf; /* encrypted data read from server. */
|
|
SecBuffer dataBuf; /* decrypted but still unread data from server.*/
|
|
|
|
};
|
|
|
|
typedef struct st_schannel SC_CTX;
|
|
|
|
extern HCERTSTORE ca_CertStore, crl_CertStore;
|
|
extern my_bool ca_Check, crl_Check;
|
|
|
|
;
|
|
SECURITY_STATUS ma_schannel_client_handshake(MARIADB_TLS *ctls);
|
|
SECURITY_STATUS ma_schannel_handshake_loop(MARIADB_PVIO *pvio, my_bool InitialRead, SecBuffer *pExtraData);
|
|
|
|
unsigned int ma_schannel_verify_certs(MARIADB_TLS *ctls, unsigned int verify_flags);
|
|
ssize_t ma_schannel_write_encrypt(MARIADB_PVIO *pvio,
|
|
uchar *WriteBuffer,
|
|
size_t WriteBufferSize);
|
|
SECURITY_STATUS ma_schannel_read_decrypt(MARIADB_PVIO *pvio,
|
|
CtxtHandle* phContext,
|
|
DWORD *DecryptLength,
|
|
uchar *ReadBuffer,
|
|
DWORD ReadBufferSize);
|
|
|
|
|
|
#endif /* _ma_schannel_h_ */
|