-
Notifications
You must be signed in to change notification settings - Fork 422
use global flag for initialised state #864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f27e786
d768d6c
a054b30
6cf9971
1da44af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /tokens | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| #! /bin/sh | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be probably better to add it to to test subdit (it means src/bin/util/test) so it's clear it's a test. |
||
| # This file is in the public domain | ||
|
|
||
| CWD=`pwd` | ||
|
|
||
| # binaries | ||
|
|
||
| OPENSSL=${OPENSSL-openssl} | ||
| OPENSSL=`command -v "$OPENSSL"` | ||
| if test -z "$OPENSSL" ; then | ||
| echo "error: openssl utility not found" >&2 | ||
| exit 77 | ||
| fi | ||
|
|
||
| openssl() { | ||
| "$OPENSSL" ${1+"$@"} | ||
| } | ||
|
|
||
| openssl_version=`openssl version` || exit $? | ||
| if test -z "$openssl_version" ; then | ||
| echo "cannot determine OpenSSL version" >&2 | ||
| exit 99 | ||
| fi | ||
|
|
||
| case $openssl_version in | ||
| *"OpenSSL 0.9."*|\ | ||
| *"OpenSSL 1."*) | ||
|
Comment on lines
+26
to
+27
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be also skip for LibreSSL.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm it might just get covered by the provider test but wouldn't hurt to add it...
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
fixed by new commit "restrict tests to OpenSSL 3+: address" |
||
| echo "$openssl_version is not impacted" >&2 | ||
| exit 77 | ||
| ;; | ||
| *"OpenSSL "*) | ||
| # OpenSSL 3+ - with provider loadable module | ||
| ;; | ||
| *) | ||
| echo "unsupported: $openssl_version" >&2 | ||
| exit 77 | ||
| ;; | ||
| esac | ||
| # NOTE OpenSSL > 1.* | ||
|
|
||
|
|
||
| # find a PKCS#11 provider | ||
| p11_find_provider() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose this doesn't work in the CI as there is no pkcs11-provider installed - it might be good to extend CI for that so it's not purely local test.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is managed by exist status - 77 means skip tests. |
||
| if test -z "$PROV_PKCS11" ; then | ||
|
|
||
| # try to extract path ... | ||
| moduledir=`openssl version -m 2>/dev/null \ | ||
| | sed -e 's/^MODULESDIR: "//' -e 's/"$//'` | ||
| if test -z "$moduledir" ; then | ||
| echo "cannot determine OpenSSL MODULESDIR" >&2 | ||
| exit 99 | ||
| fi | ||
| if test -d "$moduledir" ; then : | ||
| else | ||
| echo "does not exist MODULESDIR: $moduledir" >&2 | ||
| exit 99 | ||
| fi | ||
|
|
||
| for N in pkcs11 libpkcs11 ; do | ||
| for S in so dll ; do | ||
| test -f "$moduledir"/$N.$S || continue | ||
| PROV_PKCS11="$moduledir"/$N.$S | ||
| break | ||
| done | ||
| test -n "$PROV_PKCS11" && break | ||
| done | ||
| test -n "$PROV_PKCS11" | ||
| else | ||
| test -f "$PROV_PKCS11" | ||
| fi | ||
| } | ||
|
|
||
| if p11_find_provider ; then : | ||
| else | ||
| echo "error: PKCS#11 provider not found" >&2 | ||
| exit 77 | ||
| fi | ||
|
|
||
|
|
||
| # get absolute path to SoftHSM pkcs#11 module | ||
| # NOTE: Depending on the build model, the module | ||
| # may be located in a subdirectory. | ||
| D=`cd ../../../lib/ && pwd` | ||
| if test -z "$D" ; then | ||
| echo "unexpectedly missing library directory" >&2 | ||
| exit 99 | ||
| fi | ||
| P11MODULE= | ||
| for F in `find "$D" -name '*softhsm2.*'` ; do | ||
| case "$F" in | ||
| *.so|*.dll);; | ||
| *) continue;; | ||
| esac | ||
| test -f "$F" || continue | ||
| P11MODULE="$F" | ||
| break | ||
| done | ||
| if test -z "$P11MODULE" ; then | ||
| echo "error: unexpected module suffix" >&2 | ||
| exit 99 | ||
| fi | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| if command -v realpath > /dev/null ; then | ||
| P11MODULE=`realpath "$P11MODULE"` | ||
| fi | ||
|
|
||
| softhsm2_tool() { | ||
| "$CWD"/../softhsm2-util --module "$P11MODULE" ${1+"$@"} | ||
| } | ||
|
|
||
|
|
||
| # configurations | ||
| TOKEN_DIR="$CWD"/tokens | ||
| rm -rf "$TOKEN_DIR" | ||
| mkdir "$TOKEN_DIR" | ||
|
Comment on lines
+112
to
+114
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should clean the tokens after the test in the same way as
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Fixed by new commit "clean-up "token" directory on success" |
||
|
|
||
|
|
||
| OPENSSL_CONF="$TOKEN_DIR"/openssl.conf | ||
| cat > "$OPENSSL_CONF" <<EOF | ||
| openssl_conf = config | ||
|
|
||
| [ config ] | ||
| providers = provider_section | ||
|
|
||
| [ provider_section ] | ||
| default = default_section | ||
| provider1 = provider1_section | ||
|
|
||
| [default_section] | ||
| activate = 1 | ||
|
|
||
| [provider1_section] | ||
| pkcs11-module-path = $P11MODULE | ||
| module = $PROV_PKCS11 | ||
| activate = 1 | ||
| EOF | ||
| export OPENSSL_CONF | ||
|
|
||
|
|
||
| SOFTHSM2_CONF="$TOKEN_DIR"/softhsm2.conf | ||
| cat > "$SOFTHSM2_CONF" <<EOF | ||
| directories.tokendir = $TOKEN_DIR | ||
| objectstore.backend = file | ||
| slots.removable = false | ||
| slots.mechanisms = ALL | ||
| log.level = ERROR | ||
| EOF | ||
| export SOFTHSM2_CONF | ||
|
|
||
|
|
||
| # execution | ||
| set -e | ||
|
|
||
| TOKEN_PIN=4321 | ||
| TOKEN_ID=01 | ||
| PASS_URI=pass:$TOKEN_PIN | ||
| PASS_FILE=pass:dcba | ||
| KEY_URI=pkcs11:id=%$TOKEN_ID | ||
| KEY_FILE="$TOKEN_DIR"/test_key | ||
| SIGN_FILE="$TOKEN_DIR"/test_sign | ||
|
|
||
| softhsm2_tool --init-token --label test0 --slot free --so-pin 12345678 --pin $TOKEN_PIN | ||
| openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out "$KEY_FILE" -pass $PASS_FILE | ||
| softhsm2_tool --import "$KEY_FILE" --import-type keypair --id $TOKEN_ID --label test_key --token test0 --pin $TOKEN_PIN | ||
|
|
||
| #openssl storeutl -passin $PASS_URI $KEY_URI | ||
|
|
||
| # sample command that crash before workaround due to OpenSSL "at_exit" flaw | ||
| openssl pkeyutl -sign -inkey $KEY_URI -passin $PASS_URI -rawin -in ./Makefile -out "$SIGN_FILE" | ||
|
|
||
| # just in case | ||
| openssl pkeyutl -verify -inkey "$KEY_FILE" -passin $PASS_FILE -rawin -in ./Makefile -sigfile "$SIGN_FILE" | ||
|
|
||
| # clean-up | ||
| rm -rf "$TOKEN_DIR" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm I don't think we need this if there is a proper clean up as suggested below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please let keep this.
For instance user my cancel unfinished test and git should ignore tests artifacts.