BishopFox / h2csmuggler

HTTP Request Smuggling over HTTP/2 Cleartext (h2c)
MIT License
644 stars 100 forks source link

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

Open riramar opened 2 years ago

riramar commented 2 years ago

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 commented 1 year ago

Hi @riramar , but how to fix in code ?

sedorf commented 1 year ago

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 commented 4 months ago

@riramar: thanx