Skip to content

Commit 113418c

Browse files
committed
MDEV-14027: Determine TLS/SSL library version
1 parent 5e32110 commit 113418c

File tree

7 files changed

+45
-13
lines changed

7 files changed

+45
-13
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ CONFIGURE_FILE(${CC_SOURCE_DIR}/include/mariadb_version.h.in
338338
INCLUDE_DIRECTORIES(${CC_BINARY_DIR}/include)
339339

340340
IF(WIN32)
341-
SET(SYSTEM_LIBS ws2_32 advapi32 kernel32 shlwapi)
341+
SET(SYSTEM_LIBS ws2_32 advapi32 kernel32 shlwapi version)
342342
ELSE()
343343
SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${LIBPTHREAD} ${LIBDL} ${LIBM})
344344
IF(ICONV_EXTERNAL)

include/ma_tls.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#ifndef _ma_tls_h_
22
#define _ma_tls_h_
33

4+
#define TLS_VERSION_LENGTH 64
5+
extern char tls_library_version[TLS_VERSION_LENGTH];
6+
47
enum enum_pvio_tls_type {
58
SSL_TYPE_DEFAULT=0,
69
#ifdef _WIN32

libmariadb/ma_tls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static my_bool ma_pvio_tls_compare_fp(const char *cert_fp,
153153
char d1, d2;
154154
if (*p == ':')
155155
p++;
156-
if (p - fp > fp_len -1)
156+
if (p - fp > (int)fp_len -1)
157157
return 1;
158158
if ((d1 = ma_hex2int(*p)) == - 1 ||
159159
(d2 = ma_hex2int(*(p+1))) == -1 ||

libmariadb/mariadb_lib.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3709,15 +3709,9 @@ my_bool STDCALL mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void *
37093709
break;
37103710
case MARIADB_TLS_LIBRARY:
37113711
#ifdef HAVE_TLS
3712-
#ifdef HAVE_GNUTLS
3713-
*((const char **)arg)= "GNUTLS";
3714-
#elif HAVE_OPENSSL
3715-
*((const char **)arg)= "OPENSSL";
3716-
#elif HAVE_SCHANNEL
3717-
*((const char **)arg)= "SCHANNEL";
3718-
#endif
3712+
*((char **)arg)= tls_library_version;
37193713
#else
3720-
*((char **)arg)= "OFF";
3714+
*((char **)arg)= "Off";
37213715
#endif
37223716
break;
37233717
case MARIADB_CLIENT_VERSION:

libmariadb/secure/gnutls.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,8 @@ int ma_tls_start(char *errmsg, size_t errmsg_len)
969969
ma_tls_get_error(errmsg, errmsg_len, rc);
970970
goto end;
971971
}
972+
snprint(tls_library_version, TLS_VERSION_LENGTH - 1, "GnuTLS %s",
973+
gnutls_check_version(NULL));
972974
ma_tls_initialized= TRUE;
973975
end:
974976
pthread_mutex_unlock(&LOCK_gnutls_config);

libmariadb/secure/openssl.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <mysql/client_plugin.h>
2727
#include <string.h>
2828
#include <openssl/ssl.h> /* SSL and SSL_CTX */
29+
#include <openssl/crypto.h> /* for OpenSSL_version */
2930
#include <openssl/err.h> /* error reporting */
3031
#include <openssl/conf.h>
3132
#include <openssl/md4.h>
@@ -60,7 +61,7 @@ extern my_bool ma_tls_initialized;
6061
extern unsigned int mariadb_deinitialize_ssl;
6162

6263
#define MAX_SSL_ERR_LEN 100
63-
64+
char tls_library_version[TLS_VERSION_LENGTH];
6465
static pthread_mutex_t LOCK_openssl_config;
6566
#ifndef HAVE_OPENSSL_1_1_API
6667
static pthread_mutex_t *LOCK_crypto= NULL;
@@ -319,6 +320,13 @@ int ma_tls_start(char *errmsg __attribute__((unused)), size_t errmsg_len __attri
319320
ma_BIO_method.bwrite= ma_bio_write;
320321
#endif
321322
rc= 0;
323+
snprintf(tls_library_version, TLS_VERSION_LENGTH - 1, "%s",
324+
#if defined(LIBRESSL_VERSION_NUMBER) || !defined(HAVE_OPENSSL_1_1_API)
325+
SSLeay_version(SSLEAY_VERSION));
326+
#else
327+
OpenSSL_version(OPENSSL_VERSION));
328+
#endif
329+
322330
ma_tls_initialized= TRUE;
323331
end:
324332
pthread_mutex_unlock(&LOCK_openssl_config);

libmariadb/secure/schannel.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
#pragma comment (lib, "crypt32.lib")
2323
#pragma comment (lib, "secur32.lib")
24+
#pragma comment (lib, "version.lib")
2425

25-
//#define VOID void
2626

2727
extern my_bool ma_tls_initialized;
2828

@@ -31,6 +31,8 @@ extern my_bool ma_tls_initialized;
3131
#define PROT_TLS1_2 4
3232
#define PROT_TLS1_3 8
3333

34+
char tls_library_version[TLS_VERSION_LENGTH];
35+
3436
static struct
3537
{
3638
DWORD cipher_id;
@@ -161,7 +163,6 @@ cipher_map[] =
161163
#define MAX_ALG_ID 50
162164

163165
void ma_schannel_set_sec_error(MARIADB_PVIO *pvio, DWORD ErrorNo);
164-
void ma_schannel_set_win_error(MYSQL *mysql);
165166

166167
/*
167168
Initializes SSL and allocate global
@@ -176,7 +177,31 @@ void ma_schannel_set_win_error(MYSQL *mysql);
176177
*/
177178
int ma_tls_start(char *errmsg, size_t errmsg_len)
178179
{
180+
DWORD size;
181+
DWORD handle;
179182

183+
if ((size= GetFileVersionInfoSize("schannel.dll", &handle)))
184+
{
185+
LPBYTE VersionInfo;
186+
if ((VersionInfo = (LPBYTE)malloc(size)))
187+
{
188+
unsigned int len;
189+
VS_FIXEDFILEINFO *fileinfo;
190+
191+
GetFileVersionInfo("schannel.dll", 0, size, VersionInfo);
192+
VerQueryValue(VersionInfo, "\\", (LPVOID *)&fileinfo, &len);
193+
snprintf(tls_library_version, TLS_VERSION_LENGTH - 1, "Schannel %d.%d.%d.%d\n",
194+
HIWORD(fileinfo->dwFileVersionMS),
195+
LOWORD(fileinfo->dwFileVersionMS),
196+
HIWORD(fileinfo->dwFileVersionLS),
197+
LOWORD(fileinfo->dwFileVersionLS));
198+
free(VersionInfo);
199+
goto end;
200+
}
201+
}
202+
/* this shouldn't happen anyway */
203+
strcpy(tls_library_version, "Schannel 0.0.0.0");
204+
end:
180205
ma_tls_initialized = TRUE;
181206
return 0;
182207
}

0 commit comments

Comments
 (0)