mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-07-31 00:03:07 +03:00
The p11-kit remoting was initially introduced because softhsm
was crashing during cleanup with OpenSSL 3.0. This was resolved
since then and this code introduces a lot of complexity and
possible bugs, such as when using the mechanisms from PKCS#11 3.0
that are unknown to the p11-kit remoting tool. It decides to remove
them from the list as demonstrated here:
https://github.com/p11-glue/p11-kit/issues/668
This resulted in pkcs11-provider not registering EDDSA siganture
methods to the OpenSSL and failing when asked to provide a singature
by the Ed25519 key from the PKCS#11 token.
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Sahana Prasad <sahana@redhat.com>
(cherry picked from commit 99fcd56135
)
91 lines
1.9 KiB
Bash
Executable File
91 lines
1.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# The client keys are stored in a SoftHSM device.
|
|
|
|
TESTDIR=$1
|
|
PRIVKEY=$2
|
|
OBJNAME=$3
|
|
TOKENLABEL=$3 # yeah. The same as object label
|
|
LOADPUBLIC=$4
|
|
LIBSOFTHSM_PATH=$5
|
|
shift 5
|
|
|
|
PUBKEY="$PRIVKEY.pub"
|
|
|
|
echo "TESTDIR: $TESTDIR"
|
|
echo "PRIVKEY: $PRIVKEY"
|
|
echo "PUBKEY: $PUBKEY"
|
|
echo "OBJNAME: $OBJNAME"
|
|
echo "TOKENLABEL: $TOKENLABEL"
|
|
echo "LOADPUBLIC: $LOADPUBLIC"
|
|
|
|
if [ ! -d "$TESTDIR/db" ]; then
|
|
# Create temporary directory for tokens
|
|
install -d -m 0755 "$TESTDIR/db"
|
|
|
|
# Create SoftHSM configuration file
|
|
cat >"$TESTDIR/softhsm.conf" <<EOF
|
|
directories.tokendir = $TESTDIR/db
|
|
objectstore.backend = file
|
|
log.level = DEBUG
|
|
EOF
|
|
|
|
cat "$TESTDIR/softhsm.conf"
|
|
fi
|
|
|
|
export SOFTHSM2_CONF=$TESTDIR/softhsm.conf
|
|
|
|
#init -- each object will have its own token
|
|
cmd="softhsm2-util --init-token --label $TOKENLABEL --free --pin 1234 --so-pin 1234"
|
|
eval echo "$cmd"
|
|
out=$(eval "$cmd")
|
|
ret=$?
|
|
if [ $ret -ne 0 ]; then
|
|
echo "Init token failed"
|
|
echo "$out"
|
|
exit 1
|
|
fi
|
|
|
|
#load private key
|
|
cmd="p11tool --provider $LIBSOFTHSM_PATH --write --load-privkey $PRIVKEY --label $OBJNAME --login --set-pin=1234 \"pkcs11:token=$TOKENLABEL\""
|
|
eval echo "$cmd"
|
|
out=$(eval "$cmd")
|
|
ret=$?
|
|
if [ $ret -ne 0 ]; then
|
|
echo "Loading privkey failed"
|
|
echo "$out"
|
|
exit 1
|
|
fi
|
|
|
|
cat "$PUBKEY"
|
|
|
|
ls -l "$TESTDIR"
|
|
|
|
if [ "$LOADPUBLIC" -ne 0 ]; then
|
|
#load public key
|
|
cmd="p11tool --provider $LIBSOFTHSM_PATH --write --load-pubkey $PUBKEY --label $OBJNAME --login --set-pin=1234 \"pkcs11:token=$TOKENLABEL\""
|
|
eval echo "$cmd"
|
|
out=$(eval "$cmd")
|
|
ret=$?
|
|
if [ $ret -ne 0 ]; then
|
|
echo "Loading pubkey failed"
|
|
echo "$out"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
cmd="p11tool --list-all --login \"pkcs11:token=$TOKENLABEL\" --set-pin=1234"
|
|
eval echo "$cmd"
|
|
out=$(eval "$cmd")
|
|
ret=$?
|
|
if [ $ret -ne 0 ]; then
|
|
echo "Logging in failed"
|
|
echo "$out"
|
|
exit 1
|
|
fi
|
|
echo "$out"
|
|
|
|
pkcs11-tool -M --login --pin=1234 --module="$LIBSOFTHSM_PATH" --token-label="$TOKENLABEL"
|
|
|
|
exit 0
|