サンプル
cryptography 47.0.0: Disabling OpenSSL legacy provider via CRYPTOGRAPHY_OPENSSL_NO_LEGACY runtime environment variable causes legacy cipher operations to raise UnsupportedAlgorithm
検証済みサンプル — pypi cryptography 47.0.0: Disabling OpenSSL legacy provider via CRYPTOGRAPHY_OPENSSL_NO_LEGACY runtime environment variable causes legacy cipher…
sha256:98090b94729844a3359b8943ee2dcc5ea8569885ca1ce0bbe449f2bf38c2d002
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 3
- ビルドした署名鍵
- 3
宣言された環境
python linux x64 python python pip
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| python 3.12 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1 |
2026-08-17 |
| python 3.12 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1 |
2026-08-18 |
| python 3.12 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1python:3.12-slim@sha256:09f7da3bc104… |
2026-09-08 |
ケース
HOW- ゴール
- Disabling OpenSSL legacy provider via CRYPTOGRAPHY_OPENSSL_NO_LEGACY runtime environment variable causes legacy cipher operations to raise UnsupportedAlgorithm
- パッケージ
- シンボル
-
- cryptography.hazmat.primitives.ciphers.algorithms.Blowfish
- cryptography.hazmat.bindings.openssl.binding.Binding
- cryptography.exceptions.UnsupportedAlgorithm
- 環境
- python
- 作成日
- 2026-08-17T02:11:45Z
コントラクト
- Setting CRYPTOGRAPHY_OPENSSL_NO_LEGACY=1 before cryptography OpenSSL binding initialization prevents loading the OpenSSL legacy provider, causing Blowfish cipher encryptor creation to raise UnsupportedAlgorithm
- assert _rust.openssl._legacy_provider_loaded is False
- assert res.returncode == 0
ファイル
- NOTES.md
- csx.json
- requirements.lock
- requirements.txt
- test/contract.py
ソース
## cryptography OpenSSL Legacy Provider Configuration
The initial search for prior solutions returned sample `sha256:b98c885c2365fa2de56dab1eea1087f3137ec69c260717f69d7ade5d27bee868`, which addresses Rust native extension compilation requirements for source builds on musl toolchains.
### Behavior and Runtime Impact
Developers and language models often assume that `CRYPTOGRAPHY_OPENSSL_NO_LEGACY` is a build-time compiler flag evaluated during package installation, or that setting environment variables inside Python script execution will dynamically toggle OpenSSL provider availability at any point.
In reality, `CRYPTOGRAPHY_OPENSSL_NO_LEGACY` is a runtime environment variable inspected when `cryptography.hazmat.bindings.openssl.binding` initializes OpenSSL binding locks.
- **Pre-initialization setting**: When `os.environ["CRYPTOGRAPHY_OPENSSL_NO_LEGACY"] = "1"` is set before OpenSSL bindings initialize, `cryptography` skips loading OpenSSL 3's `legacy` provider (`_legacy_provider_loaded` is `False`). Attempting to instantiate encryptor or decryptor contexts for legacy algorithms such as `Blowfish`, `CAST5`, `IDEA`, `SEED`, or `ARC4` fails loudly with `cryptography.exceptions.UnsupportedAlgorithm`.
- **Post-initialization setting**: Setting `os.environ["CRYPTOGRAPHY_OPENSSL_NO_LEGACY"] = "1"` after `cryptography.hazmat.bindings.openssl.binding` has already loaded has no effect on currently initialized bindings because legacy provider loading occurs once at binding import time (`_legacy_provider_loaded` remains `True`).
{"case":{"believed":"CRYPTOGRAPHY_OPENSSL_NO_LEGACY is a build-time compilation flag rather than a runtime environment variable evaluated when OpenSSL bindings initialize.","caseId":"case:sha256:adcc63eaef1614abf253c713062196edc9c78eec0d532409cdc845c98a51319b","contract":["Setting CRYPTOGRAPHY_OPENSSL_NO_LEGACY=1 before cryptography OpenSSL binding initialization prevents loading the OpenSSL legacy provider, causing Blowfish cipher encryptor creation to raise UnsupportedAlgorithm","assert _rust.openssl._legacy_provider_loaded is False","assert res.returncode == 0"],"goal":"Disabling OpenSSL legacy provider via CRYPTOGRAPHY_OPENSSL_NO_LEGACY runtime environment variable causes legacy cipher operations to raise UnsupportedAlgorithm","kind":"HOW","packages":["pkg:pypi/cryptography@47.0.0"],"schemaVersion":1,"symbols":["cryptography.hazmat.primitives.ciphers.algorithms.Blowfish","cryptography.hazmat.bindings.openssl.binding.Binding","cryptography.exceptions.UnsupportedAlgorithm"]},"contractCommand":["python","test/contract.py"],"environment":{"arch":"x64","ecosystem":"pypi","executionContext":"python","language":"python","os":"linux","packageManager":"pip","runtime":"python","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/cryptography@47.0.0"],"schemaVersion":1,"symbols":["cryptography.hazmat.primitives.ciphers.algorithms.Blowfish","cryptography.hazmat.bindings.openssl.binding.Binding","cryptography.exceptions.UnsupportedAlgorithm"],"verifierAdapter":"python@1"}
cffi==2.0.0
cryptography==47.0.0
pycparser==3.00
cffi==2.0.0
cryptography==47.0.0
pycparser==3.00
import os
import sys
import subprocess
from cryptography.exceptions import UnsupportedAlgorithm
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
import cryptography.hazmat.bindings._rust as _rust
# 1. Default behavior (without CRYPTOGRAPHY_OPENSSL_NO_LEGACY set):
# OpenSSL legacy provider is loaded and legacy ciphers (Blowfish) work.
assert _rust.openssl._legacy_provider_loaded is True
key = b"0123456789abcdef"
cipher = Cipher(algorithms.Blowfish(key), modes.ECB())
enc = cipher.encryptor()
ct = enc.update(b"12345678") + enc.finalize()
dec = cipher.decryptor()
pt = dec.update(ct) + dec.finalize()
assert pt == b"12345678"
# 2. Setting CRYPTOGRAPHY_OPENSSL_NO_LEGACY=1 prior to binding initialization
# disables loading the OpenSSL legacy provider and causes Blowfish encryptor
# creation to raise UnsupportedAlgorithm.
no_legacy_code = """
import os
import sys
os.environ["CRYPTOGRAPHY_OPENSSL_NO_LEGACY"] = "1"
import cryptography.hazmat.bindings._rust as _rust
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.exceptions import UnsupportedAlgorithm
assert _rust.openssl._legacy_provider_loaded is False
c = Cipher(algorithms.Blowfish(b"0123456789abcdef"), modes.ECB())
try:
c.encryptor()
sys.exit(1)
except UnsupportedAlgorithm:
sys.exit(0)
"""
res = subprocess.run(
[sys.executable, "-c", no_legacy_code],
capture_output=True,
text=True,
)
assert res.returncode == 0, f"Subprocess failed with stderr: {res.stderr}"
# 3. Setting CRYPTOGRAPHY_OPENSSL_NO_LEGACY=1 AFTER binding initialization
# has no effect because legacy provider loading occurs at import time.
post_init_code = """
import os
import sys
import cryptography.hazmat.bindings.openssl.binding
os.environ["CRYPTOGRAPHY_OPENSSL_NO_LEGACY"] = "1"
import cryptography.hazmat.bindings._rust as _rust
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
assert _rust.openssl._legacy_provider_loaded is True
c = Cipher(algorithms.Blowfish(b"0123456789abcdef"), modes.ECB())
enc = c.encryptor()
assert enc is not None
"""
res_post = subprocess.run(
[sys.executable, "-c", post_init_code],
capture_output=True,
text=True,
)
assert res_post.returncode == 0, f"Post-init subprocess failed with stderr: {res_post.stderr}"