Skip to content

Support 'sni_hostname' extension with SOCKS proxy. #772

@Allgot

Description

@Allgot

Currently, there is an issue with sni_hostname not functioning correctly when the connection involves a socks proxy.
This problem arises due to the oversight in commit #696, where the update to _sync/socks_proxy.py and _async/socks_proxy.py was omitted.

Code for reproduction (written by @karosis88 at #771)

Set up proxy server (defaults to 1080 port)

git clone https://github.com/itsjfx/python-socks5-server
python python-socks5-server/server.py

Client

import httpcore

pool = httpcore.SOCKSProxy("socks5://127.0.0.1:1080")
response = pool.request("GET", 
                        "https://185.199.108.153:443", 
                        headers=[(b'Host', 'www.encode.io')], 
                        extensions={'sni_hostname': 'www.encode.io'})
print(response)

Expected output

<Response [200]>

Actual output

httpcore.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: IP address mismatch, certificate is not valid for '185.199.108.153'. (_ssl.c:1123)

Suggested fix

Update the _sync/socks_proxy.py and _async/socks_proxy.py in a manner similar to that of the _sync/connection.py and _async/connection.py.

Example fix for _async/socks_proxy.py:

218    218      timeouts = request.extensions.get("timeout", {})
       219   +  sni_hostname = request.extensions.get("sni_hostname", None)
219    220      timeout = timeouts.get("connect", None)

261          -  "server_hostname": self._remote_origin.host.decode("ascii"),
       262   +  "server_hostname": sni_hostname
       263   +  or self._origin.host.decode("ascii"),

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions