|
48 | 48 | builtin_hashlib = None
|
49 | 49 |
|
50 | 50 | try:
|
51 |
| - from _hashlib import HASH, HASHXOF, openssl_md_meth_names |
| 51 | + from _hashlib import HASH, HASHXOF, openssl_md_meth_names, get_fips_mode |
52 | 52 | except ImportError:
|
53 | 53 | HASH = None
|
54 | 54 | HASHXOF = None
|
55 | 55 | openssl_md_meth_names = frozenset()
|
56 | 56 |
|
| 57 | + def get_fips_mode(): |
| 58 | + return 0 |
| 59 | + |
57 | 60 | try:
|
58 | 61 | import _blake2
|
59 | 62 | except ImportError:
|
@@ -192,10 +195,7 @@ def hash_constructors(self):
|
192 | 195 |
|
193 | 196 | @property
|
194 | 197 | def is_fips_mode(self):
|
195 |
| - if hasattr(self._hashlib, "get_fips_mode"): |
196 |
| - return self._hashlib.get_fips_mode() |
197 |
| - else: |
198 |
| - return None |
| 198 | + return get_fips_mode() |
199 | 199 |
|
200 | 200 | def test_hash_array(self):
|
201 | 201 | a = array.array("b", range(10))
|
@@ -1017,7 +1017,7 @@ def _test_pbkdf2_hmac(self, pbkdf2, supported):
|
1017 | 1017 | self.assertEqual(out, expected,
|
1018 | 1018 | (digest_name, password, salt, rounds))
|
1019 | 1019 |
|
1020 |
| - with self.assertRaisesRegex(ValueError, 'unsupported hash type'): |
| 1020 | + with self.assertRaisesRegex(ValueError, '.*unsupported.*'): |
1021 | 1021 | pbkdf2('unknown', b'pass', b'salt', 1)
|
1022 | 1022 |
|
1023 | 1023 | if 'sha1' in supported:
|
@@ -1057,6 +1057,7 @@ def test_pbkdf2_hmac_c(self):
|
1057 | 1057 |
|
1058 | 1058 | @unittest.skipUnless(hasattr(hashlib, 'scrypt'),
|
1059 | 1059 | ' test requires OpenSSL > 1.1')
|
| 1060 | + @unittest.skipIf(get_fips_mode(), reason="scrypt is blocked in FIPS mode") |
1060 | 1061 | def test_scrypt(self):
|
1061 | 1062 | for password, salt, n, r, p, expected in self.scrypt_test_vectors:
|
1062 | 1063 | result = hashlib.scrypt(password, salt=salt, n=n, r=r, p=p)
|
|
0 commit comments