@@ -36,13 +36,18 @@ PERFORMANCE OF THIS SOFTWARE.
36
36
#endif
37
37
38
38
#if ((MYSQL_VERSION_ID >= 50555 && MYSQL_VERSION_ID <= 50599 ) || \
39
- (MYSQL_VERSION_ID >= 50636 && MYSQL_VERSION_ID <= 50699 ) || \
40
- (MYSQL_VERSION_ID >= 50711 && MYSQL_VERSION_ID <= 50799 ) || \
41
- (MYSQL_VERSION_ID >= 80000 )) && \
42
- !defined(MARIADB_BASE_VERSION ) && !defined(MARIADB_VERSION_ID )
39
+ (MYSQL_VERSION_ID >= 50636 && MYSQL_VERSION_ID <= 50699 ) || \
40
+ (MYSQL_VERSION_ID >= 50711 && MYSQL_VERSION_ID <= 50799 ) || \
41
+ (MYSQL_VERSION_ID >= 80000 )) && \
42
+ !defined(MARIADB_BASE_VERSION ) && !defined(MARIADB_VERSION_ID )
43
43
#define HAVE_ENUM_MYSQL_OPT_SSL_MODE
44
44
#endif
45
45
46
+ #if defined(MARIADB_VERSION_ID ) && MARIADB_VERSION_ID >= 100403 || \
47
+ !defined(MARIADB_VERSION_ID ) && MYSQL_VERSION_ID >= 50723
48
+ #define HAVE_MYSQL_SERVER_PUBLIC_KEY
49
+ #endif
50
+
46
51
#define PY_SSIZE_T_CLEAN 1
47
52
#include "Python.h"
48
53
@@ -431,7 +436,7 @@ _mysql_ConnectionObject_Initialize(
431
436
"client_flag" , "ssl" , "ssl_mode" ,
432
437
"local_infile" ,
433
438
"read_timeout" , "write_timeout" , "charset" ,
434
- "auth_plugin" ,
439
+ "auth_plugin" , "server_public_key_path" ,
435
440
NULL } ;
436
441
int connect_timeout = 0 ;
437
442
int read_timeout = 0 ;
@@ -442,14 +447,15 @@ _mysql_ConnectionObject_Initialize(
442
447
* read_default_file = NULL ,
443
448
* read_default_group = NULL ,
444
449
* charset = NULL ,
445
- * auth_plugin = NULL ;
450
+ * auth_plugin = NULL ,
451
+ * server_public_key_path = NULL ;
446
452
447
453
self -> converter = NULL ;
448
454
self -> open = false;
449
455
self -> reconnect = false;
450
456
451
457
if (!PyArg_ParseTupleAndKeywords (args , kwargs ,
452
- "|ssssisOiiisssiOsiiiss :connect" ,
458
+ "|ssssisOiiisssiOsiiisss :connect" ,
453
459
kwlist ,
454
460
& host , & user , & passwd , & db ,
455
461
& port , & unix_socket , & conv ,
@@ -462,10 +468,19 @@ _mysql_ConnectionObject_Initialize(
462
468
& read_timeout ,
463
469
& write_timeout ,
464
470
& charset ,
465
- & auth_plugin
471
+ & auth_plugin ,
472
+ & server_public_key_path
466
473
))
467
474
return -1 ;
468
475
476
+ #ifndef HAVE_MYSQL_SERVER_PUBLIC_KEY
477
+ if (server_public_key_path ) {
478
+ PyErr_SetString (_mysql_NotSupportedError , "server_public_key_path is not supported" );
479
+ return -1 ;
480
+ }
481
+ #endif
482
+ // For compatibility with PyPy, we need to keep strong reference
483
+ // to unicode objects until we use UTF8.
469
484
#define _stringsuck (d ,t ,s ) {t=PyMapping_GetItemString(s,#d);\
470
485
if(t){d=PyUnicode_AsUTF8(t);ssl_keepref[n_ssl_keepref++]=t;}\
471
486
PyErr_Clear();}
@@ -542,6 +557,10 @@ _mysql_ConnectionObject_Initialize(
542
557
mysql_options (& (self -> connection ), MYSQL_OPT_SSL_CAPATH , capath );
543
558
mysql_options (& (self -> connection ), MYSQL_OPT_SSL_CIPHER , cipher );
544
559
}
560
+ for (int i = 0 ; i < n_ssl_keepref ; i ++ ) {
561
+ Py_DECREF (ssl_keepref [i ]);
562
+ ssl_keepref [i ] = NULL ;
563
+ }
545
564
546
565
#ifdef HAVE_ENUM_MYSQL_OPT_SSL_MODE
547
566
if (ssl_mode_set ) {
@@ -557,14 +576,14 @@ _mysql_ConnectionObject_Initialize(
557
576
my_bool my_true = 1 ;
558
577
my_bool my_false = 0 ;
559
578
if (ssl_mode_num >= SSLMODE_REQUIRED ) {
560
- mysql_optionsv (& (self -> connection ), MYSQL_OPT_SSL_ENFORCE , (void * )& my_true );
579
+ mysql_options (& (self -> connection ), MYSQL_OPT_SSL_ENFORCE , (void * )& my_true );
561
580
} else {
562
- mysql_optionsv (& (self -> connection ), MYSQL_OPT_SSL_ENFORCE , (void * )& my_false );
581
+ mysql_options (& (self -> connection ), MYSQL_OPT_SSL_ENFORCE , (void * )& my_false );
563
582
}
564
583
if (ssl_mode_num >= SSLMODE_VERIFY_CA ) {
565
- mysql_optionsv (& (self -> connection ), MYSQL_OPT_SSL_VERIFY_SERVER_CERT , (void * )& my_true );
584
+ mysql_options (& (self -> connection ), MYSQL_OPT_SSL_VERIFY_SERVER_CERT , (void * )& my_true );
566
585
} else {
567
- mysql_optionsv (& (self -> connection ), MYSQL_OPT_SSL_VERIFY_SERVER_CERT , (void * )& my_false );
586
+ mysql_options (& (self -> connection ), MYSQL_OPT_SSL_VERIFY_SERVER_CERT , (void * )& my_false );
568
587
}
569
588
#endif
570
589
@@ -574,17 +593,17 @@ _mysql_ConnectionObject_Initialize(
574
593
if (auth_plugin ) {
575
594
mysql_options (& (self -> connection ), MYSQL_DEFAULT_AUTH , auth_plugin );
576
595
}
596
+ #ifdef HAVE_MYSQL_SERVER_PUBLIC_KEY
597
+ if (server_public_key_path ) {
598
+ mysql_options (& (self -> connection ), MYSQL_SERVER_PUBLIC_KEY , server_public_key_path );
599
+ }
600
+ #endif
577
601
578
602
Py_BEGIN_ALLOW_THREADS
579
603
conn = mysql_real_connect (& (self -> connection ), host , user , passwd , db ,
580
604
port , unix_socket , client_flag );
581
605
Py_END_ALLOW_THREADS
582
606
583
- for (int i = 0 ; i < n_ssl_keepref ; i ++ ) {
584
- Py_DECREF (ssl_keepref [i ]);
585
- ssl_keepref [i ] = NULL ;
586
- }
587
-
588
607
if (!conn ) {
589
608
_mysql_Exception (self );
590
609
return -1 ;
0 commit comments