Skip to content

Commit 02fd865

Browse files
committed
WL14542: Deprecate TLS 1.0 and 1.1
With this worklog a deprecation warning is raised in Connector/Python when TLSv1 or TLSv1.1 versions are being used, notifying the user that these versions will be removed in a future release.
1 parent e808c25 commit 02fd865

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/mysql/connector/connection.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import platform
3636
import socket
3737
import time
38+
import warnings
3839

3940
from .authentication import get_auth_plugin
4041
from .constants import (
@@ -421,6 +422,21 @@ def _open_connection(self):
421422
self.close()
422423
raise
423424

425+
if (
426+
not self._ssl_disabled
427+
and hasattr(self._socket.sock, "version")
428+
and callable(self._socket.sock.version)
429+
):
430+
# Raise a deprecation warning if TLSv1 or TLSv1.1 is being used
431+
tls_version = self._socket.sock.version()
432+
if tls_version in ("TLSv1", "TLSv1.1"):
433+
warn_msg = (
434+
f"This connection is using {tls_version} which is now "
435+
"deprecated and will be removed in a future release of "
436+
"MySQL Connector/Python"
437+
)
438+
warnings.warn(warn_msg, DeprecationWarning)
439+
424440
def shutdown(self):
425441
"""Shut down connection to MySQL Server.
426442
"""

lib/mysqlx/connection.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2016, 2020, Oracle and/or its affiliates.
1+
# Copyright (c) 2016, 2021, Oracle and/or its affiliates.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0, as
@@ -58,6 +58,7 @@
5858
import random
5959
import re
6060
import threading
61+
import warnings
6162

6263
try:
6364
import dns.resolver
@@ -360,6 +361,16 @@ def set_ssl(self, ssl_protos, ssl_mode, ssl_ca, ssl_crl, ssl_cert, ssl_key,
360361

361362
self._is_ssl = True
362363

364+
# Raise a deprecation warning if TLSv1 or TLSv1.1 is being used
365+
tls_version = self._socket.version()
366+
if tls_version in ("TLSv1", "TLSv1.1"):
367+
warn_msg = (
368+
f"This connection is using {tls_version} which is now "
369+
"deprecated and will be removed in a future release of "
370+
"MySQL Connector/Python"
371+
)
372+
warnings.warn(warn_msg, DeprecationWarning)
373+
363374
def is_ssl(self):
364375
"""Verifies if SSL is being used.
365376

0 commit comments

Comments
 (0)