Skip to content

Commit f7cff85

Browse files
committed
Adjust tests for OpenSSL feature availability (ENGINE, EC)
1 parent 8d13772 commit f7cff85

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+557
-472
lines changed

examples/ed25519keygen.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
* SUCH DAMAGE.
2828
*/
2929

30-
#if !defined(OPENSSL_NO_EC) && OPENSSL_VERSION_NUMBER >= 0x30000000L
30+
#if !defined(OPENSSL_NO_EC) && \
31+
(OPENSSL_VERSION_NUMBER >= 0x30000000L) && \
32+
(OPENSSL_VERSION_NUMBER < 0x40000000L)
3133

3234
#include <libp11.h>
3335
#include <string.h>
@@ -176,13 +178,16 @@ int main(int argc, char *argv[])
176178
return rc;
177179
}
178180

179-
#else /* !defined(OPENSSL_NO_EC) && OPENSSL_VERSION_NUMBER >= 0x30000000L */
181+
#else /* !OPENSSL_NO_EC && OpenSSL 3.x */
182+
183+
#include <stdio.h>
180184

181185
int main(void)
182186
{
183-
return 0;
187+
fprintf(stderr, "Skipped: requires OpenSSL 3.x built with EC support\n");
188+
return 77;
184189
}
185190

186-
#endif /* !defined(OPENSSL_NO_EC) && OPENSSL_VERSION_NUMBER >= 0x30000000L */
191+
#endif /* !OPENSSL_NO_EC && OpenSSL 3.x */
187192

188193
/* vim: set noexpandtab: */

examples/ed448keygen.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
* SUCH DAMAGE.
2828
*/
2929

30-
#if !defined(OPENSSL_NO_EC) && OPENSSL_VERSION_NUMBER >= 0x30000000L
30+
#if !defined(OPENSSL_NO_EC) && \
31+
(OPENSSL_VERSION_NUMBER >= 0x30000000L) && \
32+
(OPENSSL_VERSION_NUMBER < 0x40000000L)
3133

3234
#include <libp11.h>
3335
#include <string.h>
@@ -176,13 +178,16 @@ int main(int argc, char *argv[])
176178
return rc;
177179
}
178180

179-
#else /* !defined(OPENSSL_NO_EC) && OPENSSL_VERSION_NUMBER >= 0x30000000L */
181+
#else /* !OPENSSL_NO_EC && OpenSSL 3.x */
182+
183+
#include <stdio.h>
180184

181185
int main(void)
182186
{
183-
return 0;
187+
fprintf(stderr, "Skipped: requires OpenSSL 3.x built with EC support\n");
188+
return 77;
184189
}
185190

186-
#endif /* !defined(OPENSSL_NO_EC) && OPENSSL_VERSION_NUMBER >= 0x30000000L */
191+
#endif /* !OPENSSL_NO_EC && OpenSSL 3.x */
187192

188193
/* vim: set noexpandtab: */

tests/case-insensitive.softhsm

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,43 +35,42 @@ MIXED_PUB_KEY="pKcS11:token=libp11-0;id=%01%02%03%04;object=server-key-0;type=pu
3535
# Load common test functions
3636
. ${srcdir}/common.sh
3737

38-
if (( "${OPENSSL_VERSION%%.*}" >= 4 )); then
39-
echo "Skipping test with OpenSSL ${OPENSSL_VERSION}"
40-
exit 77
41-
fi
42-
4338
# Do the token initialization
4439
init_token "rsa" "1" "libp11" ${ID} "server-key" "privkey" "pubkey" "cert"
4540

4641
# Load openssl settings
47-
TEMP_LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
4842
. ${srcdir}/openssl-settings.sh
4943

44+
# Restore openssl settings
45+
trap cleanup EXIT
46+
5047
# Run the test
5148
${WRAPPER} ./evp-sign default false "${outdir}/engines.cnf" \
5249
${ALL_LOWER_PRIV_KEY} ${ALL_LOWER_PUB_KEY} ${MODULE}
53-
if [[ $? -ne 0 ]]; then
54-
echo "All lower case PKCS#11 URI scheme detection failed"
50+
rc=$?
51+
if [[ $rc -eq 77 ]]; then
52+
echo "PKCS#11 URI scheme detection test skipped."
53+
rm -rf "$outdir"
54+
exit 77
55+
elif [[ $rc -ne 0 ]]; then
56+
echo "All lower case PKCS#11 URI scheme detection failed."
5557
exit 1
5658
fi
5759

