Skip to content

Commit da0c0dc

Browse files
committed
crypt: use the py3 builtin openssl
With Python 3.7+, the Python installer has the libcrypto and libssl dlls in the DLLs Python folder, namely libcrypto-1_1.dll and libssl-1_1.dll, which can be used directly. Change-Id: I245c377dc8a9ec9a2e8548806bacd757bfdf27b6
1 parent 072bee9 commit da0c0dc

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

cloudbaseinit/utils/crypt.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,20 @@
2626
else:
2727
clib = ctypes.cdll.ucrtbase
2828

29-
# Note(mbivolan): The library name has changed in OpenSSL 1.1.0
30-
# Keeping the old name for backward compatibility
31-
try:
32-
openssl = ctypes.cdll.libeay32
33-
except Exception:
34-
openssl = ctypes.cdll.libcrypto
29+
# for backwards compatibility, try the older names
30+
# libcrypto-1_1 comes bundled with PY 3.7 to 3.12
31+
ssl_lib_names = [
32+
"libcrypto-1_1",
33+
"libcrypto",
34+
"libeay32"
35+
]
36+
37+
for ssl_lib_name in ssl_lib_names:
38+
try:
39+
openssl = ctypes.CDLL(ssl_lib_name)
40+
break
41+
except Exception:
42+
pass
3543
else:
3644
clib = ctypes.CDLL(clib_path)
3745
openssl_lib_path = ctypes.util.find_library("ssl")
@@ -64,6 +72,7 @@ class RSA(ctypes.Structure):
6472
("mt_blinding", ctypes.c_void_p)
6573
]
6674

75+
6776
openssl.RSA_PKCS1_PADDING = 1
6877

6978
openssl.RSA_new.restype = ctypes.POINTER(RSA)

0 commit comments

Comments
 (0)