Skip to content

DeprecationWarning: ssl.wrap_socket() is deprecated, use SSLContext.w…#16

Open
riramar wants to merge 1 commit intoBishopFox:masterfrom
riramar:patch-1
Open

DeprecationWarning: ssl.wrap_socket() is deprecated, use SSLContext.w…#16
riramar wants to merge 1 commit intoBishopFox:masterfrom
riramar:patch-1

Conversation

@riramar
Copy link
Copy Markdown
Contributor

@riramar riramar commented May 10, 2022

Fix the warning below.

./h2csmuggler-proxy.py:49: DeprecationWarning: ssl.wrap_socket() is deprecated, use SSLContext.wrap_socket()
retSock = ssl.wrap_socket(sock, ssl_version=ssl.PROTOCOL_TLS)

Ref. https://docs.python.org/3/library/ssl.html#:~:text=Deprecated%20since%20version%203.7%3A%20Since%20Python%203.2%20and%202.7.9%2C%20it%20is%20recommended%20to%20use%20the%20SSLContext.wrap_socket()%20instead%20of%20wrap_socket().

…rap_socket()

Fix the warning below.

./h2csmuggler-proxy.py:49: DeprecationWarning: ssl.wrap_socket() is deprecated, use SSLContext.wrap_socket()
  retSock = ssl.wrap_socket(sock, ssl_version=ssl.PROTOCOL_TLS)

Ref. https://docs.python.org/3/library/ssl.html#:~:text=Deprecated%20since%20version%203.7%3A%20Since%20Python%203.2%20and%202.7.9%2C%20it%20is%20recommended%20to%20use%20the%20SSLContext.wrap_socket()%20instead%20of%20wrap_socket().
@sedorf
Copy link
Copy Markdown

sedorf commented Apr 30, 2023

Hi @riramar , but how to fix in code ?

@sedorf
Copy link
Copy Markdown

sedorf commented Apr 30, 2023

def establish_tcp_connection(proxy_url):
port = proxy_url.port or (80 if proxy_url.scheme == "http" else 443)
connect_args = (proxy_url.hostname, int(port))

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

sock.settimeout(10)
sock.connect(connect_args)

return sock

def send_initial_request(connection, proxy_url, settings_header_value):
request = build_initial_request(proxy_url, settings_header_value)

connection.sendall(request)

if proxy_url.scheme == "https":
    context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
    context.load_default_certs()
    connection = context.wrap_socket(connection, server_hostname=proxy_url.hostname)

return connection

@zinzloun
Copy link
Copy Markdown

zinzloun commented Jun 7, 2024

@riramar: thanx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants