[PR #10491/de0618b8 backport][stable-9] irc: fix wrap_socket() call when validate_certs=true and use_tls=true (#10497)

irc: fix wrap_socket() call when validate_certs=true and use_tls=true (#10491)

Fix wrap_socket() call when validate_certs=true and use_tls=true.

(cherry picked from commit de0618b843)

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
patchback[bot]
2025-07-28 06:47:00 +02:00
committed by GitHub
parent b18b9314d3
commit 54861a2062
2 changed files with 5 additions and 1 deletions

View File

@@ -221,9 +221,11 @@ def send_msg(msg, server='localhost', port='6667', channel=None, nick_to=None, k
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if use_tls:
kwargs = {}
if validate_certs:
try:
context = ssl.create_default_context()
kwargs["server_hostname"] = server
except AttributeError:
raise Exception('Need at least Python 2.7.9 for SSL certificate validation')
else:
@@ -233,7 +235,7 @@ def send_msg(msg, server='localhost', port='6667', channel=None, nick_to=None, k
else:
context = ssl.SSLContext()
context.verify_mode = ssl.CERT_NONE
irc = context.wrap_socket(irc)
irc = context.wrap_socket(irc, **kwargs)
irc.connect((server, int(port)))
if passwd: