python / python/cpython

Fallback md5 is used, when trying hard to only use OpenSSL

未關閉
#118,224 26 則留言 2 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

type-bug
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

Bug report

Bug description:

When

  • OpenSSL is configured in FIPS mode
  • recommended config is used to only load "base + fips" providers
  • without the default provider
  • CPython is compiled with --with-builtin-hashlib-hashes=blake2 to exclude fallback implementation of MD5

upon importing hashlib fails to create MD5 construct.

# python3.10 -c 'import hashlib'
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
  File "/usr/lib/python3.10/hashlib.py", line 137, in __get_openssl_constructor
    f(usedforsecurity=False)
ValueError: [digital envelope routines] unsupported

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.10/hashlib.py", line 261, in <module>
    globals()[__func_name] = __get_hash(__func_name)
  File "/usr/lib/python3.10/hashlib.py", line 141, in __get_openssl_constructor
    return __get_builtin_constructor(name)
  File "/usr/lib/python3.10/hashlib.py", line 123, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type md5

Reference implementation is upstream openssl 3.3.0, with enable-fips, fipsinstall completed and openssl.cnf set to

# cat /etc/ssl/openssl.cnf 
config_diagnostics = 1
openssl_conf = openssl_init

.include /etc/ssl/fipsmodule.cnf

[openssl_init]
providers = provider_sect
alg_section = algorithm_sect

[provider_sect]
fips = fips_sect
base = base_sect

[base_sect]
activate = 1

[algorithm_sect]
default_properties = fips=yes

In essence, things work well only when "default + fips" providers are loaded, as then MD5 functions in OpenSSL are detected as available and are used at runtime and correctly get blocked.

When only "base + fips" providers are loaded, ValueError is raised by OpenSSL constructor, and instead fallback implementation used from _md5 module if it was compiled in.

It seems like the above configuration was not tested, however it can be made to work. CPython should try to load the "default" OpenSSL provider, to guarantee access to non-fips hashes.

Security concerns

This is FedRAMP/FIPS compliance by-pass. This issue may allow using md5 without specifying "usedforsecurity=False" on systems otherwise configured to be in FIPS-mode only. And is the primary reason why documentation mentions that certain distributors of python remove md5 module altogether.

CPython versions tested on:

3.10, 3.11, 3.12

Operating systems tested on:

Linux

Linked PRs
  • gh-118236
  • gh-118238
  • gh-118239
  • gh-118240
  • gh-118264
  • gh-127300

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 hashlib.py 中的 __get_openssl_constructor 和 __get_builtin_constructor 開始,接著檢查此處所述 OpenSSL base+fips provider 設定下的 _md5 fallback 路徑。繼續之前,先檢視相關 PR:gh-118236、gh-118238、gh-118239、gh-118240、gh-118264 和 gh-127300;當在此設定下匯入 hashlib 不再透過 fallback 啟用 MD5 時,即表示完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
cryptography, security
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。