mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add IPv6 support to module_utils.urls TLS validation (#26852)
socket.create_connection is a higher-level function, which tries to establish a socket connection using both AF_INET and AF_INET6. It got introduced in Python 2.6, which ought to be fine with Ansible 2.4. Fixes #26740
This commit is contained in:
parent
b8cd646afd
commit
4e01397817
1 changed files with 2 additions and 3 deletions
|
@ -720,11 +720,10 @@ class SSLValidationHandler(urllib_request.BaseHandler):
|
||||||
return req
|
return req
|
||||||
|
|
||||||
try:
|
try:
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
||||||
if https_proxy:
|
if https_proxy:
|
||||||
proxy_parts = generic_urlparse(urlparse(https_proxy))
|
proxy_parts = generic_urlparse(urlparse(https_proxy))
|
||||||
port = proxy_parts.get('port') or 443
|
port = proxy_parts.get('port') or 443
|
||||||
s.connect((proxy_parts.get('hostname'), port))
|
s = socket.create_connection((proxy_parts.get('hostname'), port))
|
||||||
if proxy_parts.get('scheme') == 'http':
|
if proxy_parts.get('scheme') == 'http':
|
||||||
s.sendall(self.CONNECT_COMMAND % (self.hostname, self.port))
|
s.sendall(self.CONNECT_COMMAND % (self.hostname, self.port))
|
||||||
if proxy_parts.get('username'):
|
if proxy_parts.get('username'):
|
||||||
|
@ -748,7 +747,7 @@ class SSLValidationHandler(urllib_request.BaseHandler):
|
||||||
else:
|
else:
|
||||||
raise ProxyError('Unsupported proxy scheme: %s. Currently ansible only supports HTTP proxies.' % proxy_parts.get('scheme'))
|
raise ProxyError('Unsupported proxy scheme: %s. Currently ansible only supports HTTP proxies.' % proxy_parts.get('scheme'))
|
||||||
else:
|
else:
|
||||||
s.connect((self.hostname, self.port))
|
s = socket.create_connection((self.hostname, self.port))
|
||||||
if context:
|
if context:
|
||||||
ssl_s = context.wrap_socket(s, server_hostname=self.hostname)
|
ssl_s = context.wrap_socket(s, server_hostname=self.hostname)
|
||||||
elif HAS_URLLIB3_SSL_WRAP_SOCKET:
|
elif HAS_URLLIB3_SSL_WRAP_SOCKET:
|
||||||
|
|
Loading…
Reference in a new issue