Skip to content

Commit 7fbcf38

Browse files
committed
Enable keyfromlabel and enginepkcs11 systemtests with pkcs11-provider
- Simplify configuration management by deducing SoftHSM module path from openssl config - Determine the engine flag (-E) value from openssl config - Drop unused/unneeded environment variables - Run pkcs11-provider tests on Debian "sid" ossl3 flavor
1 parent 628dd27 commit 7fbcf38

File tree

13 files changed

+80
-27
lines changed

13 files changed

+80
-27
lines changed

.gitlab-ci.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -864,16 +864,23 @@ scan-build:
864864
when: on_failure
865865

866866
# Jobs for strict OpenSSL 3.x (no deprecated) GCC builds on Debian "sid" (amd64)
867+
# Run with pkcs11-provider tests
867868

868869
gcc:ossl3:sid:amd64:
869870
variables:
870871
CC: gcc
871872
CFLAGS: "${CFLAGS_COMMON} -O3 -DOPENSSL_NO_DEPRECATED=1 -DOPENSSL_API_COMPAT=30000"
873+
# See https://gitlab.isc.org/isc-projects/bind9/-/issues/3444
874+
EXTRA_CONFIGURE: "--without-jemalloc --disable-leak-detection"
872875
RUN_MAKE_INSTALL: 1
873876
<<: *debian_sid_amd64_image
874877
<<: *build_job
875878

876879
system:gcc:ossl3:sid:amd64:
880+
# Set up environment variables to run pkcs11-provider system tests
881+
variables:
882+
OPENSSL_CONF: "/var/tmp/etc/openssl-provider.cnf"
883+
SOFTHSM2_CONF: "/var/tmp/softhsm2/softhsm2.conf"
877884
<<: *debian_sid_amd64_image
878885
<<: *system_test_job
879886
needs:
@@ -1207,10 +1214,8 @@ gcc:bullseye:amd64:
12071214
system:gcc:bullseye:amd64:
12081215
# Set up environment variables that allow the "keyfromlabel" system test to be run
12091216
variables:
1210-
DEFAULT_OPENSSL_CONF: "/etc/ssl/openssl.cnf"
12111217
OPENSSL_CONF: "/var/tmp/etc/openssl.cnf"
12121218
SOFTHSM2_CONF: "/var/tmp/softhsm2/softhsm2.conf"
1213-
SOFTHSM2_MODULE: "/usr/lib/softhsm/libsofthsm2.so"
12141219
<<: *debian_bullseye_amd64_image
12151220
<<: *system_test_job
12161221
needs:
@@ -1240,10 +1245,8 @@ clang:bookworm:amd64:
12401245
system:clang:bookworm:amd64:
12411246
# Set up environment variables that allow the "keyfromlabel" system test to be run
12421247
variables:
1243-
DEFAULT_OPENSSL_CONF: "/etc/ssl/openssl.cnf"
12441248
OPENSSL_CONF: "/var/tmp/etc/openssl.cnf"
12451249
SOFTHSM2_CONF: "/var/tmp/softhsm2/softhsm2.conf"
1246-
SOFTHSM2_MODULE: "/usr/lib/softhsm/libsofthsm2.so"
12471250
<<: *debian_bookworm_amd64_image
12481251
<<: *system_test_job
12491252
needs:

bin/tests/system/conf.sh.common

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,3 +728,27 @@ copy_setports() {
728728
-e "s/@DISABLED_BITS@/${DISABLED_BITS}/g" \
729729
$1 > $2
730730
}
731+
732+
# parse_openssl_config - Parse OpenSSL configuration for HSM settings
733+
#
734+
# Will set SOFTHSM2_MODULE, OPENSSL_ENGINE and ENGINE_ARG based on openssl configuration.
735+
parse_openssl_config() {
736+
ENGINE_ARG=""
737+
[ -f "$OPENSSL_CONF" ] || return 0
738+
while IFS="=" read key val; do
739+
# trim variables
740+
key="${key## }"
741+
key="${key%% }"
742+
val="${val## }"
743+
val="${val%% }"
744+
case "$key" in
745+
"engine_id")
746+
OPENSSL_ENGINE="$val"
747+
ENGINE_ARG="-E $OPENSSL_ENGINE"
748+
;;
749+
"MODULE_PATH"|"pkcs11-module-path")
750+
SOFTHSM2_MODULE="$val"
751+
;;
752+
esac
753+
done < "$OPENSSL_CONF"
754+
}

