Browse Source
crypto: check version of pycryptodomex/cryptography at runtime
As these pkgs are often provided by the OS package manager (e.g. apt),
the version limits specified in requirements*.txt and setup.py will never
get applied.
patch-4
SomberNight
4 years ago
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
1 changed files with
14 additions and
1 deletions
electrum/crypto.py
@ -30,8 +30,12 @@ import hashlib
import hmac
from typing import Union
from . util import assert_bytes , InvalidPassword , to_bytes , to_string , WalletFileException
from . util import assert_bytes , InvalidPassword , to_bytes , to_string , WalletFileException , versiontuple
from . i18n import _
from . logging import get_logger
_logger = get_logger ( __name__ )
HAS_PYAES = False
@ -43,7 +47,12 @@ else:
HAS_PYAES = True
HAS_CRYPTODOME = False
MIN_CRYPTODOME_VERSION = " 3.7 "
try :
import Cryptodome
if versiontuple ( Cryptodome . __version__ ) < versiontuple ( MIN_CRYPTODOME_VERSION ) :
_logger . warning ( f " found module ' Cryptodome ' but it is too old: { Cryptodome . __version__ } < { MIN_CRYPTODOME_VERSION } " )
raise Exception ( )
from Cryptodome . Cipher import ChaCha20_Poly1305 as CD_ChaCha20_Poly1305
from Cryptodome . Cipher import ChaCha20 as CD_ChaCha20
from Cryptodome . Cipher import AES as CD_AES
@ -53,8 +62,12 @@ else:
HAS_CRYPTODOME = True
HAS_CRYPTOGRAPHY = False
MIN_CRYPTOGRAPHY_VERSION = " 2.1 "
try :
import cryptography
if versiontuple ( cryptography . __version__ ) < versiontuple ( MIN_CRYPTOGRAPHY_VERSION ) :
_logger . warning ( f " found module ' cryptography ' but it is too old: { cryptography . __version__ } < { MIN_CRYPTOGRAPHY_VERSION } " )
raise Exception ( )
from cryptography import exceptions
from cryptography . hazmat . primitives . ciphers import Cipher as CG_Cipher
from cryptography . hazmat . primitives . ciphers import algorithms as CG_algorithms