Secure your MQTT connection
Why use Secure MQTT protocol?
Using MQTT with TLS enabled provides privacy and data integrity between your devices/applications and Live Objects. It guarantees that your device/application is communicating with the authentic Live Objects platform, and it prevents a malicious third-party from eavesdropping or tampering. Using secure TLS communication is becoming a de facto standard when communicating over internet as more and more software / operating systems / Hardware refuse to communicate over non-encrypted protocols. Live Objects offers several levels of security that require adapted credentials according to the expected level of security.
MQTT security levels
3 security levels are available, for each one, the authentication is protected by TLS protocol and credentials, the client must have in its truststore and keystore the credentials below :
Authentication\ Credentials |
Authentication level |
clientId |
API_KEY |
Root CA certificate |
Client certificate |
MQTT |
basic authentication |
☑ |
☑ |
☐ |
☐ |
MQTTS server authentication |
secured authentication |
☑ |
☑ |
☑ |
☐ |
MQTTS server and client authentication |
high secured authentication |
☑ |
☑ |
☑ |
☑ |
MQTTS server authentication
A connection to the MQTT server secure endpoints requires that the MQTT clients maintain an up-to-date list of trusted root CA (Certificate Authority) certificates in order to seamlessly handle periodic server certificate updates.
Go further with server and client authentication
Live Objects goes beyond server authentication and implements client authentication based on your own Certification Authority (CA). When enabled for a given API Key, Live Objects will:
-
make sure that only TLS with client authentication is made with this API key when used for MQTT connections
-
make sure that the client certificate has been signed by one of the CA certificates associated to the API key used by the device,
-
verify the identity of the device, by checking that client certificate’s Common Name (CN) matches the device id (in the MQTT client id). This last verification is done for MQTT “device” mode only. (i.e. not for MQTT “application” and “connector” mode)
| Live Objects does not provide PKI services, but you can configure your Live Objects account to use your own PKI’s certificates. For the time being, a maximum limit of 10 certificates is set for a tenant. |
Client certificat CA issuer requirements
Standard extensions
Basic constraints
A CA issuer certificate (which signed your client certificate) must include the basicConstraints value with the CA field set to TRUE. An end user certificate (device) must either set CA to FALSE or exclude the extension entirely.
You must check key usage extension of your CA issuer certificate, here are some common rules to consider :
Extension KeyUsage defined
In this case the KeyUsage extension must contains the permitted key usage with keyCertSign value. It can only be used to sign end user certificates and not further CAs. The end user certificates are used by the devices.
For example:
basicConstraints=CA:TRUE keyUsage= keyCertSign <--
Extension KeyUsage not defined
Nothing to do. Your CA issuer can sign your devices certificates.
For example:
basicConstraints=CA:TRUE without KeyUsage extension <--
| Otherwise, in case where this rules are not respected, your CA certificate is rejected by Live Objects. |
How to setup client authentication
The client authentication setup is done in 2 steps:
-
Make Live Objects aware of your Certification Authority (CA) by configuring the CA certificate which used to sign the devices certificates.
-
Check that your CA certificate meets standard requirements.
-
Associate that CA certificate with the API key used by your devices/external connector. This will force all communications to Live Objects using MQTT using that API key to be secured with a client certificate (or it will be rejected).
-
Generate a client certificate, signed with your CA certificate, with the MQTT
Client IDas common name (CN) (for MQTT "device" mode only).
| Client authentication is only available for MQTTS protocol. MQTT over secure websocket connection does not support client authentication. |
1. Configure your Certification Authority’s intermediate certificate on Live Objects
Generate a key pair.
openssl genrsa -out rootCA.key 2048
Use the key pair to generate your CA certificate.
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.pem
Configure your certificate on Live Objects:
POST /api/v0/certificates/ca
{
"certificate": "your pem formatted certificate",
"comment": "my awesome intermediate CA certificate"
}
This call will return an id for your certificate.
| Only provision the CA’s intermediate certificate that directly signed the device Certificate Signing Request (CSR). |
{
"id": "your_certificate_id"
}
To get a JSON compliant string of your pem certificate you can use the command line tool jq : cat rootCA.pem | jq -R --slurp
|
2. Associate this certificate with an Api Key
POST /api/v0/apiKeys/{your-api-key-id}
{
"clientCert": {
"caCertIds": [
"your-certificate-id1",
"your-certificate-id2"
],
"required": true
}
}
Once a certificate is associated with an Api Key and clientCert.required=true client authenticated MQTTS connection will be mandatory, otherwise the MQTT(s)/websocket connection will be closed with a Bad username or password error.
|
3. Generate a client certificate for a device with id *your-device-id*
Create a key pair for the device.
openssl genrsa -out deviceCert.key 2048
Create a certificate signing request from your key pair
openssl req -new -key deviceCert.key -out deviceCert.csr
Enter the information when prompted
Country Name (2 letter code) []:
State or Province Name (full name) []:
Locality Name (for example, city) []:
Organization Name (for example, company) []:
Organizational Unit Name (for example, section) []:
Common Name (e.g. server FQDN or YOUR name) []: <--------- ENTER YOUR DEVICE URN HERE
Email Address []:
Generate the device certificate by signing the CSR with your Certification Authority intermediate key.
openssl x509 -req -in deviceCert.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out deviceCert.pem -days 365 -sha256
4. Try it
Try your newly configured MQTTS with client configuration by sending a new data on the dev/data topic. We will be using the node mqtt.js client:
mqtt publish -h "mqtt.liveobjects.orange-business.com" --port 8883 -i your-device-id -q 0 -u json+device -C mqtts -t dev/data -m '{"s": "myStreamId", "v": {"temp": 12}}' --key your-cert-private-key --cert your-cert.pem --ca liveObjects.ca.cert.pem -P your-api-key
Once a certificate is associated with an Api Key and clientCert.required=true client authenticated MQTTS connection and MQTTS endpoint usage will be mandatory (see how to use MQTTS).
|