Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion nettacker/core/lib/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def create_tcp_socket(host, port, timeout):
return None

try:
socket_connection = ssl.wrap_socket(socket_connection)
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
socket_connection = context.wrap_socket(socket_connection, server_hostname=host)
ssl_flag = True
except Exception:
socket_connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Expand Down
5 changes: 4 additions & 1 deletion nettacker/core/lib/ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ def create_tcp_socket(host, port, timeout):
return None

try:
socket_connection = ssl.wrap_socket(socket_connection)
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
socket_connection = context.wrap_socket(socket_connection, server_hostname=host)
ssl_flag = True
except Exception:
socket_connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Expand Down
4 changes: 2 additions & 2 deletions tests/core/lib/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def responses():

class TestSocketMethod:
@patch("socket.socket")
@patch("ssl.wrap_socket")
@patch("ssl.SSLContext.wrap_socket")
def test_create_tcp_socket(self, mock_wrap, mock_socket):
HOST = "example.com"
PORT = 80
Expand All @@ -151,7 +151,7 @@ def test_create_tcp_socket(self, mock_wrap, mock_socket):
socket_instance = mock_socket.return_value
socket_instance.settimeout.assert_called_with(TIMEOUT)
socket_instance.connect.assert_called_with((HOST, PORT))
mock_wrap.assert_called_with(socket_instance)
mock_wrap.assert_called_with(socket_instance, server_hostname=HOST)

def test_response_conditions_matched_socket_icmp(self, socket_engine, substeps, responses):
result = socket_engine.response_conditions_matched(
Expand Down
5 changes: 3 additions & 2 deletions tests/core/lib/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def connection_params():

class TestSslMethod:
@patch("socket.socket")
@patch("ssl.wrap_socket")
@patch("ssl.SSLContext.wrap_socket")
def test_create_tcp_socket(self, mock_wrap, mock_socket, connection_params):
create_tcp_socket(
connection_params["HOST"], connection_params["PORT"], connection_params["TIMEOUT"]
Expand All @@ -190,7 +190,8 @@ def test_create_tcp_socket(self, mock_wrap, mock_socket, connection_params):
socket_instance.connect.assert_called_with(
(connection_params["HOST"], connection_params["PORT"])
)
mock_wrap.assert_called_with(socket_instance)

mock_wrap.assert_called_with(socket_instance, server_hostname=connection_params["HOST"])

@patch("nettacker.core.lib.ssl.is_weak_cipher_suite")
@patch("nettacker.core.lib.ssl.is_weak_ssl_version")
Expand Down