mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-02 20:24:23 -07:00
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
)
This commit is contained in:
parent
3d088b68ec
commit
4de1ef02e6
2 changed files with 5 additions and 1 deletions
2
changelogs/fragments/10491-irc.yml
Normal file
2
changelogs/fragments/10491-irc.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- "irc - pass hostname to ``wrap_socket()`` if ``use_tls=true`` and ``validate_certs=true`` (https://github.com/ansible-collections/community.general/issues/10472, https://github.com/ansible-collections/community.general/pull/10491)."
|
|
@ -232,9 +232,11 @@ def send_msg(msg, server='localhost', port='6667', channel=None, nick_to=None, k
|
||||||
|
|
||||||
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
if use_tls:
|
if use_tls:
|
||||||
|
kwargs = {}
|
||||||
if validate_certs:
|
if validate_certs:
|
||||||
try:
|
try:
|
||||||
context = ssl.create_default_context()
|
context = ssl.create_default_context()
|
||||||
|
kwargs["server_hostname"] = server
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise Exception('Need at least Python 2.7.9 for SSL certificate validation')
|
raise Exception('Need at least Python 2.7.9 for SSL certificate validation')
|
||||||
else:
|
else:
|
||||||
|
@ -244,7 +246,7 @@ def send_msg(msg, server='localhost', port='6667', channel=None, nick_to=None, k
|
||||||
else:
|
else:
|
||||||
context = ssl.SSLContext()
|
context = ssl.SSLContext()
|
||||||
context.verify_mode = ssl.CERT_NONE
|
context.verify_mode = ssl.CERT_NONE
|
||||||
irc = context.wrap_socket(irc)
|
irc = context.wrap_socket(irc, **kwargs)
|
||||||
irc.connect((server, int(port)))
|
irc.connect((server, int(port)))
|
||||||
|
|
||||||
if passwd:
|
if passwd:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue