Skip to content

Support 'sni_hostname' extension with SOCKS proxy. #772

Closed

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"),

Activity

  1. lovelydinosaur commented on Aug 8, 2023

    @lovelydinosaur
    Member

    Thanks for this, I'll retitle it so that it's more specific.

  2. changed the title [-]Inconsistent update, regarding sni_hostname extension.[/-] [+]Support 'sni_hostname' extension with SOCKS proxy.[/+] on Aug 8, 2023
  3. lovelydinosaur commented on Aug 8, 2023

    @lovelydinosaur
    Member

    @Allgot Would you like to issue a pull request resolving this?

  4. Allgot commented on Aug 8, 2023

    @Allgot
    ContributorAuthor

    @tomchristie
    No problem!

    But since this is my first contribution to this repository(in terms of pull requests), my request might not be perfect. It would be great if you can correct errors, if exist :)

  5. Allgot commented on Aug 9, 2023

    @Allgot
    ContributorAuthor

    I've send a PR. Please refer to #774

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions