Skip to content

Commit a751670

Browse files
committed
WL#15664: Add support for Python 3.12
Change-Id: Id048ff3eb6fdde901558eda880cdb6fb44e55719
1 parent 0cc98b5 commit a751670

File tree

4 files changed

+8
-60
lines changed

4 files changed

+8
-60
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Full release notes:
1111
v8.2.0
1212
======
1313

14+
- WL#15664: Add support for Python 3.12
1415
- WL#15623: Improve the authentication module
1516
- WL#15218: Support WebAuthn authentication
1617
- BUG#35547876: C/Python 8.1.0 type check build fails in the pb2 branch

lib/mysql/connector/network.py

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"""Module implementing low-level socket communication with MySQL servers.
3232
"""
3333

34-
import os
3534
import socket
3635
import struct
3736
import warnings
@@ -507,35 +506,6 @@ def switch_to_ssl(self, ssl_context: Any, host: str) -> None:
507506

508507
try:
509508
self.sock = ssl_context.wrap_socket(self.sock, server_hostname=host)
510-
if ssl_context.check_hostname:
511-
hostnames = [host] if host else []
512-
if os.name == "nt" and host == "localhost":
513-
hostnames = ["localhost", "127.0.0.1"]
514-
aliases = socket.gethostbyaddr(host)
515-
hostnames.extend([aliases[0]] + aliases[1])
516-
match_found = False
517-
errs = []
518-
for hostname in hostnames:
519-
try:
520-
# Deprecated in Python 3.7 without a replacement and
521-
# should be removed in the future, since OpenSSL now
522-
# performs hostname matching
523-
# pylint: disable=deprecated-method
524-
ssl.match_hostname(
525-
self.sock.getpeercert(), # type: ignore[union-attr]
526-
hostname,
527-
)
528-
# pylint: enable=deprecated-method
529-
except ssl.CertificateError as err:
530-
errs.append(str(err))
531-
else:
532-
match_found = True
533-
break
534-
if not match_found:
535-
self.sock.close()
536-
raise InterfaceError(
537-
f"Unable to verify server identity: {', '.join(errs)}"
538-
)
539509
except NameError as err:
540510
raise NotSupportedError("Python installation has no SSL support") from err
541511
except (ssl.SSLError, IOError) as err:
@@ -602,6 +572,7 @@ def build_ssl_context(
602572
if "TLSv1" not in tls_versions:
603573
context.options |= ssl.OP_NO_TLSv1
604574
else:
575+
# `check_hostname` is True by default
605576
context = ssl.create_default_context()
606577

607578
context.check_hostname = ssl_verify_identity

lib/mysqlx/connection.py

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,12 @@ def set_ssl(
366366
raise RuntimeError("Python installation has no SSL support")
367367

368368
if ssl_protos is None or not ssl_protos:
369+
# `check_hostname` is True by default
369370
context = ssl.create_default_context()
370371
if ssl_mode != SSLMode.VERIFY_IDENTITY:
371372
context.check_hostname = False
372-
if ssl_mode == SSLMode.REQUIRED:
373-
context.verify_mode = ssl.CERT_NONE
373+
if ssl_mode == SSLMode.REQUIRED:
374+
context.verify_mode = ssl.CERT_NONE
374375
else:
375376
ssl_protos.sort(reverse=True)
376377
tls_version = ssl_protos[0]
@@ -391,6 +392,8 @@ def set_ssl(
391392
if "TLSv1" not in ssl_protos:
392393
context.options |= ssl.OP_NO_TLSv1
393394

395+
context.check_hostname = ssl_mode == SSLMode.VERIFY_IDENTITY
396+
394397
if ssl_ca:
395398
try:
396399
context.load_verify_locations(ssl_ca)
@@ -422,34 +425,6 @@ def set_ssl(
422425
self._socket = context.wrap_socket(self._socket, server_hostname=self._host)
423426
except ssl.CertificateError as err:
424427
raise InterfaceError(f"{err}") from err
425-
if ssl_mode == SSLMode.VERIFY_IDENTITY:
426-
context.check_hostname = True
427-
hostnames = []
428-
# Windows does not return loopback aliases on gethostbyaddr
429-
if os.name == "nt" and self._host in ("localhost", "127.0.0.1"):
430-
hostnames = ["localhost", "127.0.0.1"]
431-
aliases = socket.gethostbyaddr(self._host)
432-
hostnames.extend([aliases[0]] + aliases[1])
433-
match_found = False
434-
errs = []
435-
for hostname in hostnames:
436-
try:
437-
# Deprecated in Python 3.7 without a replacement and
438-
# should be removed in the future, since OpenSSL now
439-
# performs hostname matching
440-
# pylint: disable=deprecated-method
441-
ssl.match_hostname(self._socket.getpeercert(), hostname)
442-
# pylint: enable=deprecated-method
443-
except ssl.CertificateError as err:
444-
errs.append(str(err))
445-
else:
446-
match_found = True
447-
break
448-
if not match_found:
449-
self.close()
450-
raise InterfaceError(
451-
f"Unable to verify server identity: {', '.join(errs)}"
452-
)
453428

454429
self._is_ssl = True
455430

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
"Programming Language :: Python :: 3.9",
130130
"Programming Language :: Python :: 3.10",
131131
"Programming Language :: Python :: 3.11",
132+
"Programming Language :: Python :: 3.12",
132133
"Topic :: Database",
133134
"Topic :: Software Development",
134135
"Topic :: Software Development :: Libraries :: Application Frameworks",

0 commit comments

Comments
 (0)