Skip to content

Commit 1894035

Browse files
olszomalmtrojnar
authored andcommitted
tests: add Ed25519/Ed448 provider privkey tests
1 parent e1f1825 commit 1894035

10 files changed

+176
-5
lines changed

tests/Makefile.am

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ dist_check_SCRIPTS = \
6565
provider-ec-check-privkey.softhsm \
6666
provider-ec-check-all.softhsm \
6767
provider-ec-copy.softhsm \
68+
provider-ed25519-check-privkey.softhsm \
69+
provider-ed448-check-privkey.softhsm \
6870
provider-ed25519-keygen.softhsm \
6971
provider-ed448-keygen.softhsm \
7072
provider-fork-change-slot.softhsm \
@@ -73,7 +75,9 @@ dist_check_SCRIPTS = \
7375
provider-search-all-matching-tokens.softhsm
7476
dist_check_DATA = \
7577
rsa-cert.der rsa-privkey.der rsa-pubkey.der \
76-
ec-cert.der ec-privkey.der ec-pubkey.der
78+
ec-cert.der ec-privkey.der ec-pubkey.der \
79+
ed25519-cert.der ed25519-privkey.der ed25519-pubkey.der \
80+
ed448-cert.der ed448-privkey.der ed448-pubkey.der
7781

7882
ed25519_keygen_SOURCES = ed25519-keygen.c eddsa_common.c
7983
ed448_keygen_SOURCES = ed448-keygen.c eddsa_common.c

tests/common.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,15 @@ init_token () {
244244
import_objects ${key_type} "${common_label}-$i" ${obj_id} "${obj_label}-$i" "$@"
245245

246246
# List the objects imported into the token
247-
list_objects "${common_label}-$i"
247+
if [[ $? -eq 0 ]]; then
248+
list_objects "${common_label}-$i"
249+
else
250+
return 77
251+
fi
248252

249253
i=$(($i + 1))
250254
done
255+
return 0
251256
}
252257

