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.
This commit is contained in:
@@ -30,8 +30,12 @@ import hashlib
|
|||||||
import hmac
|
import hmac
|
||||||
from typing import Union
|
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 .i18n import _
|
||||||
|
from .logging import get_logger
|
||||||
|
|
||||||
|
|
||||||
|
_logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
HAS_PYAES = False
|
HAS_PYAES = False
|
||||||
@@ -43,7 +47,12 @@ else:
|
|||||||
HAS_PYAES = True
|
HAS_PYAES = True
|
||||||
|
|
||||||
HAS_CRYPTODOME = False
|
HAS_CRYPTODOME = False
|
||||||
|
MIN_CRYPTODOME_VERSION = "3.7"
|
||||||
try:
|
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_Poly1305 as CD_ChaCha20_Poly1305
|
||||||
from Cryptodome.Cipher import ChaCha20 as CD_ChaCha20
|
from Cryptodome.Cipher import ChaCha20 as CD_ChaCha20
|
||||||
from Cryptodome.Cipher import AES as CD_AES
|
from Cryptodome.Cipher import AES as CD_AES
|
||||||
@@ -53,8 +62,12 @@ else:
|
|||||||
HAS_CRYPTODOME = True
|
HAS_CRYPTODOME = True
|
||||||
|
|
||||||
HAS_CRYPTOGRAPHY = False
|
HAS_CRYPTOGRAPHY = False
|
||||||
|
MIN_CRYPTOGRAPHY_VERSION = "2.1"
|
||||||
try:
|
try:
|
||||||
import cryptography
|
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 import exceptions
|
||||||
from cryptography.hazmat.primitives.ciphers import Cipher as CG_Cipher
|
from cryptography.hazmat.primitives.ciphers import Cipher as CG_Cipher
|
||||||
from cryptography.hazmat.primitives.ciphers import algorithms as CG_algorithms
|
from cryptography.hazmat.primitives.ciphers import algorithms as CG_algorithms
|
||||||
|
|||||||
Reference in New Issue
Block a user