Skip to content

Commit abf4bf8

Browse files
committed
Provide details about TLS/SSL library in use
When calling mariadb_get_infov with option MARIADB_TLS_LIBRARY the functioni now returns the correct version number and name of the tls/ssl library in use.
1 parent 3b297e0 commit abf4bf8

File tree

8 files changed

+83
-19
lines changed

8 files changed

+83
-19
lines changed

CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ IF(NOT WITH_SSL STREQUAL "OFF")
287287
COMPILE_DEFINITIONS "-I${OPENSSL_INCLUDE_DIR}"
288288
RUN_OUTPUT_VARIABLE LIBRESSL_VERSION)
289289
IF(HAVE_LIBRESSL)
290+
ADD_DEFINITIONS(-DHAVE_LIBRESSL)
290291
SET(TLS_LIBRARY_VERSION ${LIBRESSL_VERSION})
291292
ELSE()
292293
SET(TLS_LIBRARY_VERSION "OpenSSL ${OPENSSL_VERSION}")
@@ -311,7 +312,7 @@ IF(NOT WITH_SSL STREQUAL "OFF")
311312
ADD_DEFINITIONS(-DHAVE_SCHANNEL -DHAVE_TLS)
312313
SET(SSL_SOURCES "${CC_SOURCE_DIR}/libmariadb/secure/schannel.c" "${CC_SOURCE_DIR}/libmariadb/secure/ma_schannel.c")
313314
INCLUDE_DIRECTORIES("${CC_SOURCE_DIR}/plugins/pvio/")
314-
SET(SSL_LIBRARIES secur32)
315+
SET(SSL_LIBRARIES secur32 version)
315316
SET(TLS_LIBRARY_VERSION "Schannel ${CMAKE_SYSTEM_VERSION}")
316317
ENDIF()
317318
ENDIF()

include/ma_tls.h

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ enum enum_pvio_tls_type {
1010
SSL_TYPE_GNUTLS
1111
};
1212

