2024-09-19 14:19:46 +00:00
# This older version only exists because `ceph` needs it, see its package.
{
lib ,
stdenv ,
callPackage ,
buildPythonPackage ,
fetchPypi ,
fetchpatch ,
rustPlatform ,
cargo ,
rustc ,
setuptoolsRustBuildHook ,
openssl ,
Security ? null ,
isPyPy ,
cffi ,
pkg-config ,
pytestCheckHook ,
pytest-subtests ,
pythonOlder ,
pretend ,
libiconv ,
libxcrypt ,
iso8601 ,
py ,
pytz ,
hypothesis ,
} :
let
cryptography-vectors = callPackage ./cryptography-vectors.nix { } ;
in
buildPythonPackage rec {
pname = " c r y p t o g r a p h y " ;
version = " 4 0 . 0 . 1 " ; # Also update the hash in vectors.nix
format = " s e t u p t o o l s " ;
disabled = pythonOlder " 3 . 6 " ;
src = fetchPypi {
inherit pname version ;
hash = " s h a 2 5 6 - K A P y + L H p X 2 F E G Z J s f m 9 V 2 C i v x h T K X t Y V Q 4 d 6 5 m j M N H I = " ;
} ;
cargoDeps = rustPlatform . fetchCargoTarball {
inherit src ;
sourceRoot = " ${ pname } - ${ version } / ${ cargoRoot } " ;
name = " ${ pname } - ${ version } " ;
hash = " s h a 2 5 6 - g F f D T c 2 Q W B W H B C y c V H 1 d Y l C s W Q M V c R Z f O B I a u + n j t D U = " ;
} ;
# Since Cryptography v40 is quite outdated, we need to backport
# security fixes that are only available in newer versions.
patches = [
# Fix https://nvd.nist.gov/vuln/detail/CVE-2023-49083 which has no upstream backport.
# See https://github.com/pyca/cryptography/commit/f09c261ca10a31fe41b1262306db7f8f1da0e48a#diff-f5134bf8f3cf0a5cc8601df55e50697acc866c603a38caff98802bd8e17976c5R1893
./python-cryptography-Cherry-pick-fix-for-CVE-2023-49083-on-cryptography-40.patch
# Fix https://nvd.nist.gov/vuln/detail/CVE-2024-26130
# See https://github.com/pyca/cryptography/commit/97d231672763cdb5959a3b191e692a362f1b9e55
( fetchpatch {
name = " p y t h o n - c r y p t o g r a p h y - C V E - 2 0 2 4 - 2 6 1 3 0 - d o n t - c r a s h - w h e n - a - P K C S - 1 2 - k e y - a n d - c e r t - d o n t - m a t c h - m m a p - m o d e . p a t c h " ;
url = " h t t p s : / / g i t h u b . c o m / p y c a / c r y p t o g r a p h y / c o m m i t / 9 7 d 2 3 1 6 7 2 7 6 3 c d b 5 9 5 9 a 3 b 1 9 1 e 6 9 2 a 3 6 2 f 1 b 9 e 5 5 . p a t c h " ;
hash = " s h a 2 5 6 - l 4 5 N O z O W h H W 4 n Y 4 O I R p d j Y Q R v U W 8 B R O G W d p k A t v V n 0 Y = " ;
} )
] ;
postPatch = ''
substituteInPlace pyproject . toml \
- - replace " - - b e n c h m a r k - d i s a b l e " " "
'' ;
cargoRoot = " s r c / r u s t " ;
nativeBuildInputs = [
rustPlatform . cargoSetupHook
setuptoolsRustBuildHook
cargo
rustc
pkg-config
] ++ lib . optionals ( ! isPyPy ) [ cffi ] ;
buildInputs =
[ openssl ]
2024-09-26 11:04:55 +00:00
++ lib . optionals stdenv . hostPlatform . isDarwin [
2024-09-19 14:19:46 +00:00
Security
libiconv
]
++ lib . optionals ( pythonOlder " 3 . 9 " ) [ libxcrypt ] ;
propagatedBuildInputs = lib . optionals ( ! isPyPy ) [ cffi ] ;
nativeCheckInputs = [
cryptography-vectors
hypothesis
iso8601
pretend
py
pytestCheckHook
pytest-subtests
pytz
] ;
pytestFlagsArray = [ " - - d i s a b l e - p y t e s t - w a r n i n g s " ] ;
disabledTestPaths =
[
# save compute time by not running benchmarks
" t e s t s / b e n c h "
]
2024-09-26 11:04:55 +00:00
++ lib . optionals ( stdenv . hostPlatform . isDarwin && stdenv . hostPlatform . isAarch64 ) [
2024-09-19 14:19:46 +00:00
# aarch64-darwin forbids W+X memory, but this tests depends on it:
# * https://cffi.readthedocs.io/en/latest/using.html#callbacks
" t e s t s / h a z m a t / b a c k e n d s / t e s t _ o p e n s s l _ m e m l e a k . p y "
] ;
meta = with lib ; {
description = " A p a c k a g e w h i c h p r o v i d e s c r y p t o g r a p h i c r e c i p e s a n d p r i m i t i v e s " ;
longDescription = ''
Cryptography includes both high level recipes and low level interfaces to
common cryptographic algorithms such as symmetric ciphers , message
digests , and key derivation functions .
Our goal is for it to be your " c r y p t o g r a p h i c s t a n d a r d l i b r a r y " . It
supports Python 2 .7 , Python 3 .5 + , and PyPy 5 .4 + .
'' ;
homepage = " h t t p s : / / g i t h u b . c o m / p y c a / c r y p t o g r a p h y " ;
changelog =
" h t t p s : / / c r y p t o g r a p h y . i o / e n / l a t e s t / c h a n g e l o g / # v " + replaceStrings [ " . " ] [ " - " ] version ;
license = with licenses ; [
asl20
bsd3
psfl
] ;
maintainers = with maintainers ; [ nh2 ] ;
} ;
}