Connect an application to the EMQX broker on Amazon IoT SiteWise Edge
The EMQX broker uses Transport Layer Security (TLS) on port 8883 to encrypt all communications, ensuring your data remains protected during transmission. This section walks you through the steps to establish connections between your applications and the EMQX broker. Following these steps helps maintain the integrity and confidentiality of your industrial data. The connection process involves two main approaches: using automated IP discovery through components, or manually configuring DNS names and IP addresses as Subject Alternative Names (SANs) in your TLS certificates. Each method has its own advantages depending on your network setup and security requirements. This documentation will guide you through both options.
Topics
Configure TLS for secure connections to the EMQX broker on Amazon IoT SiteWise Edge
By default, Amazon IoT Greengrass generates a TLS server certificate for the EMQX broker that is signed by the core device certificate authority (CA). For more information, see Connecting client devices to an Amazon IoT Greengrass Core device with an MQTT broker.
Retrieve the TLS certificate
To get the CA certificate run the following command on the gateway host:
Copy the contents of the ca.pem file to the external application that
you're connecting to the broker. Save it as
BrokerCoreDeviceCA.pem
.
Add custom DNS names/IP addresses to the TLS server certificate
The subject alternative name (SAN) on the cert generated by Amazon IoT Greengrass is
localhost
. When establishing a TLS connection from
outside of the gateway host, the TLS verification step fails because the
broker’s hostname does not match the hostname of localhost
on the server certificate.
To address mismatched hostname issue, Amazon IoT Greengrass provides two ways of managing core device endpoints. This section covers both options. For more detailed information, see Manage core device endpoints in the Amazon IoT Greengrass Version 2 Developer Guide.
-
To connect to the EMQX broker using the core device's IP address, use the Automated IP discovery section.
-
To connect to the EMQX broker using a DNS name instead of IP address, you use the Manual management section.
Test the EMQX broker connection on Amazon IoT SiteWise Edge
After configuring your EMQX broker with TLS certificates and authentication credentials, it's important to verify that your setup works correctly. Testing the connection helps ensure that your security configurations are properly implemented and that clients can successfully establish encrypted connections to the broker. This section demonstrates how to test your broker connection using the Mosquitto command line interface (CLI) client, a widely-used MQTT client tool that supports TLS encryption and authentication.
Use Mosquitto CLI client to test the EMQX broker connection
In this step we will use the mosquitto CLI client to test our setup
and make sure we can connect successfully to the broker using the
username and password we created earlier. To get the
BrokerCoreDeviceCA.pem
follow steps under Step 3:
Setting up TLS.
mosquitto_sub -h
hostname|ip address
\ -p 8883 \ -t "#" \ -q 1 \ -uusername
-Ppassword
\ --cafile BrokerCoreDeviceCA.pem
Note
You may get an SSL:verify error if the hostname/IP address you are connecting to does not match the Subject Alternative Name (SAN) that is on the CA cert you're passing to the client. See "Adding custom DNS names/IP addresses to the TLS server cert" under Step 3: Setting up TLS for how to get a certificate with the correct SAN.
At this point, all users have access to publish and subscribe to all topics on the broker. Proceed to Set up authorization rules for Amazon IoT SiteWise Edge in EMQX.
Use your own CA
Amazon IoT Greengrass outlines how to configure your own client device auth component to
use your own certificate authority (CA). The client device auth component
(aws.greengrass.clientdevices.Auth
) authenticates client
devices and authorizes client device actions. For more information, see
Using your own certificate authority in the
Amazon IoT Greengrass Version 2 Developer Guide.
To use your own CA, add the aws.greengrass.clientdevices.Auth
component to your deployment so that you can specify a custom
configuration.