Skip to content

Commit 23895fb

Browse files
committed
Fixed gnutls support
1 parent f2955a4 commit 23895fb

File tree

17 files changed

+391
-197
lines changed

17 files changed

+391
-197
lines changed

CMakeLists.txt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ IF(WITH_SSL STREQUAL "OPENSSL")
152152
FIND_PACKAGE(OpenSSL)
153153
IF(OPENSSL_FOUND)
154154
ADD_DEFINITIONS(-DHAVE_OPENSSL -DHAVE_SSL)
155-
ADD_DEFINITIONS(-DSSL_PLUGIN=cio_openssl_plugin)
156-
SET(SSL_SOURCES "${CMAKE_SOURCE_DIR}/plugins/builtin/cio_openssl.c")
155+
SET(SSL_SOURCES "${CMAKE_SOURCE_DIR}/libmariadb/secure/openssl.c")
157156
SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARIES})
158157
ELSE()
159158
MESSAGE(FATAL "OpenSSL not found")
@@ -162,24 +161,23 @@ ENDIF()
162161
IF(WITH_SSL STREQUAL "GNUTLS")
163162
FIND_PACKAGE(GnuTLS)
164163
IF(GNUTLS_FOUND)
165-
ADD_DEFINITIONS(-DSSL_PLUGIN=cio_gnutls_plugin)
166164
ADD_DEFINITIONS(-DHAVE_GNUTLS -DHAVE_SSL)
167-
SET(SSL_SOURCES "${CMAKE_SOURCE_DIR}/plugins/builtin/cio_gnutls.c")
168-
SET(SSL_LIBRARIES ${GNUTLS_LIBRARIES})
165+
SET(SSL_SOURCES "${CMAKE_SOURCE_DIR}/libmariadb/secure/gnutls.c")
166+
SET(SSL_LIBRARIES ${GNUTLS_LIBRARY})
169167
ELSE()
170168
MESSAGE(FATAL "GnuTLS not found")
171169
ENDIF()
172170
ENDIF()
173171
IF(WIN32)
174172
IF(WITH_SSL STREQUAL "SCHANNEL")
175-
ADD_DEFINITIONS(-DSSL_PLUGIN=cio_schannel_plugin)
176173
MESSAGE(STATUS "SSL_TYPE ${SSL_TYPE}")
177174
ADD_DEFINITIONS(-DHAVE_SCHANNEL -DHAVE_SSL)
178-
SET(SSL_SOURCES "${CMAKE_SOURCE_DIR}/plugins/builtin/cio_schannel.c" "${CMAKE_SOURCE_DIR}/plugins/builtin/ma_schannel.c")
175+
SET(SSL_SOURCES "${CMAKE_SOURCE_DIR}/libmariadb/secure/schannel.c" "${CMAKE_SOURCE_DIR}/libmariadb/secure/ma_schannel.c")
179176
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/plugins/cio/")
180177
ENDIF()
181178
ENDIF()
182179

180+
MARK_AS_ADVANCED(SSL_SOURCES)
183181

184182

185183
IF(WITH_SQLITE)
@@ -206,7 +204,7 @@ IF(WIN32)
206204
ELSE()
207205
SET(SYSTEM_LIBS ${LIBPTHREAD} ${LIBDL} ${LIBM} ${LIBICONV})
208206
ENDIF()
209-
IF(OPENSSL_FOUND)
207+
IF(WITH_SSL)
210208
SET(SYSTEM_LIBS ${SYSTEM_LIBS} ${SSL_LIBRARIES})
211209
ENDIF()
212210

@@ -291,7 +289,7 @@ MESSAGE(STATUS "CPack generation: ${CPACK_GENERATOR}")
291289
IF(CLIENT_DOCS)
292290
MESSAGE(STATUS "Documentation included from ${CLIENT_DOCS}")
293291
ENDIF()
294-
MESSAGE(STATUS "SSL support: ${WITH_SSL} Sources: ${SSL_SOURCES}")
292+
MESSAGE(STATUS "SSL support: ${WITH_SSL} Libs: ${SSL_LIBRARIES}")
295293
MESSAGE(STATUS "Experimental Sqlite support: ${WITH_SQLITE}")
296294
IF(WITH_EXTERNAL_ZLIB)
297295
MESSAGE(STATUS "Zlib support: ${WITH_EXTERNAL_ZLIB}")

include/ma_ssl.h

Lines changed: 108 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#ifndef _ma_ssl_h_
22
#define _ma_ssl_h_
33

