代理无法通过 SSL 连接工作 [英] Proxy not working over SSL connection

查看:92
本文介绍了代理无法通过 SSL 连接工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 tor、socksipy 和 ssl 来代理 ssl 连接.我的客户看起来像这样:

I'm trying to use tor, socksipy and ssl to proxy a ssl connection. My client looks like this:

import socks, ssl
s = socks.socksocket()
s.setproxy(socks.PROXY_TYPE_SOCKS5,"127.0.0.1", 9050)
ssl_sock = ssl.wrap_socket(s, ssl_version=ssl.PROTOCOL_TLSv1)
ssl_sock.connect(('127.0.0.1', 443))

服务器只接受连接并打印getpeername.

The server just accepts connections and prints getpeername.

对等名称始终为 127.0.0.1.如果我给它一个无效的代理,它甚至都没有关系.客户端不会抱怨,无论如何它都会连接.

The peer name is always 127.0.0.1. It doesn't even matter if I give it a non-valid proxy. The client won't complain, it will connect anyway.

如何让它通过代理连接?

How do I make it connect through the proxy?

推荐答案

我设法弄明白了,所以我将答案留在这里以备将来参考.

I managed to figure it out so I will leave the answer here for future reference.

第一个问题是我试图连接到 127.0.0.1.当请求被代理时,代理会尝试连接到 127.0.0.1,所以它会尝试连接到它自己,而不是我.我必须将路由器配置为将端口 443 上的请求转发到我的笔记本电脑,然后我将 127.0.0.1 替换为我的路由器 IP.

The first problem was that I tried to connect to 127.0.0.1. As the request was proxied, the proxy would try to connect to 127.0.0.1, so it would try to connect to itself, not to me. I had to configure my router to forward requests on port 443 to my laptop and then I replaced 127.0.0.1 with my routers IP.

在那之后,我发现socksipy 不能很好地与ssl 配合使用.我必须在包装它之前在套接字上调用 connect ,否则我会遇到握手失败.代码变成:

After that was out of the way, I found out that socksipy doesn't play very well with ssl. I had to call connect on the socket before wrapping it, otherwise I'd get a handshake failure. The code became:

import socks, ssl
s = socks.socksocket()
s.setproxy(socks.PROXY_TYPE_SOCKS5,"127.0.0.1", 9050)
s.connect(('127.0.0.1', 443))
ssl_sock = ssl.wrap_socket(s, ssl_version=ssl.PROTOCOL_TLSv1)

在那之后,一切正常.

这篇关于代理无法通过 SSL 连接工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