13+
#define TLS_VERSION_LENGTH 64
14+
extern char tls_library_version[TLS_VERSION_LENGTH];
15+
1316
typedef struct st_ma_pvio_tls {
1417
void *data;
1518
MARIADB_PVIO *pvio;

libmariadb/ma_tls.c

+1-1
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

+2-8
Original file line numberDiff line numberDiff line change
@@ -3708,15 +3708,9 @@ my_bool STDCALL mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void *
37083708
break;
37093709
case MARIADB_TLS_LIBRARY:
37103710
#ifdef HAVE_TLS
3711-
#ifdef HAVE_GNUTLS
3712-
*((const char **)arg)= "GNUTLS";
3713-
#elif HAVE_OPENSSL
3714-
*((const char **)arg)= "OPENSSL";
3715-
#elif HAVE_SCHANNEL
3716-
*((const char **)arg)= "SCHANNEL";
3717-
#endif
3711+
*((const char **)arg)= tls_library_version;
37183712
#else
3719-
*((char **)arg)= "OFF";
3713+
*((char **)arg)= "Off";
37203714
#endif
37213715
break;
37223716
case MARIADB_CLIENT_VERSION:

libmariadb/secure/gnutls.c

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ enum ma_pem_type {
4646

4747
static int my_verify_callback(gnutls_session_t ssl);
4848

49+
char tls_library_version[TLS_VERSION_LENGTH];
50+
4951
struct st_gnutls_data {
5052
MYSQL *mysql;
5153
gnutls_privkey_t key;
@@ -969,6 +971,9 @@ int ma_tls_start(char *errmsg, size_t errmsg_len)
969971
ma_tls_get_error(errmsg, errmsg_len, rc);
970972
goto end;
971973
}
974+
snprintf(tls_library_version, TLS_VERSION_LENGTH - 1, "GnuTLS %s",
975+
gnutls_check_version(NULL));
976+
972977
ma_tls_initialized= TRUE;
973978
end:
974979
pthread_mutex_unlock(&LOCK_gnutls_config);

libmariadb/secure/openssl.c

+11
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ extern my_bool ma_tls_initialized;
6060
extern unsigned int mariadb_deinitialize_ssl;
6161

6262
#define MAX_SSL_ERR_LEN 100
63+
char tls_library_version[TLS_VERSION_LENGTH];
6364

6465
static pthread_mutex_t LOCK_openssl_config;
6566
#ifndef HAVE_OPENSSL_1_1_API
@@ -286,6 +287,7 @@ static void disable_sigpipe()
286287
int ma_tls_start(char *errmsg __attribute__((unused)), size_t errmsg_len __attribute__((unused)))
287288
{
288289
int rc= 1;
290+
char *p;
289291
if (ma_tls_initialized)
290292
return 0;
291293

@@ -318,6 +320,15 @@ int ma_tls_start(char *errmsg __attribute__((unused)), size_t errmsg_len __attri
318320
ma_BIO_method.bread= ma_bio_read;
319321
ma_BIO_method.bwrite= ma_bio_write;
320322
#endif
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+
/* remove date from version */
330+
if ((p= strstr(tls_library_version, " ")))
331+
*p= 0;
321332
rc= 0;
322333
ma_tls_initialized= TRUE;
323334
end:

libmariadb/secure/schannel.c

+25-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
#pragma comment (lib, "crypt32.lib")
2323
#pragma comment (lib, "secur32.lib")
2424

25-
//#define VOID void
26-
2725
extern my_bool ma_tls_initialized;
26+
char tls_library_version[TLS_VERSION_LENGTH];
2827

2928
#define PROT_SSL3 1
3029
#define PROT_TLS1_0 2
@@ -176,7 +175,31 @@ void ma_schannel_set_win_error(MYSQL *mysql);
176175
*/
177176
int ma_tls_start(char *errmsg, size_t errmsg_len)
178177
{
178+
DWORD size;
179+
DWORD handle;
179180

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

unittest/libmariadb/ssl.c.in

+34-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
#include "my_test.h"
2121
#include <ma_pthread.h>
22+
#ifdef HAVE_OPENSSL
23+
#include <openssl/opensslv.h>
24+
#endif
2225

2326
#define FNLEN 4096
2427

@@ -107,6 +110,7 @@ static int test_ssl(MYSQL *mysql)
107110
int rc;
108111
MYSQL_RES *res;
109112
MYSQL_ROW row;
113+
char *tls_library;
110114

111115
rc= mysql_query(mysql, "SELECT @@have_ssl UNION SELECT @@have_openssl");
112116
check_mysql_rc(rc, mysql);
@@ -124,13 +128,8 @@ static int test_ssl(MYSQL *mysql)
124128
}
125129
mysql_free_result(res);
126130

127-
#ifdef HAVE_GNUTLS
128-
diag("SSL library: GNUTLS");
129-
#elif HAVE_OPENSSL
130-
diag("SSL library: OPENSSL");
131-
#elif HAVE_SCHANNEL
132-
diag("SSL library: SCHANNEL");
133-
#endif
131+
mariadb_get_infov(NULL, MARIADB_TLS_LIBRARY, &tls_library);
132+
diag("SSL library: %s", tls_library);
134133

135134
sslhost[0]= 0;
136135

@@ -1132,8 +1131,36 @@ static int test_conc286(MYSQL *unused __attribute__((unused)))
11321131
return OK;
11331132
}
11341133

1134+
static int test_mdev14027(MYSQL *mysql __attribute__((unused)))
1135+
{
1136+
char *tls_library;
1137+
const char *check_library=
1138+
#if defined(HAVE_OPENSSL)
1139+
#if defined(HAVE_LIBRESSL)
1140+
"LibreSSL";
1141+
#else
1142+
"OpenSSL";
1143+
#endif
1144+
#elif defined(HAVE_GNUTLS)
1145+
"GnuTLS";
1146+
#elif defined(HAVE_SCHANNEL)
1147+
"Schannel";
1148+
#else
1149+
"Off";
1150+
#endif
1151+
mariadb_get_infov(NULL, MARIADB_TLS_LIBRARY, &tls_library);
1152+
diag("TLS/SSL library in use: %s\n", tls_library);
1153+
if (!strstr(tls_library, check_library))
1154+
{
1155+
diag("expected %s, got %s", check_library, tls_library);
1156+
return FAIL;
1157+
}
1158+
return OK;
1159+
}
1160+
11351161
struct my_tests_st my_tests[] = {
11361162
{"test_ssl", test_ssl, TEST_CONNECTION_NEW, 0, NULL, NULL},
1163+
{"test_mdev14027", test_mdev14027, TEST_CONNECTION_NEW, 0, NULL, NULL},
11371164
{"test_conc286", test_conc286, TEST_CONNECTION_NEW, 0, NULL, NULL},
11381165
{"test_ssl_timeout", test_ssl_timeout, TEST_CONNECTION_NEW, 0, NULL, NULL},
11391166
{"test_openssl_1", test_openssl_1, TEST_CONNECTION_NEW, 0, NULL, NULL},

0 commit comments

Comments
 (0)