electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 9bc4182924424bab2b1c11ef1e9c7f32ab6f2922
parent e4e6c4fb1ba967f8db5acc28bebc1ddabac3e21e
Author: SomberNight <somber.night@protonmail.com>
Date:   Thu, 15 Oct 2020 16:25:06 +0200

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.

Diffstat:
Melectrum/crypto.py | 15++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/electrum/crypto.py b/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