With Trust Onboard you will be able to use X.509 certificates on theTwilio SIM to authenticate your devices. In this guide, we will demonstrate how to use Trust Onboard features for your IoT products. Use this guide, along with examples published on GitHub, to learn how to implement Trust Onboard.
The Twilio IoT Breakout SDK for Trust Onboard offers tools and examples which will show you how to utilize the two X.509 certificates, Available and Signing,added to Trust Onboard enabled SIM cards. The SDK can be built as a static or dynamic library and linked to your executable. The SDK currently only offers C bindings, which means you can use it with C and C++ applications, or in other languages using the C FFI. The SDK can be built and installed with CMake. Please follow the instructions published in the repository.
Get the SDK from Github.
On Raspbian you can also install the SDK from our debian repository:
echo "deb https://twilio.bintray.com/wireless buster main" | sudo tee -a /etc/apt/sources.list # Raspbian stretch is also supported sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 379CE192D401AB61 sudo apt update sudo apt install trust-onboard-sdk
Trust Onboard makes SIM certificates available to you so you can add them to your backend service in order to authenticate connections from your devices. There are couple of ways you can get the SIM certificates.
If you have a home-grown backend system, then you can download the SIM certificates and add them to your backend system.
You can also sync your SIM certificates directly with a cloud backend service like Microsoft Azure. To do so, use the Console:
To begin using certificates on your IoT device, you need the Breakout SDK for Trust Onboard.
The Available Key certificate and its associated private key can be read from the SIM card using the Breakout SDK. Your code will have access to the full text of the public and private keys and certificate in PEM form.
The Signing Key certificate can be read in the same way as the Available Key certificate, but the Signing Key itself will stay in the SIM. You utilize TLS libraries such as OpenSSL, mBed or wolfSSL that are able to ask the SIM card to sign requests using the Signing Keys.
Most frequently you will want to use Trust Onboard to establish a TLS connection. With a low-level API you can implement the bindings for your own TLS library. We have already implemented OpenSSL, mbedTLS and wolfSSL bindings for you to use.
Please refer to the samples in Trust Onboard SDK for the details of how to use these bindings. The short code excerpts below demonstrate all three use-cases. Error checking is omitted for brevity. Please refer to theOpenSSL, curl, mbedTLS and WolfSSL documentation to learn how to use these libraries.
If all you want to do is to extract the TLS credentials and feed the, to your application, you might not need to use the Trust Onboard library. For this use-case the Trust Onboard SDK contains a command line utility called
After building and installing the SDK,
trust_onboard_tool can be used as follows:
trust_onboard_tool --device /dev/ttyACM0 --baudrate 115200 --pin 0000 --available-cert ~/available.cert.pem --available-key ~/available.key.pem
Please rfer to the tool’s help screen for more options.
The certificate bundles below contain the CA certificates used to sign the certificates on Twilio SIM cards. Upload this bundle to your backend services as needed. You should use the first bundles unless your SIM has “Certificates on this SIM are valid until December 2020” written on its label.
Generation Two Trust Onboard SIMs (August 2019 onwards)
- Twilio Trust Onboard CA
- Twilio Trust Onboard Available key Intermediate certificate
- Twilio Trust Onboard Signing Intermediate certificate
Generation One Trust Onboard SIMs (Prior to August 2019)
Connecting to Azure IoT Hub involves two steps:
- Registering your device with the Azure Device Provisioning Service (DPS).
- Sending messages to and receiving messages from the IoT Hub itself.
You can refer to the temperature measurement sample in the Trust Onboard SDK for a comprehensive example showing both of these steps; below you can find short code excerpts which show the steps in a more brief way.
Note At the time of writing, Trust Onboard requires you to use Twilio’s fork of Azure IoT SDK. On Raspbian it can also be installed from Twilio's debian repo:
echo "deb https://twilio.bintray.com/wireless buster main" | sudo tee -a /etc/apt/sources.list sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 379CE192D401AB61 sudo apt update sudo apt install azure-iot-sdk-twilio-dev
Registering a device with the DPS involves establishing a TLS connection to an Azure URL,
global.azure-devices-provisioning.net. Depending on which certificate you use, DPS will return to you your device’s ID and the IoT Hub URL it should connect to to register itself.
The output of the actual registration process is a ‘connection string’ that will be used to provision the device.
Functions to perform these tasks are shown in the next code sample.
Note Your certificate should be pre-registered with the DPS. Please see the Broadband Kit documentation for detailed instructions.
The connection string retrieved during the DPS registration can now be used to talk to the IoT Hub, as shown in the next code sample. Some further setup will still need to be done to use Trust Onboard for IoT Hub communication.
Note Refer to Azure IoT Hub documentation to learn how to send and receive messages. The sample will only show the setup process.
You can use the Azure IoT SDK for Python, installable via
pip, to perform the device registration, and to send and receive messages to and from the IoT Hub. As the Python SDK and Python SSL library do not support cryptographic hardware, only the Available Key can be used with Python. To extract the key from the SIM card, use
trust_oboard_tool. Please see the Python sample on GitHub for more details.
誰しもが一度は考える「コーディングって難しい」。そんな時は、お問い合わせフォームから質問してください。 または、Stack Overflow でTwilioタグのついた情報から欲しいものを探してみましょう。