diff options
Diffstat (limited to 'recipes-support/softhsm-testtoken/files/createtoken.sh')
-rw-r--r-- | recipes-support/softhsm-testtoken/files/createtoken.sh | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/recipes-support/softhsm-testtoken/files/createtoken.sh b/recipes-support/softhsm-testtoken/files/createtoken.sh new file mode 100644 index 0000000..fa4569d --- /dev/null +++ b/recipes-support/softhsm-testtoken/files/createtoken.sh | |||
@@ -0,0 +1,27 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | if pkcs11-tool --module=/usr/lib/softhsm/libsofthsm2.so -O; then | ||
4 | # The token has already been initialized, exit | ||
5 | exit 0 | ||
6 | fi | ||
7 | |||
8 | if ! ls /var/sota/import/pkey.pem /var/sota/import/client.pem; then | ||
9 | # Key/certificate pair is not present, repeat | ||
10 | exit 1 | ||
11 | fi | ||
12 | |||
13 | mkdir -p /var/lib/softhsm/tokens | ||
14 | softhsm2-util --init-token --slot 0 --label "Virtual token" --pin 1234 --so-pin 1234 | ||
15 | |||
16 | openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in /var/sota/import/pkey.pem -out /var/sota/import/pkey.p8 | ||
17 | softhsm2-util --import /var/sota/import/pkey.p8 --label "pkey" --id 02 --token 'Virtual token' --pin 1234 | ||
18 | openssl x509 -outform der -in /var/sota/import/client.pem -out /var/sota/import/client.der | ||
19 | pkcs11-tool --module=/usr/lib/softhsm/libsofthsm2.so --id 1 --write-object /var/sota/import/client.der --type cert --login --pin 1234 | ||
20 | |||
21 | # Import UPTANE keypair if it exists | ||
22 | if [ -f /var/sota/import/ecukey.pem ]; then | ||
23 | openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in /var/sota/import/ecukey.pem -out /var/sota/import/ecukey.p8 | ||
24 | softhsm2-util --import /var/sota/import/ecukey.p8 --label "uptanekey" --id 03 --token 'Virtual token' --pin 1234 | ||
25 | fi | ||
26 | |||
27 | exit 0 | ||