5860
./evp-sign default false "${outdir}/engines.cnf" \
5961
${ALL_UPPER_PRIV_KEY} ${ALL_UPER_PUB_KEY} ${MODULE}
6062
if [[ $? -ne 0 ]]; then
61-
echo "All upper case PKCS#11 URI scheme detection failed"
63+
echo "All upper case PKCS#11 URI scheme detection failed."
6264
exit 1
6365
fi
6466

6567
./evp-sign default false "${outdir}/engines.cnf" \
6668
${MIXED_PRIV_KEY} ${MIXED_PUB_KEY} ${MODULE}
6769
if [[ $? -ne 0 ]]; then
68-
echo "Mixed case PKCS#11 URI scheme detection failed"
70+
echo "Mixed case PKCS#11 URI scheme detection failed."
6971
exit 1
7072
fi
7173

72-
# Restore settings
73-
export LD_LIBRARY_PATH=${TEMP_LD_LIBRARY_PATH}
74-
7574
rm -rf "$outdir"
7675

7776
exit 0

tests/check-all-prov.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,13 @@ int main(int argc, char *argv[])
8585
return ret;
8686
}
8787

88-
#else
88+
#else /* OPENSSL_VERSION_NUMBER >= 0x30000000L */
89+
90+
#include <stdio.h>
8991

9092
int main() {
91-
return 0;
93+
fprintf(stderr, "Skipped: requires OpenSSL >= 3.0\n");
94+
return 77;
9295
}
9396

9497
#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000L */

tests/check-privkey-prov.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,13 @@ int main(int argc, char *argv[])
8484
return ret;
8585
}
8686

87-
#else
87+
#else /* OPENSSL_VERSION_NUMBER >= 0x30000000L */
88+
89+
#include <stdio.h>
8890

8991
int main() {
90-
return 0;
92+
fprintf(stderr, "Skipped: requires OpenSSL >= 3.0\n");
93+
return 77;
9194
}
9295

9396
#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000L */

tests/check-privkey.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,13 @@ int main(int argc, char *argv[])
190190
return ret;
191191
}
192192

193-
#else
193+
#else /* OPENSSL_NO_ENGINE */
194+
195+
#include <stdio.h>
194196

195197
int main() {
196-
return 0;
198+
fprintf(stderr, "Skipped: ENGINE support not available\n");
199+
return 77;
197200
}
198201

199202
#endif /* OPENSSL_NO_ENGINE */

tests/common.sh

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ echo "Current directory: $(pwd)"
2626
echo "Source directory: ${srcdir}"
2727
echo "Output directory: ${outdir}"
2828

