Hi,
I’m trying to configure Mender to use PKCS#11. I’m using the tpm2-pkcs11 project to provide a PKCS#11 interface to my TPM and the pkcs11-provider project to provide an OpenSSL provider for it.
I’ve configured the provider in /etc/ssl/openssl.cnf. I’ve created an EC private key in the TPM, and I can use it in openssl from the command line.
$ openssl pkey -noout -text -in "pkcs11:model=SLM9670;manufacturer=Infineon;serial=0000000000000000;token=dev;id=%01;object=my_key;type=private;pin-value=1234"
PKCS11 EC Private Key (256 bits)
[Can't export and print private key data]
URI pkcs11:model=SLM9670;manufacturer=Infineon;serial=0000000000000000;token=dev;id=%01;object=my_key;type=private
However, if I configure Mender to use this key for security
/var/lib/mender.conf:
{
"Security": {
"AuthPrivateKey": "pkcs11:model=SLM9670;manufacturer=Infineon;serial=0000000000000000;token=dev;id=%01;object=my_key;type=private;pin-value=1234"
}
}
the mender-authd service doesn’t start.
Jul 18 10:51:10 iot-gate-imx8plus systemd[1]: mender-authd.service: Scheduled restart job, restart counter is at 4.
Jul 18 10:51:10 iot-gate-imx8plus systemd[1]: Stopped Mender authentication service.
Jul 18 10:51:10 iot-gate-imx8plus systemd[1]: Started Mender authentication service.
Jul 18 10:51:10 iot-gate-imx8plus mender-auth[63160]: record_id=1 severity=error time="2024-Jul-18 10:51:10.477359" name="Global" msg="Failed to load the the private key: pkcs11:model=SLM9670;manufacturer=Infineon;serial=0000000000000000;token=dev;id=%01;object=my_key;type=private;pin-value=1234 trying the next object in the context: "
Jul 18 10:51:10 iot-gate-imx8plus mender-auth[63160]: record_id=2 severity=error time="2024-Jul-18 10:51:10.477632" name="Global" msg="Failed to bootstrap: Error during crypto library setup: Failed to load the private key from the configuration: Failed to load the private key: "
Jul 18 10:51:10 iot-gate-imx8plus systemd[1]: mender-authd.service: Main process exited, code=exited, status=1/FAILURE
Jul 18 10:51:10 iot-gate-imx8plus systemd[1]: mender-authd.service: Failed with result 'exit-code'.
I’ve tried setting the environment in the service file in /lib/systemd/system/mender-authd.service
. But this doesn’t make a difference.
[Service]
...
Environment="OPENSSL_CONF=/etc/ssl/openssl.cnf"
However - I can run the mender-authd process manually
$ /usr/bin/mender-auth daemon
record_id=75 severity=info time="2024-Jul-18 11:32:56.736502" name="Global" msg="Signing with: pkcs11:model=SLM9670;manufacturer=Infineon;serial=0000000000000000;token=dev;id=%01;object=my_key;type=private;pin-value=1234"
record_id=76 severity=info time="2024-Jul-18 11:32:57.105879" name="Global" msg="Successfully received new authorization data"
Presumably this is a case of OpenSSL not finding the correct config when running as a systemd service. Does anyone have any suggestions?