Skip to content

Commit 89511ee

Browse files
authored
windows: use DEFAULT_SSL_VERIFY_SERVER_CERT=0 option (#731)
1 parent 6eb6c2f commit 89511ee

File tree

2 files changed

+44
-23
lines changed

2 files changed

+44
-23
lines changed

.github/workflows/windows.yaml

+21-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
uses: actions/cache@v4
1818
with:
1919
path: c:/mariadb-connector
20-
key: mariadb-connector-c-${{ env.CONNECTOR_VERSION }}-win
20+
key: mariadb-connector-c-${{ env.CONNECTOR_VERSION }}-win-2
2121

2222
- name: Download and Unzip Connector
2323
if: steps.cache-connector.outputs.cache-hit != 'true'
@@ -27,15 +27,32 @@ jobs:
2727
unzip "mariadb-connector-c-${CONNECTOR_VERSION}-src.zip" -d c:/
2828
mv "c:/mariadb-connector-c-${CONNECTOR_VERSION}-src" c:/mariadb-connector-src
2929
30-
- name: Build Connector
30+
- name: make build directory
3131
if: steps.cache-connector.outputs.cache-hit != 'true'
3232
shell: cmd
3333
working-directory: c:/mariadb-connector-src
3434
run: |
3535
mkdir build
36-
cd build
37-
cmake -A x64 .. -DCMAKE_BUILD_TYPE=Release -DCLIENT_PLUGIN_DIALOG=static -DCLIENT_PLUGIN_SHA256_PASSWORD=static -DCLIENT_PLUGIN_CACHING_SHA2_PASSWORD=static
36+
37+
- name: cmake
38+
if: steps.cache-connector.outputs.cache-hit != 'true'
39+
shell: cmd
40+
working-directory: c:/mariadb-connector-src/build
41+
run: |
42+
cmake -A x64 .. -DCMAKE_BUILD_TYPE=Release -DCLIENT_PLUGIN_DIALOG=static -DCLIENT_PLUGIN_SHA256_PASSWORD=static -DCLIENT_PLUGIN_CACHING_SHA2_PASSWORD=static -DDEFAULT_SSL_VERIFY_SERVER_CERT=0
43+
44+
- name: cmake build
45+
if: steps.cache-connector.outputs.cache-hit != 'true'
46+
shell: cmd
47+
working-directory: c:/mariadb-connector-src/build
48+
run: |
3849
cmake --build . -j 8 --config Release
50+
51+
- name: cmake install
52+
if: steps.cache-connector.outputs.cache-hit != 'true'
53+
shell: cmd
54+
working-directory: c:/mariadb-connector-src/build
55+
run: |
3956
cmake -DCMAKE_INSTALL_PREFIX=c:/mariadb-connector -DCMAKE_INSTALL_COMPONENT=Development -DCMAKE_BUILD_TYPE=Release -P cmake_install.cmake
4057
4158
- name: Checkout mysqlclient

src/MySQLdb/_mysql.c

+23-19
Original file line numberDiff line numberDiff line change
@@ -543,23 +543,30 @@ _mysql_ConnectionObject_Initialize(
543543
mysql_options(&(self->connection), MYSQL_OPT_SSL_CIPHER, cipher);
544544
}
545545

546-
if (ssl_mode_set) {
547546
#ifdef HAVE_ENUM_MYSQL_OPT_SSL_MODE
547+
if (ssl_mode_set) {
548548
mysql_options(&(self->connection), MYSQL_OPT_SSL_MODE, &ssl_mode_num);
549+
}
549550
#else
550-
// MariaDB doesn't support MYSQL_OPT_SSL_MODE.
551-
// See https://github.com/PyMySQL/mysqlclient/issues/474
552-
// TODO: Does MariaDB supports PREFERRED and VERIFY_CA?
553-
// We support only two levels for now.
554-
my_bool enforce_tls = 1;
555-
if (ssl_mode_num >= SSLMODE_REQUIRED) {
556-
mysql_optionsv(&(self->connection), MYSQL_OPT_SSL_ENFORCE, (void *)&enforce_tls);
557-
}
558-
if (ssl_mode_num >= SSLMODE_VERIFY_CA) {
559-
mysql_optionsv(&(self->connection), MYSQL_OPT_SSL_VERIFY_SERVER_CERT, (void *)&enforce_tls);
560-
}
561-
#endif
551+
// MariaDB doesn't support MYSQL_OPT_SSL_MODE.
552+
// See https://github.com/PyMySQL/mysqlclient/issues/474
553+
// And MariDB 11.4 changed the default value of MYSQL_OPT_SSL_ENFORCE and
554+
// MYSQL_OPT_SSL_VERIFY_SERVER_CERT to 1.
555+
// https://github.com/mariadb-corporation/mariadb-connector-c/commit/8dffd56936df3d03eeccf47904773860a0cdeb57
556+
// We emulate the ssl_mode and old behavior.
557+
my_bool my_true = 1;
558+
my_bool my_false = 0;
559+
if (ssl_mode_num >= SSLMODE_REQUIRED) {
560+
mysql_optionsv(&(self->connection), MYSQL_OPT_SSL_ENFORCE, (void *)&my_true);
561+
} else {
562+
mysql_optionsv(&(self->connection), MYSQL_OPT_SSL_ENFORCE, (void *)&my_false);
563+
}
564+
if (ssl_mode_num >= SSLMODE_VERIFY_CA) {
565+
mysql_optionsv(&(self->connection), MYSQL_OPT_SSL_VERIFY_SERVER_CERT, (void *)&my_true);
566+
} else {
567+
mysql_optionsv(&(self->connection), MYSQL_OPT_SSL_VERIFY_SERVER_CERT, (void *)&my_false);
562568
}
569+
#endif
563570

564571
if (charset) {
565572
mysql_options(&(self->connection), MYSQL_SET_CHARSET_NAME, charset);
@@ -573,12 +580,9 @@ _mysql_ConnectionObject_Initialize(
573580
port, unix_socket, client_flag);
574581
Py_END_ALLOW_THREADS
575582

576-
if (ssl) {
577-
int i;
578-
for (i=0; i<n_ssl_keepref; i++) {
579-
Py_DECREF(ssl_keepref[i]);
580-
ssl_keepref[i] = NULL;
581-
}
583+
for (int i=0; i<n_ssl_keepref; i++) {
584+
Py_DECREF(ssl_keepref[i]);
585+
ssl_keepref[i] = NULL;
582586
}
583587

584588
if (!conn) {

0 commit comments

Comments
 (0)