无法连接到 MacOS 中的旧版 SQL Server 数据库(OpenSSL v3 可疑)

问题描述 投票:0回答:1

由于我的 MacOS Catalina 中安装了新的brew,PHP 7.4 被破坏了,所以我不得不重新安装它。因此,我还必须重新安装 PHP 的依赖项。 PHP 和我的本地项目工作正常,但与 SQL Server 的连接除外(这是需要 TLS v1.0 的旧数据库)。因此,我重新安装了 PHP 驱动程序 和 brews FreeTDS、unixOBDC、msodbcsql17 和 mssql-tools。 但是,当尝试使用此命令连接

sqlcmd -S <DB_IP>
时,会出现此错误:

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : SSL Provider: [error:0A000102:SSL routines::unsupported protocol].
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Client unable to establish connection.

首先,我认为通过将 /etc/ssl/openssl.cnf 文件修改为 stated here,可以解决问题,但没有。我还尝试从 OpenSSL v3.2 降级到 OpenSSL v1.0 但错误更改为这样

Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : SSPI Provider:  The operation or option is not available.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Cannot generate SSPI context.

当尝试连接到 SQL Server 时,这两个错误也出现在我的 PHP 项目中,因此我回到了 OpenSSL v3。我的理论之一是 OpenSSL 在某种程度上不遵守 /etc/ssl/openssl.cnf 修改。这是因为运行此命令时

sudo dtruss sqlcmd -S <DB_IP>
这会出现在整个跟踪中:

open_nocancel("/usr/local/etc/openssl@3/openssl.cnf\0", 0x0, 0x1B6)      = 5 0

但没有出现 /etc/ssl/openssl.cnf 文件的引用。对了,我也尝试直接在/usr/local/etc/openssl@3/openssl.cnf中设置修改,但没有效果。在求助于另一台开发机器之前我还能做什么? 一些额外的细节:

odbcinst -j

unixODBC 2.3.12
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /Users/MY-USER/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8

odbcinst -q -d

[ODBC Driver 13 for SQL Server]
[ODBC Driver 17 for SQL Server]

OpenSSL v3.2 酿造安装

openssl@3 
==> Patching
==> Applying cafccb768be5b8f5c21852764f7b2863b6f5e204.patch
patching file crypto/x509/by_file.c
==> perl ./Configure --prefix=/usr/local/Cellar/openssl@3/3.2.0_1 --openssldir=/usr/local/etc/openssl@3 --libdir=/usr/local/Cellar/openssl@3/3.2.0_1/lib no-ssl3 no-ssl3-method no-zlib darwin64-x86_64-cc enable-ec_nistp_64_gcc_128
==> make
==> make install MANDIR=/usr/local/Cellar/openssl@3/3.2.0_1/share/man MANSUFFIX=ssl
==> make test
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@3/certs

and run
  /usr/local/opt/openssl@3/bin/c_rehash
==> Summary
🍺  /usr/local/Cellar/openssl@3/3.2.0_1: 6,798 files, 32.5MB, built in 23 minutes 33 seconds
==> Running `brew cleanup openssl@3`...
php sql-server macos openssl tls1.0
1个回答
0
投票

免责声明:在正常情况下我不建议这样做。最好先尝试这些建议修改

暂时找到了解决方法。我编辑了 /usr/local/etc/openssl@3/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=0

#
# OpenSSL example configuration file.

之后,我以 root 身份执行了

sqlcmd
和 PHP,现在我可以连接到旧的数据库了。幸运的是,数据库很快就会升级,所以我可以放弃这个解决方法。

© www.soinside.com 2019 - 2024. All rights reserved.