diff options
Diffstat (limited to 'recipes-support/softhsm-testtoken')
3 files changed, 60 insertions, 0 deletions
diff --git a/recipes-support/softhsm-testtoken/files/createtoken.service b/recipes-support/softhsm-testtoken/files/createtoken.service new file mode 100644 index 0000000..23317b9 --- /dev/null +++ b/recipes-support/softhsm-testtoken/files/createtoken.service | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | [Unit] | ||
| 2 | Description=Create a mock smartcard for testing | ||
| 3 | Before=aktualizr.service | ||
| 4 | RequiredBy=aktualizr.service | ||
| 5 | |||
| 6 | [Service] | ||
| 7 | RestartSec=10 | ||
| 8 | Restart=on-failure | ||
| 9 | ExecStart=/usr/bin/createtoken.sh | ||
| 10 | |||
| 11 | [Install] | ||
| 12 | WantedBy=aktualizr.service | ||
diff --git a/recipes-support/softhsm-testtoken/files/createtoken.sh b/recipes-support/softhsm-testtoken/files/createtoken.sh new file mode 100644 index 0000000..a72ec34 --- /dev/null +++ b/recipes-support/softhsm-testtoken/files/createtoken.sh | |||
| @@ -0,0 +1,21 @@ | |||
| 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/token/pkey.pem /var/sota/token/client.pem; then | ||
| 9 | # Key/certificate pair is not present, repeat | ||
| 10 | mkdir -p /var/sota/token | ||
| 11 | exit 1 | ||
| 12 | fi | ||
| 13 | |||
| 14 | mkdir -p /var/lib/softhsm/tokens | ||
| 15 | softhsm2-util --init-token --slot 0 --label "Virtual token" --pin 1234 --so-pin 1234 | ||
| 16 | |||
| 17 | pkcs11-tool --module=/usr/lib/softhsm/libsofthsm2.so --label 'Virtual token' --write-object /var/sota/token/pkey.pem --type privkey --login --pin 1234 | ||
| 18 | openssl x509 -outform der -in /var/sota/token/client.pem -out /var/sota/token/client.der | ||
| 19 | pkcs11-tool --module=/usr/lib/softhsm/libsofthsm2.so --label 'Virtual token' --write-object /var/sota/token/client.der --type cert --login --pin 1234 | ||
| 20 | |||
| 21 | exit 0 | ||
diff --git a/recipes-support/softhsm-testtoken/softhsm-testtoken.bb b/recipes-support/softhsm-testtoken/softhsm-testtoken.bb new file mode 100644 index 0000000..c5691db --- /dev/null +++ b/recipes-support/softhsm-testtoken/softhsm-testtoken.bb | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | SUMMARY = "Mock smartcard for aktualizr" | ||
| 2 | LICENSE = "MIT" | ||
| 3 | LIC_FILES_CHKSUM = "file://${COREBASE}/LICENSE;md5=4d92cd373abda3937c2bc47fbc49d690 \ | ||
| 4 | file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" | ||
| 5 | |||
| 6 | |||
| 7 | inherit systemd | ||
| 8 | |||
| 9 | RDEPENDS_${PN} = "softhsm libp11" | ||
| 10 | DEPENDS_append = "${@bb.utils.contains('DISTRO_FEATURES', 'systemd', ' systemd', '', d)}" | ||
| 11 | |||
| 12 | |||
| 13 | SRC_URI = "file://createtoken.service \ | ||
| 14 | file://createtoken.sh" | ||
| 15 | |||
| 16 | SYSTEMD_SERVICE_${PN} = "createtoken.service" | ||
| 17 | |||
| 18 | do_install() { | ||
| 19 | install -d ${D}${systemd_unitdir}/system | ||
| 20 | install -m 0644 ${WORKDIR}/createtoken.service ${D}${systemd_unitdir}/system/createtoken.service | ||
| 21 | install -d ${D}${bindir} | ||
| 22 | install -m 0744 ${WORKDIR}/createtoken.sh ${D}${bindir}/createtoken.sh | ||
| 23 | } | ||
| 24 | |||
| 25 | FILES_${PN} = "${bindir}/createtoken.sh \ | ||
| 26 | ${systemd_unitdir}/system/createtoken.service" | ||
| 27 | |||