253258
# Write an object (privkey, pubkey, cert) to the token
@@ -272,10 +277,10 @@ import_objects () {
272277
--id ${obj_id} --label "${obj_label}" >/dev/null
273278
if [[ $? -eq 0 ]]; then
274279
echo ok
275-
else
276-
echo failed
277-
exit 1
280+
continue
278281
fi
282+
echo "pkcs11-tool cannot import ${key_type} ${param}"
283+
return 77
279284
else
280285
echo "Skipping empty parameter"
281286
fi

tests/ed25519-cert.der

316 Bytes
Binary file not shown.

tests/ed25519-privkey.der

48 Bytes
Binary file not shown.

tests/ed25519-pubkey.der

44 Bytes
Binary file not shown.

tests/ed448-cert.der

388 Bytes
Binary file not shown.

tests/ed448-privkey.der

73 Bytes
Binary file not shown.

tests/ed448-pubkey.der

69 Bytes
Binary file not shown.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
3+
# Copyright © 2026 Mobi - Com Polska Sp. z o.o.
4+
# Author: Małgorzata Olszówka <Malgorzata.Olszowka@stunnel.org>
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>
18+
#
19+
# EdDSA public key resolution tests
20+
#
21+
# The provider resolves the public key for a private key as follows:
22+
# 1. CKO_PUBLIC_KEY (CKA_EC_POINT)
23+
# 2. CKO_CERTIFICATE (CKA_VALUE + X.509 parsing)
24+
#
25+
# Ed25519:
26+
# Import privkey + cert only (no pubkey) to exercise the CKO_CERTIFICATE fallback path.
27+
28+
outdir="output.$$"
29+
30+
# Load common test functions
31+
. ${srcdir}/common.sh
32+
33+
PRIVATE_KEY="pkcs11:token=libp11-0;id=%01%02%03%04;object=server-key-0;type=private;pin-value=${PIN}"
34+
CERTIFICATE_URL="pkcs11:token=libp11-0;id=%01%02%03%04;object=server-key-0;type=cert"
35+
36+
# Do the token initialization
37+
init_token "ed25519" "1" "libp11" ${ID} "server-key" "privkey" "" "cert"
38+
if [[ $? -eq 77 ]]; then
39+
echo "Ed448 key test skipped."
40+
rm -rf "$outdir"
41+
exit 77
42+
fi
43+
44+
# Ensure the use of the locally built provider; applies after running 'pkcs11-tool'
45+
unset OPENSSL_ENGINES
46+
export OPENSSL_MODULES="../src/.libs/"
47+
export PKCS11_MODULE_PATH=${MODULE}
48+
echo "OPENSSL_MODULES=${OPENSSL_MODULES}"
49+
echo "PKCS11_MODULE_PATH=${PKCS11_MODULE_PATH}"
50+
51+
# Load openssl settings
52+
. ${srcdir}/openssl-settings.sh
53+
54+
# Restore openssl settings
55+
trap cleanup EXIT
56+
57+
${OPENSSL} x509 -in ${srcdir}/ed25519-cert.der -inform DER -outform PEM \
58+
-out ${outdir}/ed25519-cert.pem
59+
CERTIFICATE="${outdir}/ed25519-cert.pem"
60+
61+
# Run the test
62+
${WRAPPER} ./check-privkey-prov ${CERTIFICATE} ${PRIVATE_KEY}
63+
rc=$?
64+
if [[ $rc -eq 77 ]]; then
65+
echo "Ed25519 key test skipped."
66+
rm -rf "$outdir"
67+
exit 77
68+
elif [[ $rc -ne 0 ]]; then
69+
echo "The private key loading couldn't get the public key from the certificate."
70+
exit 1
71+
fi
72+
73+
./check-privkey-prov ${CERTIFICATE_URL} ${PRIVATE_KEY}
74+
if [[ $? -ne 0 ]]; then
75+
echo "The private key loading couldn't get the public key from the certificate URL."
76+
exit 1
77+
fi
78+
79+
rm -rf "$outdir"
80+
81+
exit 0
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
3+
# Copyright © 2026 Mobi - Com Polska Sp. z o.o.
4+
# Author: Małgorzata Olszówka <Malgorzata.Olszowka@stunnel.org>
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>
18+
#
19+
# EdDSA public key resolution tests
20+
#
21+
# The provider resolves the public key for a private key as follows:
22+
# 1. CKO_PUBLIC_KEY (CKA_EC_POINT)
23+
# 2. CKO_CERTIFICATE (CKA_VALUE + X.509 parsing)
24+
#
25+
# Ed448:
26+
# Import privkey + pubkey + cert to exercise the direct CKO_PUBLIC_KEY lookup path.
27+
28+
outdir="output.$$"
29+
30+
# Load common test functions
31+
. ${srcdir}/common.sh
32+
33+
PRIVATE_KEY="pkcs11:token=libp11-0;id=%01%02%03%04;object=server-key-0;type=private;pin-value=${PIN}"
34+
CERTIFICATE_URL="pkcs11:token=libp11-0;id=%01%02%03%04;object=server-key-0;type=cert"
35+
36+
# Do the token initialization
37+
init_token "ed448" "1" "libp11" ${ID} "server-key" "privkey" "pubkey" "cert"
38+
if [[ $? -eq 77 ]]; then
39+
echo "Ed448 key test skipped."
40+
rm -rf "$outdir"
41+
exit 77
42+
fi
43+
44+
# Ensure the use of the locally built provider; applies after running 'pkcs11-tool'
45+
unset OPENSSL_ENGINES
46+
export OPENSSL_MODULES="../src/.libs/"
47+
export PKCS11_MODULE_PATH=${MODULE}
48+
echo "OPENSSL_MODULES=${OPENSSL_MODULES}"
49+
echo "PKCS11_MODULE_PATH=${PKCS11_MODULE_PATH}"
50+
51+
# Load openssl settings
52+
. ${srcdir}/openssl-settings.sh
53+
54+
# Restore openssl settings
55+
trap cleanup EXIT
56+
57+
${OPENSSL} x509 -in ${srcdir}/ed448-cert.der -inform DER -outform PEM \
58+
-out ${outdir}/ed448-cert.pem
59+
CERTIFICATE="${outdir}/ed448-cert.pem"
60+
61+
# Run the test
62+
${WRAPPER} ./check-privkey-prov ${CERTIFICATE} ${PRIVATE_KEY}
63+
rc=$?
64+
if [[ $rc -eq 77 ]]; then
65+
echo "Ed448 key test skipped."
66+
rm -rf "$outdir"
67+
exit 77
68+
elif [[ $rc -ne 0 ]]; then
69+
echo "The private key loading couldn't get the public key from the certificate."
70+
exit 1
71+
fi
72+
73+
./check-privkey-prov ${CERTIFICATE_URL} ${PRIVATE_KEY}
74+
if [[ $? -ne 0 ]]; then
75+
echo "The private key loading couldn't get the public key from the certificate URL."
76+
exit 1
77+
fi
78+
79+
rm -rf "$outdir"
80+
81+
exit 0

0 commit comments

Comments
 (0)