websocket - Squid4 转发代理从 ws 升级到 wss
问题描述
Squid4.6 用作转发代理,将所有流量转换为安全流量。squid 的配置非常简单,它允许所有流量,并使用 urlrewrite.pl 将“http”替换为“https”。(不使用 SSL-BUMP)squid 代理设置了 tls_outgoing_options,因此以下工作:
客户端(http) -----> Squid ------> 服务器(https)
现在,我正在尝试使用 websockets 复制相同的内容。有3个测试用例,1.client(ws)-----> Squid -----> Server(ws)
- 客户端(wss) ------> 鱿鱼 -----> 服务器(wss)
3 客户端(ws) ------> Squid -----> 服务器(wss)
前两种情况适用于 squid,但第三种情况不起作用。我只需要第三个选项。
我已经为 urlrewrite.pl 提供了调试日志,以显示收到的 websocket 连接的确切请求,以下是日志:这里端口 8080:是服务器,端口 3128:是鱿鱼
DEBUG:root:localhost:8080 127.0.0.1/localhost - 连接 myip=127.0.0.1 myport=3128
甚至wireshark 显示相同,1. CONNECT HTTP 1.1 2. GET 3. 升级协议。
问题: 1.有什么方法可以使用 squid4.6 将 websocket 连接升级到安全 websocket?2.或者说我使用wss-client(没有证书)和wss-server(有证书),有没有办法通知squid使用自己的证书,甚至在“tls_outgoing_options”中提到来建立连接?
要求:客户端将始终发送不安全的流量 HTTP/WS,Squid 应将其升级到 HTTPS/WSS。在我们的应用程序设置中,我们使用我们自己的 openssl 库来创建证书——它不能包含在 (client.go) go-tls 包中,因此我们使用 squid 代理来使用我们自己的 openssl 库生成的证书。Client 和 Forward-Proxy (Squid) 都在我们特定的环境中,所以 squid.conf 非常简单,允许所有流量。我们需要相互证书认证。
鱿鱼密码
#
# Recommended minimum configuration:
#
# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
acl localhost src 127.0.0.1
acl SSL_ports port 443
acl Safe_ports port 443 # https
acl Safe_ports port 80 # http
acl CONNECT method CONNECT
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost
http_access deny all
# Squid normally listens to port 3128
http_port 3128
url_rewrite_program /etc/squid/urlrewrite.pl
url_rewrite_access allow all
tls_outgoing_options cert=/etc/squid/proxy.crt
tls_outgoing_options key=/etc/squid/proxy.key
tls_outgoing_options cafile=/etc/squid/serverauth.crt
url重写代码
#!/usr/bin/perl
select(STDOUT);
$| = 1;
while (<>) {
#print STDOUT "OK rewrite-url=\"https://google.com\"\n";
if (/^(|\d+\s+)((\w+):\/+)([^\/:]+)(|:(\d+))(|\/\S*)(|\s.*)$/) {
my $channel = $1;
my $protocolClean = $3;
my $domain = $4;
my $port = $5;
my $portClean = $6;
my $urlPath = $7;
if ($protocolClean eq 'http' ){#&& ($port eq '' || $portClean eq '80')) {
print STDOUT "${channel}OK rewrite-url=\"https://${domain}${port}${urlPath}\"\n";
#print STDOUT "${channel}OK rewrite-url=\"https://google.com\"\n";
} else {
print STDOUT "${channel}ERR\n";
}
}
}
解决方案
推荐阅读
- android - 使用通知计数指示器制作“徽章”自定义视图
- arrays - 将 Matlab 中的动态类型数组转换为 Fortran
- wordpress - 更新 40,000 个现有帖子的 wordpress Advance 自定义字段
- xml - 使用 XSLT 将具有多个输出的 XML 转换为具有单个输出的 XML
- css - CSS 表格抓取
- java - 下载 Java - 我应该更改 Java Bin 的路径吗
- css - 如何在本机反应中添加浮动按钮?
- php - PDO MySQL 查询因多个比较运算符而失败
- sapui5 - 如何循环和收集 MultiInput 值?
- eclipse - 使用 H2 DB 自动创建 Camunda 用户