29-
mkdir -p ${outdir}
30-
3129
# List of directories to search
3230
SOFTHSM_SEARCH_PATHS=(
3331
"/opt/homebrew"
@@ -77,6 +75,13 @@ TEMP_LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
7775

7876
OPENSSL_VERSION=$(./openssl_version | cut -d ' ' -f 2)
7977

78+
# Skip if SoftHSM requires ECDSA_SIG_get0 but current libcrypto doesn't provide it (no-ec build)
79+
if nm -D "${MODULE}" 2>/dev/null | grep -q ' U ECDSA_SIG_get0' && \
80+
! "${OPENSSL}" list -public-key-algorithms 2>/dev/null | grep -qi '\bec\b'; then
81+
echo "Skipping test: SoftHSM requires EC support, but OpenSSL was built without EC."
82+
exit 77
83+
fi
84+
8085
# Restore settings
8186
export LD_LIBRARY_PATH=${TEMP_LD_LIBRARY_PATH}
8287

@@ -107,6 +112,7 @@ else
107112
SHARED_EXT=.so
108113
fi
109114

115+
mkdir -p ${outdir}
110116

111117
sed -e "s|@MODULE_PATH@|${MODULE}|g" -e \
112118
"s|@ENGINE_PATH@|../src/.libs/pkcs11${SHARED_EXT}|g" \
@@ -152,6 +158,7 @@ init_db() {
152158
# Exit if no tool was found
153159
if [[ -z "${SOFTHSM_TOOL}" ]]; then
154160
echo "Skipping test: No softhsm or softhsm2-util tool found in expected locations."
161+
rm -rf "$outdir"
155162
exit 77
156163
fi
157164

@@ -282,10 +289,17 @@ list_objects () {
282289
echo "***************************************"
283290
echo "* Listing objects on the token ${token_label}"
284291
echo "***************************************"
285-
pkcs11-tool --login --pin ${PIN} --module ${MODULE} \
286-
--token-label "${token_label}" --list-objects
287-
if [[ $? -ne 0 ]]; then
288-
exit 1
289-
fi
292+
293+
# Ensure pkcs11-tool runs with the original library path
294+
export LD_LIBRARY_PATH="${TEMP_LD_LIBRARY_PATH}"
295+
296+
pkcs11-tool --login --pin "${PIN}" --module "${MODULE}" \
297+
--token-label "${token_label}" --list-objects || exit 1
298+
290299
echo "***************************************"
291300
}
301+
302+
# Cleanup test environment
303+
cleanup() {
304+
export LD_LIBRARY_PATH="${TEMP_LD_LIBRARY_PATH}"
305+
}

tests/dup-key-prov.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,13 @@ int main(int argc, char *argv[])
8585
return ret;
8686
}
8787

88-
#else
88+
#else /* OPENSSL_VERSION_NUMBER >= 0x30000000L */
89+
90+
#include <stdio.h>
8991

9092
int main() {
91-
return 0;
93+
fprintf(stderr, "Skipped: requires OpenSSL >= 3.0\n");
94+
return 77;
9295
}
9396

9497
#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000L */

tests/dup-key.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,13 @@ int main(int argc, char *argv[])
187187
return ret;
188188
}
189189

190-
#else
190+
#else /* OPENSSL_NO_ENGINE */
191+
192+
#include <stdio.h>
191193

192194
int main() {
193-
return 0;
195+
fprintf(stderr, "Skipped: ENGINE support not available\n");
196+
return 77;
194197
}
195198

196199
#endif /* OPENSSL_NO_ENGINE */

tests/ec-cert-store.softhsm

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,31 @@ outdir="output.$$"
3030
init_token "ec" "1" "libp11" ${ID} "server-key" "privkey" "" "cert"
3131

3232
# Load openssl settings
33-
TEMP_LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
3433
. ${srcdir}/openssl-settings.sh
3534

35+
# Restore openssl settings
36+
trap cleanup EXIT
37+
3638
${OPENSSL} x509 -in ${srcdir}/ec-cert.der -inform DER -outform PEM \
3739
-out ${outdir}/ec-cert.pem
3840
CERTIFICATE="${outdir}/ec-cert.pem"
3941
CERTIFICATE_URL="pkcs11:token=libp11-0;id=04030201;object=stored-cert;pin-value=1234"
4042

4143
# Run the test
4244
${WRAPPER} ../examples/storecert ${CERTIFICATE} ${CERTIFICATE_URL} ${MODULE}
43-
if [[ $? -ne 0 ]]; then
44-
echo "The certificate storing couldn't be performed"
45+
rc=$?
46+
if [[ $rc -eq 77 ]]; then
47+
echo "EC certificate storing test skipped."
48+
rm -rf "$outdir"
49+
exit 77
50+
elif [[ $rc -ne 0 ]]; then
51+
echo "EC certificate storing couldn't be performed."
4552
exit 1
4653
fi
4754

48-
# Restore settings
49-
export LD_LIBRARY_PATH=${TEMP_LD_LIBRARY_PATH}
50-
5155
list_objects && list_objects | grep -q stored-cert
5256
if [[ $? -ne 0 ]]; then
53-
echo "The certificate was not properly stored"
57+
echo "EC certificate was not properly stored."
5458
exit 1
5559
fi
5660

0 commit comments

Comments
 (0)