簡體   English   中英

Python:未定義符號:導入 ssl 時的 TLSv1_method

[英]Python: undefined symbol: TLSv1_method when importing ssl

我在一個發行版上運行 Python 3.5.6,其中 TLS 版本低於 1.2 已通過將這些選項傳遞給no-ssl no-tls1 no-tls1_1 no-ssl3-method no-tls1-method no-tls1_1-method編譯出來。 no-ssl no-tls1 no-tls1_1 no-ssl3-method no-tls1-method no-tls1_1-method OpenSSL 版本為 1.1.1d。 Python 3 在發行版構建時從源代碼構建,並與發行版中包含的 OpenSSL 版本相關聯。

一切構建成功,但是當我嘗試在 Python 中導入ssl庫時,出現以下錯誤:

$ python3
Python 3.5.6 (default, Mar 23 2020, 05:11:33)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.5/ssl.py", line 99, in <module>
    import _ssl             # if we can't import it, let the error propagate
ImportError: /usr/lib/python3.5/lib-dynload/_ssl.cpython-35m-aarch64-linux-gnu.so: undefined symbol: TLSv1_method

我不明白為什么在運行時會發生此錯誤。 我在 TLSv1_method 的 Python 3.5.6 代碼中可以找到的唯一參考是 _ssl.c 的第 3088 行:

ctx = SSL_CTX_new(TLSv1_method());

使用no-tls1-method確實編譯出TLSv1_method的實現,並且 Python 代碼中的那一行不受任何#ifdef保護。 但我希望這會導致_ssl.cpython-35m-aarch64-linux-gnu.so模塊在鏈接時失敗,而不是在 Python 嘗試導入模塊時在運行時失敗。 這是怎么回事,有沒有辦法在不修補 Python 的情況下修復它? 我無法升級正在使用的 OpenSSL 或 Python 的版本。

似乎我的困惑是由於誤解_ssl.cpython-35m-aarch64-linux-gnu.so如何鏈接到 OpenSSL。 我假設它是靜態鏈接的,但它實際上是動態鏈接到libssl.so的。 這就是為什么在加載共享 object 時在運行時發生錯誤的原因。

那么,在不更新 Python 的情況下解決此問題的唯一方法似乎是修補對TLSv1_method的調用以改用通用TLS_method 我會把這個問題留幾天,但萬一有人有更好的建議。

編輯:我為此問題提交了Python 錯誤 它應該在未來的版本中得到修復。

暫無
暫無

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

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