Use unique SoftHSMv2 token label for the "keyfromlabel" test

When there are more than one tokens initialized in SoftHSMv2,
care must be taken to correctly identify them.

Use a SoftHSMv2 token label which will uniquely identify the
token used for this test.

Use the "--token-label" parameter for the `pkcs11-tool` program
to make sure that it finds and uses the correct token.

(cherry picked from commit a449709441)
This commit is contained in:
Aram Sargsyan 2022-02-03 10:59:45 +00:00 committed by Matthijs Mekking
parent b3e5e12ddf
commit 25cb2704b4
3 changed files with 4 additions and 4 deletions

View file

@ -24,4 +24,4 @@ rm -f keyfromlabel.out.*
rm -f pkcs11-tool.out.*
rm -f signer.out.*
softhsm2-util --delete-token --token "softhsm2" || echo_i "softhsm2 token not found"
softhsm2-util --delete-token --token "softhsm2-keyfromlabel" >/dev/null 2>&1 || echo_i "softhsm2-keyfromlabel token not found for cleaning"

View file

@ -16,7 +16,7 @@
set -e
softhsm2-util --init-token --free --pin 1234 --so-pin 1234 --label "softhsm2" | awk '/^The token has been initialized and is reassigned to slot/ { print $NF }'
softhsm2-util --init-token --free --pin 1234 --so-pin 1234 --label "softhsm2-keyfromlabel" | awk '/^The token has been initialized and is reassigned to slot/ { print $NF }'
printf '%s' "${HSMPIN:-1234}" > pin
PWD=$(pwd)

View file

@ -24,7 +24,7 @@ keygen() {
label="${id}-${zone}"
p11id=$(echo "${label}" | sha1sum - | awk '{print $1}')
pkcs11-tool --module $SOFTHSM2_MODULE -l -k --key-type $type:$bits --label "${label}" --id "${p11id//$'\n'/}" --pin $(cat $PWD/pin) > pkcs11-tool.out.$zone.$id || return 1
pkcs11-tool --module $SOFTHSM2_MODULE --token-label "softhsm2-keyfromlabel" -l -k --key-type $type:$bits --label "${label}" --id "${p11id//$'\n'/}" --pin $(cat $PWD/pin) > pkcs11-tool.out.$zone.$id || return 1
}
keyfromlabel() {
@ -33,7 +33,7 @@ keyfromlabel() {
id="$3"
shift 3
$KEYFRLAB -E pkcs11 -a $alg -l "token=softhsm2;object=${id}-${zone};pin-source=$PWD/pin" "$@" $zone >> keyfromlabel.out.$zone.$id 2>> /dev/null || return 1
$KEYFRLAB -E pkcs11 -a $alg -l "token=softhsm2-keyfromlabel;object=${id}-${zone};pin-source=$PWD/pin" "$@" $zone >> keyfromlabel.out.$zone.$id 2>> /dev/null || return 1
cat keyfromlabel.out.$zone.$id
}