我有一个公共(public) ssl 端点 some.example.com,它需要使用 SNI 扩展。我无法直接访问它,所以我想通过haproxy(在可以访问互联网的服务器中设置)来传递它
这不起作用:
openssl s_client -connect some.example.com:443
这工作正常:
openssl s_client -connect some.example.com:443 -servername some.example.com
我的 haproxy 配置(版本 1.8.24):
frontend my_frontend
bind *:443
mode tcp
log global
option tcplog
tcp-request inspect-delay 5s
tcp-request content accept if { req_ssl_hello_type 1 }
use_backend my_backend
backend my_backend
mode tcp
server my-server something.example.com:443 sni str(something.example.com)
当我登录 haproxy 服务器时,我可以执行以下操作:
curl -v https://something.example.com/
可以看到SSL连接已建立
但是在执行curl -v https://127.0.0.1/
时我面临:
curl:(35) OpenSSL SSL_connect:SSL_ERROR_SYSCALL 连接到 127.0.0.1:443
出了什么问题?我已经尝试终止 ssl,替换主机 header ,但没有成功。我的理解是,SNI 本身与加密请求分离,通过上述配置,我应该能够连接到后端。
PS。后端服务器不是我管理的。编辑:如注释中所述,不可能在 TCP 模式配置中传递自定义 SNI。对于 http 模式,可以执行以下操作,并使用 TLS 终止,以下工作正常:
frontend log_frontend
bind *:443 ssl crt /etc/pki/tls/private/mycert.pem
mode http
log global
option httplog
option forwardfor
use_backend log_backend
backend log_backend
mode http
server my-server something.example.com:443 ssl verify none sni str(something.example.com)
最佳答案
My understanding is that SNI itself is separated from ciphered request ...
SNI 是 SSL/TLS 握手的一部分,特别是客户端在握手开始时发送的 ClientHello。 不可能替换 TLS 握手的任何部分,包括 SNI。相反,需要终止 TLS(这意味着需要正确的证书等),然后必须使用预期的 SNI 集创建新的 TLS session 。
关于ssl - 如何在TCP模式下用haproxy传递自定义SNI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68212958/