Skip to content

Commit fd366be

Browse files
committed
Fix provider tests with older OpenSC tools
OpenSC 0.22 ignores --label when listing objects, so filter the output explicitly before checking generated key IDs. Skip the ambiguity test when pkcs11-tool reports unsupported Ed25519 imports, while preserving failures for other import errors. Reproduced both CI failures with Ubuntu 22.04's OpenSC package and verified that generation now passes and the ambiguity test skips. The full local suite passes with 49 tests passed and 5 skipped.
1 parent 8e32d22 commit fd366be

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

‎tests/provider-ambiguous-public-key.softhsm‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,18 @@ fi
3030
# Import directly: provider generation now assigns IDs even to empty URI IDs.
3131
import_object() {
3232
local type="$1" label="$2" fixture="$3"
33+
local status=0
3334
"${PKCS11_TOOL}" --module "${MODULE}" --token-label "$token" \
3435
--login --pin "${PIN}" --write-object "${srcdir}/$fixture" \
35-
--type "$type" --label "$label" "${id_args[@]}"
36+
--type "$type" --label "$label" "${id_args[@]}" \
37+
>"$outdir/import.log" 2>&1 || status=$?
38+
cat "$outdir/import.log"
39+
if [[ "$status" -ne 0 ]] && grep -q 'Unsupported key type' "$outdir/import.log"; then
40+
echo "Skipping test: pkcs11-tool cannot import Ed25519 keys."
41+
rm -rf "$outdir"
42+
exit 77
43+
fi
44+
return "$status"
3645
}
3746

3847
load_public() {

‎tests/provider-genpkey.softhsm‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,17 @@ genpkey_with_id()
8585
for type in pubkey privkey; do
8686
objects=$(${PKCS11_TOOL} --module "${MODULE}" --login --pin "${PIN}" \
8787
--list-objects --type "$type" --label "$label") || return 1
88-
# OpenSC versions print IDs as hex, colon-separated hex, or
89-
# decimal followed by parenthesized hex for short IDs.
90-
ids=$(printf '%s\n' "$objects" | awk '/^[[:space:]]*ID:/ {
88+
# Older OpenSC versions ignore --label when listing objects.
89+
# IDs may be hex, colon-separated hex, or decimal followed by
90+
# parenthesized hex for short IDs.
91+
ids=$(printf '%s\n' "$objects" | awk -v label="$label" '
92+
/^[^[:space:]]/ { matches = 0 }
93+
/^[[:space:]]*label:/ {
94+
value = $0
95+
sub(/^[[:space:]]*label:[[:space:]]*/, "", value)
96+
matches = value == label
97+
}
98+
matches && /^[[:space:]]*ID:/ {
9199
id = $3 ~ /^\(0x/ ? $3 : $2
92100
sub(/^\(0x/, "", id)
93101
gsub(/[:)]/, "", id)

0 commit comments

Comments
 (0)