From 9eb9bb893e758896552357f2ebcaec1a4b02f5dc Mon Sep 17 00:00:00 2001 From: Clemens Lang Date: Wed, 25 Jan 2023 17:55:24 +0100 Subject: [PATCH] tests/softhsm: Search library near softhsm2-util On macOS, libsofthsm2.so might be installed in /usr/local/lib/libsofthsm2.so, /opt/local/lib/libsofthsm2.so, somewhere in /usr/local/Cellar/softhsm, or on Apple Silicon in /opt/homebrew/lib/libsofths2.so. Simplify searching for it by using $PATH, which we know must already contain softhsm2-util, and then attempt to identify the library relative to that. Signed-off-by: Clemens Lang --- tests/setup-softhsm.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/setup-softhsm.sh b/tests/setup-softhsm.sh index 74119f4f..5dc7a014 100755 --- a/tests/setup-softhsm.sh +++ b/tests/setup-softhsm.sh @@ -28,7 +28,21 @@ find_softhsm() { } title SECTION "Searching for SoftHSM PKCS#11 library" +# Attempt to guess the path to libsofthsm2.so relative to that. This fixes +# auto-detection on platforms such as macOS with MacPorts (and potentially +# Homebrew). +# +# This should never be empty, since we checked for the presence of +# softhsm2-util above and use it below. + +# Strip bin/softhsm2-util +softhsm_prefix=$(dirname "$(dirname "$(type -p softhsm2-util)")") + find_softhsm \ + "$softhsm_prefix/lib64/softhsm/libsofthsm2.so" \ + "$softhsm_prefix/lib/softhsm/libsofthsm2.so" \ + "$softhsm_prefix/lib64/pkcs11/libsofthsm2.so" \ + "$softhsm_prefix/lib/pkcs11/libsofthsm2.so" \ /usr/local/lib/softhsm/libsofthsm2.so \ /usr/lib64/pkcs11/libsofthsm2.so \ /usr/lib/pkcs11/libsofthsm2.so \