我尝试在我自己的 HTTPS 代理上工作,但我无法创建我的 https 服务器,在连接初始化期间,我收到此错误消息“tlsClientError 错误:101057795:错误:1407609B:SSL 例程:SSL23_GET_CLIENT_HELLO:https 代理请求:openssl\ssl\s23_srvr.c:400".
Node JS源码下方:
private runHttpsServer() {
const instance = this;
const cert = fs.readFileSync("./certificate/server.crt", "utf8");
const key = fs.readFileSync("./certificate/key.pem", "utf8");
const options : https.ServerOptions = {
cert: cert,
key: key
};
const httpsServer = https.createServer(options, (req, res)=>{
console.log("Request ...");
instance.handleRequest.call(instance, req, res);
});
httpsServer.on("tlsClientError", (err : Error, tlsSocket : TLSSocket)=>{
console.log("tlsClientError", err.stack);
});
httpsServer.listen(7001);
当我在没有代理的情况下直接浏览到“https://localhost:7001/”时,没有出现 SSL 握手错误。 当我通过我的代理浏览到其他网站时,出现此 SSL 握手错误。
有人遇到过这个问题吗? 有些人可以帮助我吗?
最佳答案
看来您对代理 HTTPS 的工作原理有错误的理解。并不是像您假设的那样,客户端将与代理建立 TLS 连接,而是客户端将使用 CONNECT 方法向代理发送普通 HTTP 请求,以使代理建立到目标主机的隧道。然后客户端将此隧道升级为 TLS,从而在客户端和最终服务器之间获得端到端的保护。
在线路上它看起来像这样(确切消息可能略有不同 - 详情请参阅 RFC 2817):
Client ------------------------> Proxy
- create TCP connection
- send to proxy:
> CONNECT google.com:443 HTTP/1.0\r\n
> \r\n
Proxy -----------------------------> Server
- create TCP connection
Client <------------------------ Proxy
- send to client
< HTTP/1.0 200 Connection established\r\n
< \r\n
Client <------------------------(Proxy)-----------------------------> Server
use tunnel from client to server through proxy to
- make the end-to-end TLS handshake
- transfer the HTTP messages within the TLS connection
... SSL routines:SSL23_GET_CLIENT_HELLO:https proxy request: ...
此错误消息实质上表明您的代理期望 TLS 握手 (ClientHello) 开始,但却收到了 https 代理请求,即 CONNECT ...
。您需要修复您的代理以正确处理 https 代理请求,这些请求按我所描述的方式工作。
关于node.js - 在 NodeJS 上使用自己的 https 代理发出 SSL 握手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52677236/