From c0d1843aa5cd25f131f529e13837e1bb9142e130 Mon Sep 17 00:00:00 2001 From: Camillo Lugaresi Date: Tue, 27 Aug 2024 12:27:17 -0700 Subject: [PATCH] Ignore a libcrypto.dylib with the wrong architecture If you install Homebrew with arch -x86_64, you get a /usr/local/lib/libcrypto.dylib that the system Python can't load. We should ignore the resulting error and proceed without that library (which does not ship with the OS any more). The error looks like: OSError: cannot load library '/usr/local/lib/libcrypto.dylib': dlopen(/usr/local/lib/libcrypto.dylib, 0x0002): tried: '/usr/local/lib/libcrypto.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/lib/libcrypto.dylib' (no such file), '/usr/local/lib/libcrypto.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')), '/usr/local/Cellar/openssl@3/3.3.1/lib/libcrypto.3.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/Cellar/openssl@3/3.3.1/lib/libcrypto.3.dylib' (no such file), '/usr/local/Cellar/openssl@3/3.3.1/lib/libcrypto.3.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')) --- oscrypto/_mac/util.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/oscrypto/_mac/util.py b/oscrypto/_mac/util.py index 34cc8c0..730b27a 100644 --- a/oscrypto/_mac/util.py +++ b/oscrypto/_mac/util.py @@ -348,6 +348,10 @@ def pkcs12_kdf(hash_algorithm, password, salt, iterations, key_length, id_): return bytes_from_buffer(output_buffer) -except (LibraryNotFoundError): +except (LibraryNotFoundError, OSError): + # OpenSSL no longer ships with macOS. If you install Homebrew with arch -x86_64, you end + # up with a /usr/local/lib/libcrypto.dylib that will not work with an arm64 Python, and + # will fail to load with an OSError. In that case, we should still fall back as if it + # were missing. from .._pkcs12 import pkcs12_kdf