通过 HAproxy 使用 Powershell 连接到 MSSQL

问题描述

我有在 Ubuntu 20.04 上运行的 powershell 脚本,我想与在 MS Server 2012 R2 上运行的 MSsql 对话。 我可以使用完全相同的设置从 Ubuntu 16.04 连接到 MSsql,但是从 U2004 获得 "A connection was successfully established with the server,but then an error occurred during the pre-login handshake. (provider: SSL Provider,error: 31 - Encryption(ssl/tls) handshake Failed)" 经过一番挖掘,发现 Ubuntu 和 MS Server 无法就加密/密码达成一致。事实上,Ubuntu 2004 不支持 MSsql 提供的密码列表。 试图在 U2004 早期版本的 openssl 上构建以启用弱密码,但这不起作用(顺便说一句,不推荐这样做,因为这可能会破坏其他操作系统依赖项......)。 我的下一个赌注是让 HAproxy 在 Ubuntu 16.04 上运行,并通过它将流量从 Ubuntu 20.04 转发到 MSsql。这个想法是在“后端”上支持弱密码。事实上,我知道 MSsql 支持“AES256-SHA”。我的配置如下:

frontend sql-db
    bind 192.168.100.3:1433
    mode tcp
    option tcplog
    log global
    default_backend connToDB

backend connToDB
    mode tcp
    option tcplog
    log global
    server DB-1 db1:1433 ciphers AES256-SHA

但仍然得到相同的 provider: SSL Provider,error: 31 - Encryption(ssl/tls) handshake Failed

如果我执行 server DB-1 db1:1433 ssl verify none ciphers AES256-SHA(我发现它有时会修复问题,但似乎仅适用于 http 代理)然后我会得到 "Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake ackNowledgement. This Could be because the pre-login handshake Failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=3; handshake=15058; "

顺便说一句,在 Ubuntu 20.04 上使用 openssl.conf(设置 minsslversion 和定义密码)也没有帮助。

附言目前无法对 MSsql 进行任何更改!这将是修复它的方法,但不幸的是

请帮忙!

解决方法

好吧,在与这个问题斗争了几天之后,我终于想通了。 只需在 openssl.cnf 文件的开头 (!!!) 附加 openssl_conf = default_conf 并附加在文件末尾:

[ default_conf ]
ssl_conf = ssl_sect

[ssl_sect]
system_default = system_default_sect

[system_default_sect]
MinProtocol = TLSv1
CipherString = DEFAULT:@SECLEVEL=1

我之前已经尝试过该解决方案,但我的错误是我的 openssl_conf = default_conf 行不在文件的最顶部,因此该解决方案对我不起作用。 (-_-)

无需重启主机即可测试配置的简便方法 - 使用您要使用的配置创建 /path/to/my/file/openssl_test.cnf。 然后简单地将需要在 bash 中运行的命令加上 OPENSSL_CONF=/path/to/my/file/openssl_test.cnf 使其看起来像(在我的情况下使用 Linux powershell):

OPENSSL_CONF=/path/to/my/file/openssl_test.cnf pwsh myScript.ps1 arg1 arg2