4-
struct st_ma_cio_ssl_methods;
5-
typedef struct st_ma_cio_ssl_methods CIO_SSL_METHODS;
6-
extern int ssl_default_plugin;
7-
84
enum enum_cio_ssl_type {
95
SSL_TYPE_DEFAULT=0,
106
#ifdef _WIN32
@@ -16,23 +12,117 @@ enum enum_cio_ssl_type {
1612

1713
typedef struct st_ma_cio_ssl {
1814
void *data;
19-
enum enum_cio_ssl_type type;
2015
MARIADB_CIO *cio;
21-
CIO_SSL_METHODS *methods;
2216
void *ssl;
2317
} MARIADB_SSL;
2418

25-
struct st_ma_cio_ssl_methods
26-
{
27-
void *(*init)(MARIADB_SSL *cssl, MYSQL *mysql);
28-
my_bool (*connect)(MARIADB_SSL *cssl);
29-
size_t (*read)(MARIADB_SSL *cssl, const uchar* buffer, size_t length);
30-
size_t (*write)(MARIADB_SSL *cssl, const uchar* buffer, size_t length);
31-
my_bool (*close)(MARIADB_SSL *cssl);
32-
int (*verify_server_cert)(MARIADB_SSL *ssl);
33-
const char *(*cipher)(MARIADB_SSL *ssl);
34-
my_bool (*check_fp)(MARIADB_SSL *cssl, const char *fp);
35-
};
19+
/* Function prototypes */
20+
21+
/* ma_ssl_start
22+
initializes the ssl library
23+
Parameter:
24+
errmsg pointer to error message buffer
25+
errmsg_len length of error message buffer
26+
Returns:
27+
0 success
28+
1 if an error occured
29+
Notes:
30+
On success the global variable ma_ssl_initialized will be set to 1
31+
*/
32+
int ma_ssl_start(char *errmsg, size_t errmsg_len);
33+
34+
/* ma_ssl_end
35+
unloads/deinitializes ssl library and unsets global variable
36+
ma_ssl_initialized
37+
*/
38+
void ma_ssl_end(void);
39+
40+
/* ma_ssl_init
41+
creates a new SSL structure for a SSL connection and loads
42+
client certificates
43+
44+
Parameters:
45+
MYSQL a mysql structure
46+
Returns:
47+
void * a pointer to internal SSL structure
48+
*/
49+
void * ma_ssl_init(MYSQL *mysql);
50+
51+
/* ma_ssl_connect
52+
performs SSL handshake
53+
Parameters:
54+
MARIADB_SSL MariaDB SSL container
55+
Returns:
56+
0 success
57+
1 error
58+
*/
59+
my_bool ma_ssl_connect(MARIADB_SSL *cssl);
60+
61+
/* ma_ssl_read
62+
reads up to length bytes from socket
63+
Parameters:
64+
cssl MariaDB SSL container
65+
buffer read buffer
66+
length buffer length
67+
Returns:
68+
0-n bytes read
69+
-1 if an error occured
70+
*/
71+
size_t ma_ssl_read(MARIADB_SSL *cssl, const uchar* buffer, size_t length);
72+
73+
/* ma_ssl_write
74+
write buffer to socket
75+
Parameters:
76+
cssl MariaDB SSL container
77+
buffer write buffer
78+
length buffer length
79+
Returns:
80+
0-n bytes written
81+
-1 if an error occured
82+
*/
83+
size_t ma_ssl_write(MARIADB_SSL *cssl, const uchar* buffer, size_t length);
84+
85+
/* ma_ssl_close
86+
closes SSL connection and frees SSL structure which was previously
87+
created by ma_ssl_init call
88+
Parameters:
89+
MARIADB_SSL MariaDB SSL container
90+
Returns:
91+
0 success
92+
1 error
93+
*/
94+
my_bool ma_ssl_close(MARIADB_SSL *cssl);
95+
96+
/* ma_ssl_verify_server_cert
97+
validation check of server certificate
98+
Parameter:
99+
MARIADB_SSL MariaDB SSL container
100+
Returns:
101+
ß success
102+
1 error
103+
*/
104+
int ma_ssl_verify_server_cert(MARIADB_SSL *cssl);
105+
106+
/* ma_ssl_get_cipher
107+
returns cipher for current ssl connection
108+
Parameter:
109+
MARIADB_SSL MariaDB SSL container
110+
Returns:
111+
cipher in use or
112+
NULL on error
113+
*/
114+
const char *ma_ssl_get_cipher(MARIADB_SSL *ssl);
115+
116+
/* ma_ssl_get_finger_print
117+
returns SHA1 finger print of server certificate
118+
Parameter:
119+
MARIADB_SSL MariaDB SSL container
120+
fp buffer for fingerprint
121+
fp_len buffer length
122+
Returns:
123+
actual size of finger print
124+
*/
125+
unsigned int ma_ssl_get_finger_print(MARIADB_SSL *cssl, unsigned char *fp, unsigned int fp_len);
36126

37127
/* Function prototypes */
38128
MARIADB_SSL *ma_cio_ssl_init(MYSQL *mysql);
@@ -42,6 +132,6 @@ size_t ma_cio_ssl_write(MARIADB_SSL *cssl, const uchar *buffer, size_t length);
42132
my_bool ma_cio_ssl_close(MARIADB_SSL *cssl);
43133
int ma_cio_ssl_verify_server_cert(MARIADB_SSL *cssl);
44134
const char *ma_cio_ssl_cipher(MARIADB_SSL *cssl);
45-
my_bool ma_cio_ssl_check_fp(MARIADB_SSL *cssl, const char *fp, size_t length);
135+
my_bool ma_cio_ssl_check_fp(MARIADB_SSL *cssl, const char *fp, const char *fp_list);
46136

47137
#endif /* _ma_ssl_h_ */

libmariadb/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,10 @@ client_plugin.c
325325
ma_io.c
326326
${CMAKE_SOURCE_DIR}/plugins/builtin/my_auth.c
327327
${CMAKE_SOURCE_DIR}/plugins/builtin/cio_socket.c
328+
${SSL_SOURCES}
328329
)
329330

330-
IF(SSL_SOURCES)
331-
SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES} ${SSL_SOURCES})
332-
ENDIF()
331+
MESSAGE(STATUS "${LIBMARIADB_SOURCES}")
333332

