STSAFE-A110 and MbedTLS - Authenticating IoT device to MS Azure IoT Hub
Hi,
In our application, we want to authenticate our IoT devices in Azure IoT Hub using X509 certificates with the help of STSAFE-A110. The application is written in Zephyr RTOS and is using the MbedTLS library for the TLS part. Using the in-tree Zephyr libraries for secure sockets, it is necessary to load the device private key and certificate, in the simplest way from an MCU Flash memory. They are eventually used when calling the functions mbedtls_pk_parse_key() and mbedtls_x509_crt_parse(). My goal is to integrate STSAFE-A110 in this process, so that the device private key and certificate are stored in STSAFE-A110 instead of the MCU Flash. I'd like to get some feedback on whether the process sounds reasonable.
I suppose the process would look something like this:
- While in production, we should provision STSAFE-A110 with the device's individual certificate. It needs to be like this, because authentication in Azure requires that the subject common name is the same as the unique id that the device is registered in IoT Hub.
- First, we should ask STSAFE-A110 to generate a new private key in slot 1.
- Then, we generate a CSR based on this key.
- The CSR is given to the PKI and the device certificate is returned.
- The device certificate is stored in STSAFE-A110 memory zone 1.
- In normal operation, the MbedTLS library should be instructed to establish the TLS connection using the key in slot 1 and the certificate in zone 1.
I suppose we can't avoid step 1 (certificate provisioning in production). It's probably not a good idea to use directly the leaf certificate and private key in slot 0, since all STSAFE-A110 chips share the same PKI.
Step 2 is one topic that I have doubts about whether the whole concept works. As mentioned, the libraries currently require the private key to be present in a buffer in the RAM, but this is of course not going to work, since the private key in STSAFE-A110 cannot be read out. So how to do it? I studied thoroughly the sample code given in this topic by
Additionally, if searching for information inside the github repo of MbedTLS, my understanding is that waiting until the new PSA crypto API is fully rolled-out, with support for opaque drivers for the secure elements, is generally better. See for example here. Any thoughts on this? When using the PSA crypto API and the opaque drivers, is perhaps the only difference that a private key will never exist in the code, not even as a struct? I'm not sure I fully understand this topic.
Any comments are welcome! :)
