Skip to content

Commit 7e683d4

Browse files
authored
Set mac_iter to OpenSSL's default
On OpenSSL 3, it uses 2048 iterations for mac_iter by default. We've been doing this with NoEncryption for two years, so I guess it's fine now and the comment is out of date.
1 parent 7c0b5b5 commit 7e683d4

File tree

1 file changed

+3
-6
lines changed
  • src/cryptography/hazmat/backends/openssl

1 file changed

+3
-6
lines changed

src/cryptography/hazmat/backends/openssl/backend.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ def serialize_key_and_certificates_to_pkcs12(
410410
nid_cert = -1
411411
nid_key = -1
412412
pkcs12_iter = 0
413+
# mac_iter of 0 uses OpenSSL's default value
413414
mac_iter = 0
414415
mac_alg = self._ffi.NULL
415416
elif isinstance(
@@ -426,10 +427,7 @@ def serialize_key_and_certificates_to_pkcs12(
426427
nid_key = self._lib.NID_pbe_WithSHA1And3_Key_TripleDES_CBC
427428
# At least we can set this higher than OpenSSL's default
428429
pkcs12_iter = 20000
429-
# mac_iter chosen for compatibility reasons, see:
430-
# https://www.openssl.org/docs/man1.1.1/man3/PKCS12_create.html
431-
# Did we mention how lousy PKCS12 encryption is?
432-
mac_iter = 1
430+
mac_iter = 0
433431
# MAC algorithm can only be set on OpenSSL 3.0.0+
434432
mac_alg = self._ffi.NULL
435433
password = encryption_algorithm.password
@@ -446,8 +444,7 @@ def serialize_key_and_certificates_to_pkcs12(
446444
nid_key = 0
447445
# Use the default iters we use in best available
448446
pkcs12_iter = 20000
449-
# See the Best Available comment for why this is 1
450-
mac_iter = 1
447+
mac_iter = 0
451448
password = encryption_algorithm.password
452449
keycertalg = encryption_algorithm._key_cert_algorithm
453450
if keycertalg is PBES.PBESv1SHA1And3KeyTripleDESCBC:

0 commit comments

Comments
 (0)