-
Notifications
You must be signed in to change notification settings - Fork 429
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
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,3 @@ | ||
| # shell files have unix(LF) end-of-line conversion | ||
|
|
||
| *.sh text eol=lf |
| 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,191 @@ | ||
| #! /bin/sh | ||
|
bukka marked this conversation as resolved.
|
||
| # 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."*) | ||
|
bukka marked this conversation as resolved.
|
||
| 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.
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. What I meant is that it might be useful to install pkcs11-provider in CI so we have got at least one workflow where this test runs. In other words I would like to have this running in CI and not be always skipped. The test that runs only in local setup gets much more easily broken without anyone noticing.
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. done with a separate commit - add pkcs11-provider to the CI workflow tests with host OpenSSL 3+ |
||
| 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 S in ".libs" "$CMAKE_CONFIG_TYPE" ; do | ||
| for F in "$D/$S/"*softhsm2.* ; do | ||
| case "$F" in | ||
| *.so|*.dll);; | ||
| *) continue;; | ||
| esac | ||
| P11MODULE="$F" | ||
| break; | ||
| done | ||
| test -n "$P11MODULE" && break | ||
| done | ||
| if test -z "$P11MODULE" ; then | ||
| echo "error: unexpected module suffix" >&2 | ||
| exit 99 | ||
| fi | ||
| if command -v realpath > /dev/null ; then | ||
| P11MODULE=`realpath "$P11MODULE"` | ||
| fi | ||
|
|
||
|
|
||
| # get path to SoftHSM utility | ||
| SOFTHSM2_UTIL= | ||
| for S in "" "$CMAKE_CONFIG_TYPE" ; do | ||
| F="$CWD/../$S/softhsm2-util" | ||
| # NOTE: test should succeded for files with specific suffixes | ||
| test -x "$F" || continue | ||
| SOFTHSM2_UTIL="$F" | ||
| break | ||
| done | ||
| if test -z "$SOFTHSM2_UTIL" ; then | ||
| echo "error: SoftHSM utility not found" >&2 | ||
| exit 99 | ||
| fi | ||
|
|
||
| softhsm2_tool() { | ||
| "$SOFTHSM2_UTIL" --module "$P11MODULE" ${1+"$@"} | ||
| } | ||
|
|
||
|
|
||
| # configurations | ||
| TOKEN_DIR="$CWD"/tokens | ||
| rm -rf "$TOKEN_DIR" | ||
| mkdir "$TOKEN_DIR" | ||
|
bukka marked this conversation as resolved.
|
||
|
|
||
|
|
||
| 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 "$SOFTHSM2_UTIL" -out "$SIGN_FILE" | ||
|
|
||
| # just in case | ||
| openssl pkeyutl -verify -inkey "$KEY_FILE" -passin $PASS_FILE -rawin -in "$SOFTHSM2_UTIL" -sigfile "$SIGN_FILE" | ||
|
|
||
| # clean-up | ||
| rm -rf "$TOKEN_DIR" | ||
Uh oh!
There was an error while loading. Please reload this page.