@@ -1006,17 +1006,46 @@ void ma_tls_end()
1006
1006
return ;
1007
1007
}
1008
1008
1009
- static int ma_gnutls_set_ciphers (gnutls_session_t ssl , char * cipher_str )
1009
+ static size_t ma_gnutls_get_protocol_version (const char * tls_version_option ,
1010
+ char * priority_string ,
1011
+ size_t prio_len )
1012
+ {
1013
+ char tls_versions [128 ];
1014
+
1015
+ tls_versions [0 ]= 0 ;
1016
+ if (!tls_version_option || !tls_version_option [0 ])
1017
+ goto end ;
1018
+
1019
+
1020
+ if (strstr (tls_version_option , "TLSv1.0" ))
1021
+ strcat (tls_versions , ":+VERS-TLS1.0" );
1022
+ if (strstr (tls_version_option , "TLSv1.1" ))
1023
+ strcat (tls_versions , ":+VERS-TLS1.1" );
1024
+ if (strstr (tls_version_option , "TLSv1.2" ))
1025
+ strcat (tls_versions , ":+VERS-TLS1.2" );
1026
+ end :
1027
+ if (tls_versions [0 ])
1028
+ snprintf (priority_string , prio_len - 1 , "NORMAL:-VERS-TLS-ALL%s" , tls_versions );
1029
+ else
1030
+ strncpy (priority_string , "NORMAL" , prio_len - 1 );
1031
+ return strlen (priority_string );
1032
+ }
1033
+
1034
+ static int ma_gnutls_set_ciphers (gnutls_session_t ssl ,
1035
+ const char * cipher_str ,
1036
+ const char * tls_version )
1010
1037
{
1011
1038
const char * err ;
1012
1039
char * token ;
1013
- #define PRIO_SIZE 1024
1040
+ #define PRIO_SIZE 1024
1014
1041
char prio [PRIO_SIZE ];
1015
1042
1043
+ ma_gnutls_get_protocol_version (tls_version , prio , PRIO_SIZE );
1044
+
1016
1045
if (!cipher_str )
1017
- return gnutls_priority_set_direct (ssl , "NORMAL" , & err );
1046
+ return gnutls_priority_set_direct (ssl , prio , & err );
1018
1047
1019
- token = strtok (cipher_str , ":" );
1048
+ token = strtok (( char * ) cipher_str , ":" );
1020
1049
1021
1050
strcpy (prio , "NONE:+VERS-TLS-ALL:+SIGN-ALL:+COMP-NULL" );
1022
1051
@@ -1180,7 +1209,7 @@ void *ma_tls_init(MYSQL *mysql)
1180
1209
/*
1181
1210
gnutls_certificate_set_retrieve_function2(GNUTLS_xcred, client_cert_callback);
1182
1211
*/
1183
- ssl_error = ma_gnutls_set_ciphers (ssl , mysql -> options .ssl_cipher );
1212
+ ssl_error = ma_gnutls_set_ciphers (ssl , mysql -> options .ssl_cipher , mysql -> options . extension ? mysql -> options . extension -> tls_version : NULL );
1184
1213
if (ssl_error < 0 )
1185
1214
goto error ;
1186
1215
@@ -1427,19 +1456,17 @@ unsigned int ma_tls_get_finger_print(MARIADB_TLS *ctls, char *fp, unsigned int l
1427
1456
else
1428
1457
{
1429
1458
my_set_error (mysql , CR_SSL_CONNECTION_ERROR , SQLSTATE_UNKNOWN ,
1430
- ER (CR_SSL_CONNECTION_ERROR ),
1459
+ ER (CR_SSL_CONNECTION_ERROR ),
1431
1460
"Finger print buffer too small" );
1432
1461
return 0 ;
1433
1462
}
1434
1463
}
1435
1464
1436
- my_bool ma_tls_get_protocol_version (MARIADB_TLS * ctls , struct st_ssl_version * version )
1465
+ int ma_tls_get_protocol_version (MARIADB_TLS * ctls )
1437
1466
{
1438
1467
if (!ctls || !ctls -> ssl )
1439
1468
return 1 ;
1440
1469
1441
- version -> iversion = gnutls_protocol_get_version (ctls -> ssl );
1442
- version -> cversion = (char * )gnutls_protocol_get_name (version -> iversion );
1443
- return 0 ;
1470
+ return gnutls_protocol_get_version (ctls -> ssl ) - 1 ;
1444
1471
}
1445
1472
#endif /* HAVE_GNUTLS */
0 commit comments