簡體   English   中英

PHP ODBC 無法使用 Openssl 1.1.1 連接到 SQL Server 2012

[英]PHP ODBC can't connect to SQL Server 2012 with Openssl 1.1.1

我已經看到這個問題的一部分被問了幾次,但對我來說還沒有任何效果。

我有一個在 Windows 服務器上運行的 SQL Server 2012 實例。 在我的 Ubuntu 20.10 服務器上,我在 apache 服務器上運行 PHP 7.4.12。 我安裝了 openssl 1.1.1 版。

我遵循了微軟文檔中的大部分說明:

https://docs.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver15#installing-the-drivers-on-ubuntu-1604-1804-和-2004

但是在下載 msodbcsql17 驅動程序時遇到了一些問題。 我不得不從這里下載它:

https://packages.microsoft.com/ubuntu/20.04/prod/pool/main/m/msodbcsql17/

我的 PHP 腳本:

<?php

try {
    // Sensitive info is replaced by temporary strings.
    $serverName = "<ip_addr>,<port>";

    $options = array("Database" => "<db_name>", "UID" => "<user_name>", "PWD" => "<password>");

    $conn = sqlsrv_connect($serverName, $options);

    if ($conn == false) {
        var_dump(sqlsrv_errors());
        die();
    }
} catch(Exception $e) {
    echo("Error!");
}

這是從var_dump(sqlsrv_errors());打印出來的錯誤var_dump(sqlsrv_errors()); 在上面的代碼中:

array(2) {
  [0]=>
  array(6) {
    [0]=>
    string(5) "08001"
    ["SQLSTATE"]=>
    string(5) "08001"
    [1]=>
    int(10054)
    ["code"]=>
    int(10054)
    [2]=>
    string(73) "[Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x2746"
    ["message"]=>
    string(73) "[Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Error code 0x2746"
  }
  [1]=>
  array(6) {
    [0]=>
    string(5) "08001"
    ["SQLSTATE"]=>
    string(5) "08001"
    [1]=>
    int(10054)
    ["code"]=>
    int(10054)
    [2]=>
    string(79) "[Microsoft][ODBC Driver 17 for SQL Server]Client unable to establish connection"
    ["message"]=>
    string(79) "[Microsoft][ODBC Driver 17 for SQL Server]Client unable to establish connection"
  }
}

我在這里看到了這個潛在的解決方案: https : //github.com/microsoft/msphpsql/issues/1021#issuecomment-520943561/etc/ssl/openssl.cnf文件中沒有一行CipherString = DEFAULT@SECLEVEL-2答案指出。 無論如何,我嘗試將CipherString = DEFAULT@SECLEVEL=1到文件末尾,但沒有任何改變。

我能做些什么來修復連接中的這個錯誤? 是降級 openssl 版本的唯一其他選擇嗎? 我讀過它可以破壞許多軟件包並導致問題。 我也無法將 SQL Server 脫機升級到更新的 SQL 版本。

我已確保 SQL Server 接受遠程連接,因為我可以使用 Crystal Reports 從另一台計算機建立到 SQL Server 的 ODBC 連接。

編輯:openssl 命令結果

以下是運行后立即打印的結果:

openssl s_client -host <ip_addr> -port <port> -tls1
CONNECTED(00000003)
139710250579264:error:141E70BF:SSL routines:tls_construct_client_hello:no protoc                                           ols available:../ssl/statem/statem_clnt.c:1112:
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 0 bytes and written 7 bytes
Verification: OK
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
Early data was not sent
Verify return code: 0 (ok)
---

下面是運行后的結果:

openssl s_client -host <ip_addr> -port <port> -tls1_2

它保持打開狀態一段時間,最后在沒有輸入任何內容后,它打印了以下內容:

CONNECTED(00000003)
write:errno=104
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 0 bytes and written 188 bytes
Verification: OK
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : 0000
    Session-ID:
    Session-ID-ctx:
    Master-Key:
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    Start Time: 1605916005
    Timeout   : 7200 (sec)
    Verify return code: 0 (ok)
    Extended master secret: no
---

現在有點晚了。 /etc/ssl/openssl.cnf嘗試MinProtocol = TLSv1.0 這對我來說很好( https://github.com/microsoft/msphpsql/issues/1023#issuecomment-523214695

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM