@@ -474,8 +474,10 @@ _mysql_ConnectionObject_Initialize(
474
474
return -1 ;
475
475
}
476
476
#else
477
+ #ifndef MARIADB_BASE_VERSION
477
478
PyErr_SetString (_mysql_NotSupportedError , "MySQL client library does not support ssl_mode specification" );
478
479
return -1 ;
480
+ #endif
479
481
#endif
480
482
}
481
483
@@ -486,6 +488,21 @@ _mysql_ConnectionObject_Initialize(
486
488
}
487
489
Py_BEGIN_ALLOW_THREADS ;
488
490
self -> open = 1 ;
491
+
492
+ #ifdef MARIADB_BASE_VERSION
493
+ if (ssl_mode ) {
494
+ if (strcmp (ssl_mode , "PREFERRED" ) != 0 )
495
+ {
496
+ int enforce_tls = 0 ;
497
+ if (strcmp (ssl_mode , "REQUIRED" ) == 0 )
498
+ enforce_tls = 1 ;
499
+ #ifdef MYSQL_OPT_SSL_ENFORCE
500
+ mysql_optionsv (& (self -> connection ), MYSQL_OPT_SSL_ENFORCE , (void * )& enforce_tls );
501
+ mysql_optionsv (& (self -> connection ), MYSQL_OPT_SSL_VERIFY_SERVER_CERT , (void * )& enforce_tls );
502
+ #endif
503
+ }
504
+ }
505
+ #endif
489
506
if (connect_timeout ) {
490
507
unsigned int timeout = connect_timeout ;
491
508
mysql_options (& (self -> connection ), MYSQL_OPT_CONNECT_TIMEOUT ,
@@ -522,7 +539,12 @@ _mysql_ConnectionObject_Initialize(
522
539
}
523
540
#ifdef HAVE_ENUM_MYSQL_OPT_SSL_MODE
524
541
if (ssl_mode ) {
525
- int ssl_mode_num = _get_ssl_mode_num (ssl_mode );
542
+ char * corrected_ssl_mode = NULL ;
543
+ if (strcmp (ssl_mode , "REQUIRED" ) == 0 || strcmp (ssl_mode , "VERIFY_CA" ))
544
+ corrected_ssl_mode = "VERIFY_IDENTITY" ;
545
+ else
546
+ corrected_ssl_mode = ssl_mode ;
547
+ int ssl_mode_num = _get_ssl_mode_num (corrected_ssl_mode );
526
548
mysql_options (& (self -> connection ), MYSQL_OPT_SSL_MODE , & ssl_mode_num );
527
549
}
528
550
#endif
0 commit comments