blob: fdc0a3f9820a63734480d204ae143af16b6cd9ee [file] [log] [blame]
Manjunath Ranganathaiah54944fe2018-04-03 16:29:45 -07001#
2# Import the keys and certs to pkcs11 based softhsm
3#
4
5if [ "$#" -ne 3 ]; then
6 echo "Usage: p11.sh <user pin> <so pin> <id>"
7 exit 1
8fi
9
10LIB_PATH=/usr/lib/x86_64-linux-gnu/softhsm/libsofthsm2.so
11
12mkdir -p p11key p11crt cacerts
13# Conver the keys and certs to DER format
14# key to der
15openssl rsa -in private/ca.key -outform DER -out p11key/cakey.der
16# cert to der
17cp certs/ca.crt cacerts
18DLIST=`ls -d intermediate_*`
19for DIR in $DLIST; do
20 cp $DIR/certs/ca.crt cacerts/$DIR.crt
21done
22for CA in `ls cacerts`; do
23 openssl x509 -in cacerts/$CA -outform DER -out p11crt/$CA
24done
25
26# create token directory
27mkdir /var/lib/softhsm/tokens
28# create slot
29softhsm2-util --init-token --slot 0 --label "ca token" --pin $1 --so-pin $2
30# import key into softhsm
31pkcs11-tool --module $LIB_PATH -l --pin $1 --write-object p11key/cakey.der --type privkey --id $3
32# import certs into softhsm
33for CRT in `ls cacerts`; do
34 pkcs11-tool --module $LIB_PATH -l --pin $1 --write-object p11crt/$CRT --type cert --id $3
35done
36
37rm -r p11key
38rm -r p11crt
39rm -r cacerts