aboutsummaryrefslogtreecommitdiff
blob: e0ca3a012ea0b58f05feed3d394c4025159bae60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
diff --git a/keyrings/alt/file.py b/keyrings/alt/file.py
index 37c837f..866e8d0 100644
--- a/keyrings/alt/file.py
+++ b/keyrings/alt/file.py
@@ -44,8 +44,12 @@ class Encrypted:
         """
         Create the cipher object to encrypt or decrypt a payload.
         """
-        from Cryptodome.Protocol.KDF import PBKDF2
-        from Cryptodome.Cipher import AES
+        try:
+            from Cryptodome.Protocol.KDF import PBKDF2
+            from Cryptodome.Cipher import AES
+        except ImportError:
+            from Crypto.Protocol.KDF import PBKDF2
+            from Crypto.Cipher import AES
 
         pw = PBKDF2(password, salt, dkLen=self.block_size)
         return AES.new(pw[: self.block_size], AES.MODE_CFB, IV)
@@ -79,7 +83,12 @@ class EncryptedKeyring(Encrypted, Keyring):
             __import__('Cryptodome.Protocol.KDF')
             __import__('Cryptodome.Random')
         except ImportError:  # pragma: no cover
-            raise RuntimeError("pycryptodomex required")
+            try:
+                __import__('Crypto.Cipher.AES')
+                __import__('Crypto.Protocol.KDF')
+                __import__('Crypto.Random')
+            except ImportError:
+                raise RuntimeError("pycryptodomex or pycryptodome required")
         if not json:  # pragma: no cover
             raise RuntimeError("JSON implementation such as simplejson required.")
         return 0.6
@@ -190,10 +199,16 @@ class EncryptedKeyring(Encrypted, Keyring):
 
     def encrypt(self, password, assoc=None):
         # encrypt password, ignore associated data
-        from Cryptodome.Random import get_random_bytes
+        try:
+            from Cryptodome.Random import get_random_bytes
+        except ImportError:
+            from Crypto.Random import get_random_bytes
 
         salt = get_random_bytes(self.block_size)
-        from Cryptodome.Cipher import AES
+        try:
+            from Cryptodome.Cipher import AES
+        except ImportError:
+            from Crypto.Cipher import AES
 
         IV = get_random_bytes(AES.block_size)
         cipher = self._create_cipher(self.keyring_key, salt, IV)
diff --git a/tests/test_crypto.py b/tests/test_crypto.py
index cfc782a..7396023 100644
--- a/tests/test_crypto.py
+++ b/tests/test_crypto.py
@@ -14,7 +14,12 @@ def is_crypto_supported():
         __import__('Cryptodome.Protocol.KDF')
         __import__('Cryptodome.Random')
     except ImportError:
-        return False
+        try:
+            __import__('Crypto.Cipher.AES')
+            __import__('Crypto.Protocol.KDF')
+            __import__('Crypto.Random')
+        except ImportError:
+            return False
     return True
 
 
diff --git a/tests/test_file.py b/tests/test_file.py
index 62192da..3f813f0 100644
--- a/tests/test_file.py
+++ b/tests/test_file.py
@@ -157,7 +157,14 @@ class FileKeyringTests(BackendBasicTests):
 class TestEncryptedFileKeyring(FileKeyringTests):
     @pytest.fixture(autouse=True)
     def crypt_fixture(self, monkeypatch):
-        pytest.importorskip('Cryptodome')
+        try:
+            import Cryptodome
+        except ImportError:
+            try:
+                import Crypto
+            except ImportError:
+                pytest.skip("Neither pycryptodome nor pycryptodomex are available",
+                    allow_module_level=True)
         fake_getpass = mock.Mock(return_value='abcdef')
         monkeypatch.setattr(getpass, 'getpass', fake_getpass)