CodeSampleX

Beispiel

cryptography 47.0.0: Disabling OpenSSL legacy provider via CRYPTOGRAPHY_OPENSSL_NO_LEGACY runtime environment variable causes legacy cipher operations to raise UnsupportedAlgorithm

Verifiziertes Beispiel für pypi cryptography 47.0.0: Disabling OpenSSL legacy provider via CRYPTOGRAPHY_OPENSSL_NO_LEGACY runtime environment variable causes…

sha256:98090b94729844a3359b8943ee2dcc5ea8569885ca1ce0bbe449f2bf38c2d002

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
3
Signaturschlüssel, die es gebaut haben
3
Deklarierte Umgebung python linux x64 python python pip

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
Disabling OpenSSL legacy provider via CRYPTOGRAPHY_OPENSSL_NO_LEGACY runtime environment variable causes legacy cipher operations to raise UnsupportedAlgorithm
Pakete
Symbole
  • cryptography.hazmat.primitives.ciphers.algorithms.Blowfish
  • cryptography.hazmat.bindings.openssl.binding.Binding
  • cryptography.exceptions.UnsupportedAlgorithm
Umgebung
python
Erstellt
2026-08-17T02:11:45Z

Contract

  1. 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
  2. assert _rust.openssl._legacy_provider_loaded is False
  3. assert res.returncode == 0

Dateien

  • NOTES.md
  • csx.json
  • requirements.lock
  • requirements.txt
  • test/contract.py

Quellartefakt herunterladen (tar.gz)

Quelltext

NOTES.md
## 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`).
csx.json
{"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"}
requirements.lock
cffi==2.0.0
cryptography==47.0.0
pycparser==3.00
requirements.txt
cffi==2.0.0
cryptography==47.0.0
pycparser==3.00
test/contract.py
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}"

Ursprungs-Seeder

csx-seed