bin/tests/system/enginepkcs11/clean.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ rm -f ns1/*.example.db ns1/*.example.db.signed
2626
rm -f ns1/*.kskid1 ns1/*.kskid2 ns1/*.zskid1 ns1/*.zskid2
2727
rm -f ns1/dig.out.*
2828
rm -f ns1/K*
29-
rm -f ns1/named.conf ns1/named.run ns1/named.memstats
29+
rm -f ns1/named.conf ns1/named.args ns1/named.run ns1/named.memstats
3030
rm -f ns1/update.cmd.*
3131
rm -f ns1/update.log.*
3232
rm -f ns1/verify.out.*
3333
rm -f ns1/zone.*.signed.jnl ns1/zone.*.signed.jbk
3434

35-
softhsm2-util --delete-token --token "softhsm2-enginepkcs11" >/dev/null 2>&1 || echo_i "softhsm2-enginepkcs11 token not found for cleaning"
35+
OPENSSL_CONF= softhsm2-util --delete-token --token "softhsm2-enginepkcs11" >/dev/null 2>&1 || echo_i "softhsm2-enginepkcs11 token not found for cleaning"

bin/tests/system/enginepkcs11/ns1/named.args

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@ENGINE_ARGS@ -D enginepkcs11-ns1 -X named.lock -m record -c named.conf -d 99 -U 4 -T maxcachesize=2097152

bin/tests/system/enginepkcs11/prereq.sh

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,20 @@
1313

1414
. ../conf.sh
1515

16-
if [ -n "${SOFTHSM2_MODULE}" ] && command -v softhsm2-util >/dev/null; then
17-
exit 0
18-
fi
16+
[ -n "${SOFTHSM2_CONF}" ] || {
17+
echo_i "skip: softhsm2 configuration not available"
18+
exit 255
19+
}
1920

20-
echo_i "skip: softhsm2-util not available"
21-
exit 255
21+
parse_openssl_config
22+
[ -f "$SOFTHSM2_MODULE" ] || {
23+
echo_i "skip: softhsm2 module not available"
24+
exit 1
25+
}
26+
27+
for _bin in softhsm2-util pkcs11-tool; do
28+
command -v "$_bin" >/dev/null || {
29+
echo_i "skip: $_bin not available"
30+
exit 1
31+
}
32+
done

bin/tests/system/enginepkcs11/setup.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616

1717
set -e
1818

19-
softhsm2-util --init-token --free --pin 1234 --so-pin 1234 --label "softhsm2-enginepkcs11" | awk '/^The token has been initialized and is reassigned to slot/ { print $NF }'
19+
OPENSSL_CONF= softhsm2-util --init-token --free --pin 1234 --so-pin 1234 --label "softhsm2-enginepkcs11" | awk '/^The token has been initialized and is reassigned to slot/ { print $NF }'
2020

2121
printf '%s' "${HSMPIN:-1234}" > pin
22+
parse_openssl_config
2223
PWD=$(pwd)
2324

2425
copy_setports ns1/named.conf.in ns1/named.conf
26+
sed -e "s/@ENGINE_ARGS@/${ENGINE_ARG}/g" < ns1/named.args.in > ns1/named.args
2527

2628
keygen() {
2729
type="$1"
@@ -31,7 +33,7 @@ keygen() {
3133

3234
label="${id}-${zone}"
3335
p11id=$(echo "${label}" | openssl sha1 -r | awk '{print $1}')
34-
pkcs11-tool --module $SOFTHSM2_MODULE --token-label "softhsm2-enginepkcs11" -l -k --key-type $type:$bits --label "${label}" --id "${p11id}" --pin $(cat $PWD/pin) > pkcs11-tool.out.$zone.$id 2> pkcs11-tool.err.$zone.$id || return 1
36+
OPENSSL_CONF= pkcs11-tool --module $SOFTHSM2_MODULE --token-label "softhsm2-enginepkcs11" -l -k --key-type $type:$bits --label "${label}" --id "${p11id}" --pin $(cat $PWD/pin) > pkcs11-tool.out.$zone.$id 2> pkcs11-tool.err.$zone.$id || return 1
3537
}
3638

3739
keyfromlabel() {
@@ -41,7 +43,7 @@ keyfromlabel() {
4143
dir="$4"
4244
shift 4
4345

44-
$KEYFRLAB -K $dir -E pkcs11 -a $alg -l "token=softhsm2-enginepkcs11;object=${id}-${zone};pin-source=$PWD/pin" "$@" $zone >> keyfromlabel.out.$zone.$id 2> keyfromlabel.err.$zone.$id || return 1
46+
$KEYFRLAB $ENGINE_ARG -K $dir -a $alg -l "pkcs11:token=softhsm2-enginepkcs11;object=${id}-${zone};pin-source=$PWD/pin" "$@" $zone >> keyfromlabel.out.$zone.$id 2> keyfromlabel.err.$zone.$id || return 1
4547
cat keyfromlabel.out.$zone.$id
4648
}
4749

@@ -86,7 +88,7 @@ do
8688

8789
echo_i "Sign zone with $ksk1 $zsk1"
8890
cat "$infile" "${dir}/${ksk1}.key" "${dir}/${zsk1}.key" > "${dir}/${zonefile}"
89-
$SIGNER -K $dir -E pkcs11 -S -a -g -O full -o "$zone" "${dir}/${zonefile}" > signer.out.$zone || ret=1
91+
$SIGNER $ENGINE_ARG -K $dir -S -a -g -O full -o "$zone" "${dir}/${zonefile}" > signer.out.$zone || ret=1
9092
test "$ret" -eq 0 || exit 1
9193

9294
echo_i "Generate successor keys $alg $type:$bits for zone $zone"

bin/tests/system/enginepkcs11/tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set -e
1616
# shellcheck source=conf.sh
1717
. ../conf.sh
1818

19+
parse_openssl_config
1920
PWD=$(pwd)
2021

2122
status=0

bin/tests/system/keyfromlabel/clean.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ rm -f keyfromlabel.out.*
2424
rm -f pkcs11-tool.out.*
2525
rm -f signer.out.*
2626

27-
softhsm2-util --delete-token --token "softhsm2-keyfromlabel" >/dev/null 2>&1 || echo_i "softhsm2-keyfromlabel token not found for cleaning"
27+
OPENSSL_CONF= softhsm2-util --delete-token --token "softhsm2-keyfromlabel" >/dev/null 2>&1 || echo_i "softhsm2-keyfromlabel token not found for cleaning"

bin/tests/system/keyfromlabel/prereq.sh

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,20 @@
1313

1414
. ../conf.sh
1515

16-
if [ -n "${SOFTHSM2_MODULE}" ] && command -v pkcs11-tool >/dev/null && command -v softhsm2-util >/dev/null; then
17-
exit 0
18-
fi
16+
[ -n "${SOFTHSM2_CONF}" ] || {
17+
echo_i "skip: softhsm2 configuration not available"
18+
exit 255
19+
}
1920

20-
echo_i "skip: softhsm2-util or pkcs11-tool not available"
21-
exit 255
21+
parse_openssl_config
22+
[ -f "$SOFTHSM2_MODULE" ] || {
23+
echo_i "skip: softhsm2 module not available"
24+
exit 1
25+
}
26+
27+
for _bin in softhsm2-util pkcs11-tool; do
28+
command -v "$_bin" >/dev/null || {
29+
echo_i "skip: $_bin not available"
30+
exit 1
31+
}
32+
done

0 commit comments

Comments
 (0)