PACSign: output more info when libcrypto not found
When the openssl hsm_manager fails to find libcrypto.so, output a
message describing the packages required to install the library.
@@ -76,6 +76,12 @@ PEM_PASSWORD_WARNING = """The specified password is considered insecure.
openssl ec -in <input PEM> -out <output PEM> -aes256
"""
+LIBCRYPTO_MSG = """Failed to find crypto library (libcrypto.so).
+
+For RedHat-based distros, install package openssl-devel.
+For Debian-based distros, install package libssl-dev.
+"""
+
class CURVE_INFO:
def __init__(
@@ -285,9 +291,13 @@ class OPENSSL_AES_KEY(Structure):
class openssl:
# Look for something like: OpenSSL 1.1.1d FIPS 10 Sep 2019
def _find_openssl_so(self, versions):
- crypto = util.find_library('crypto')
+ for link, vers in versions:
+ try:
+ dll = CDLL(link)
+ except OSError:
+ common_util.assert_in_error(False, LIBCRYPTO_MSG)
+ return None
- dll = CDLL(crypto)
if dll is None:
log.warn('could not open: %s', crypto)
return None
@@ -304,15 +314,14 @@ class openssl:
log.warn('"%s" is not a valid OpenSSL version', c_version)
return None
- for version in versions:
- if m.group('version')[:-1] == version:
- log.info('OpenSSL version "%s" matches "%s"', c_version, version)
+ if m.group('version')[:-1] == vers:
+ log.info('OpenSSL version "%s" matches "%s"', c_version, vers)
return dll
log.debug('OpenSSL version "%s" fails to match "%s"',
- c_version, version)
+ c_version, vers)
- def __init__(self, versions=['1.1.1']):
+ def __init__(self, versions=[('libcrypto.so.1.1', '1.1.1')]):
self.nanotime = None
if _platform == "win32" or _platform == "win64":
@@ -320,7 +329,7 @@ class openssl:
return
self.lib = self._find_openssl_so(versions)
- common_util.assert_in_error(self.lib, "Failed to find crypto library")
+ common_util.assert_in_error(self.lib, LIBCRYPTO_MSG)
# Initialize OPEN algorithm
self.lib.OPENSSL_init_crypto.argtypes = [c_uint, c_void_p]
@@ -579,7 +588,7 @@ class openssl:
def close(self):
- if self.lib is not None:
+ if hasattr(self, 'lib') and self.lib is not None:
del self.lib
self.lib = None
