I am using ESP32C3 using ESP-IDF. I have connected ATECC608B (TrustFlex) via i2c with my ESP32C3. My goal is to read the device certificate from the TrustFlex and connect to the Azure IoTHub. I have already configured the certificate and manifest file of my secure element in the IotHub.
I have successfully generated the public key from slot 0 and using that I was able to reconstruct the device certificate and signer certificate. Verification also came back with Success.
Now coming to the real issue; Azure SDK for C uses x.509 certificated and symmetric keys for connecting to the IoTHub. When using x.509 certificate, SDK requires 3 things:
- IOT Device ID
- Device Certificate
- Private Key
I have already fetched the Device ID and device certificate from the secure element but what to do with the private key? Since we cannot read private key from the secure element. I researched alot on this but didn't find anything useful. I looked into this example of ATECC608 in ESP-IDF link here It uses function atca_mbedtls_pk_init() to initialize hardware private key for EC operations. Can somebody point out if I am looking in right direction of the problem? If not how to resolve this issue since MQTT client requires:
esp_mqtt_client_config_t mqtt_config;
memset(&mqtt_config, 0, sizeof(mqtt_config));
mqtt_config.uri = mqtt_broker_uri;
mqtt_config.port = mqtt_port;
mqtt_config.client_id = mqtt_client_id;
mqtt_config.username = mqtt_username;
#ifdef IOT_CONFIG_USE_X509_CERT
Serial.println("MQTT client using X509 Certificate authentication");
** mqtt_config.client_cert_pem = IOT_CONFIG_DEVICE_CERT;
mqtt_config.client_key_pem = IOT_CONFIG_PRIVATE_KEY;**
Serial.println(mqtt_config.client_key_pem);
#else
LOGS: Error
Useful Links: Azure SDK for C CryptoAuthLib v3.3.1
The device
ATECC608Bis a secure element, and it is designed to protect the private key and prevent it from being extracted. Hence you cannot directly read the private key from the secure element.And this device provides an API that allows you to sign data using the private key without exposing the key itself.
Steps to follow
Initialize the device ATECC608B and establish a secure connection to it using I2C.
And use the ATECC608B API to sign data. You need to sign the data that Azure IoT Hub requires for authentication.
And pass the signed data or signature using Azure IoT Hub SDK for C as the private key.
Thanks to
shinigami35for the code reference.Sample code to signIn using C#
Use the Azure IoT Hub Device Provisioning Service (DPS) to provision simulated X.509 device And sign an HTTP request with an HMAC signature for Azure Communication Services using C#
The implementation details will depend on the SDK you are using to interact with the ATECC608B and the Azure IoT Hub SDK for C.
For certificate details refer SO link.
For more information refer to the GitHub Link and Azure IoT SDK in ESP-IDF.