1 # This older version only exists because `ceph` needs it, see its package.
12 setuptoolsRustBuildHook,
31 cryptography-vectors = callPackage ./cryptography-vectors.nix { };
33 buildPythonPackage rec {
34 pname = "cryptography";
35 version = "40.0.1"; # Also update the hash in vectors.nix
36 format = "setuptools";
37 disabled = pythonOlder "3.6";
40 inherit pname version;
41 hash = "sha256-KAPy+LHpX2FEGZJsfm9V2CivxhTKXtYVQ4d65mjMNHI=";
44 cargoDeps = rustPlatform.fetchCargoTarball {
46 sourceRoot = "${pname}-${version}/${cargoRoot}";
47 name = "${pname}-${version}";
48 hash = "sha256-gFfDTc2QWBWHBCycVH1dYlCsWQMVcRZfOBIau+njtDU=";
51 # Since Cryptography v40 is quite outdated, we need to backport
52 # security fixes that are only available in newer versions.
54 # Fix https://nvd.nist.gov/vuln/detail/CVE-2023-49083 which has no upstream backport.
55 # See https://github.com/pyca/cryptography/commit/f09c261ca10a31fe41b1262306db7f8f1da0e48a#diff-f5134bf8f3cf0a5cc8601df55e50697acc866c603a38caff98802bd8e17976c5R1893
56 ./python-cryptography-Cherry-pick-fix-for-CVE-2023-49083-on-cryptography-40.patch
58 # Fix https://nvd.nist.gov/vuln/detail/CVE-2024-26130
59 # See https://github.com/pyca/cryptography/commit/97d231672763cdb5959a3b191e692a362f1b9e55
61 name = "python-cryptography-CVE-2024-26130-dont-crash-when-a-PKCS-12-key-and-cert-dont-match-mmap-mode.patch";
62 url = "https://github.com/pyca/cryptography/commit/97d231672763cdb5959a3b191e692a362f1b9e55.patch";
63 hash = "sha256-l45NOzOWhHW4nY4OIRpdjYQRvUW8BROGWdpkAtvVn0Y=";
68 substituteInPlace pyproject.toml \
69 --replace "--benchmark-disable" ""
72 cargoRoot = "src/rust";
75 rustPlatform.cargoSetupHook
76 setuptoolsRustBuildHook
80 ] ++ lib.optionals (!isPyPy) [ cffi ];
84 ++ lib.optionals stdenv.hostPlatform.isDarwin [
88 ++ lib.optionals (pythonOlder "3.9") [ libxcrypt ];
90 propagatedBuildInputs = lib.optionals (!isPyPy) [ cffi ];
103 pytestFlagsArray = [ "--disable-pytest-warnings" ];
107 # save compute time by not running benchmarks
110 ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [
111 # aarch64-darwin forbids W+X memory, but this tests depends on it:
112 # * https://cffi.readthedocs.io/en/latest/using.html#callbacks
113 "tests/hazmat/backends/test_openssl_memleak.py"
117 description = "A package which provides cryptographic recipes and primitives";
119 Cryptography includes both high level recipes and low level interfaces to
120 common cryptographic algorithms such as symmetric ciphers, message
121 digests, and key derivation functions.
122 Our goal is for it to be your "cryptographic standard library". It
123 supports Python 2.7, Python 3.5+, and PyPy 5.4+.
125 homepage = "https://github.com/pyca/cryptography";
127 "https://cryptography.io/en/latest/changelog/#v" + replaceStrings [ "." ] [ "-" ] version;
128 license = with licenses; [
133 maintainers = with maintainers; [ nh2 ];