334333
IF(WIN32)
335334
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/win-iconv)

libmariadb/client_plugin.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,12 @@ extern struct st_mysql_client_plugin old_password_client_plugin;
8484
extern struct st_mysql_client_plugin native_password_client_plugin;
8585

8686
extern MARIADB_CIO_PLUGIN cio_socket_plugin;
87-
#ifdef HAVE_SSL
88-
extern MARIADB_CIO_PLUGIN SSL_PLUGIN;
89-
#endif
9087

9188
struct st_mysql_client_plugin *mysql_client_builtins[]=
9289
{
9390
(struct st_mysql_client_plugin *)&old_password_client_plugin,
9491
(struct st_mysql_client_plugin *)&native_password_client_plugin,
9592
(struct st_mysql_client_plugin *)&cio_socket_plugin,
96-
#ifdef HAVE_SSL
97-
(struct st_mysql_client_plugin *)&SSL_PLUGIN,
98-
#endif
9993
0
10094
};
10195

libmariadb/libmariadb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@
6262
#define INADDR_NONE -1
6363
#endif
6464
#include <sha1.h>
65-
#include <ma_cio.h>
6665
#ifndef _WIN32
6766
#include <poll.h>
6867
#endif
68+
#include <ma_cio.h>
6969
#include <ma_dyncol.h>
7070

7171
#define ASYNC_CONTEXT_DEFAULT_STACK_SIZE (4096*15)

libmariadb/ma_cio.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ MARIADB_CIO *ma_cio_init(MA_CIO_CINFO *cinfo)
116116
cio->methods->set_timeout(cio, CIO_WRITE_TIMEOUT, cinfo->mysql->options.write_timeout);
117117
}
118118

119-
if (!(cio->cache= my_malloc(CIO_READ_AHEAD_CACHE_SIZE, MYF(MY_WME))))
119+
if (!(cio->cache= my_malloc(CIO_READ_AHEAD_CACHE_SIZE, MYF(MY_ZEROFILL))))
120120
{
121121
CIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0);
122122
return NULL;
@@ -405,7 +405,9 @@ my_bool ma_cio_start_ssl(MARIADB_CIO *cio)
405405
return 1;
406406
CLEAR_CLIENT_ERROR(cio->mysql);
407407
if (!(cio->cssl= ma_cio_ssl_init(cio->mysql)))
408+
{
408409
return 1;
410+
}
409411
if (ma_cio_ssl_connect(cio->cssl))
410412
{
411413
my_free((gptr)cio->cssl);
@@ -417,6 +419,16 @@ my_bool ma_cio_start_ssl(MARIADB_CIO *cio)
417419
ma_cio_ssl_verify_server_cert(cio->cssl))
418420
return 1;
419421

422+
if (cio->mysql->options.extension &&
423+
(cio->mysql->options.extension->ssl_fp || cio->mysql->options.extension->ssl_fp_list))
424+
{
425+
426+
if (ma_cio_ssl_check_fp(cio->cssl,
427+
cio->mysql->options.extension->ssl_fp,
428+
cio->mysql->options.extension->ssl_fp_list))
429+
return 1;
430+
}
431+
420432
return 0;
421433
}
422434
/* }}} */

0 commit comments

Comments
 (0)