MQTT with TLS on BX3105

I want to use the MQTT protocol to connect to the AWS IOT MQTT broker. (BX FW version 2.6.3)

The broker requires that the connection uses a X.509 Certificates to authenticate. When creating a “thing” on the platform you are supplied with a:

  • rootCA for AWS.
  • Certificate (local)
  • Private Key
    Using commands : AT+KCERTSTORE=0, AT+KCERTSTORE=1 and AT+KPRIVKSTORE=0 I uploaded the 3 files to the BX3105. All command executed with OK and querying the certs: AT+KCERTSTORE? returns the information for the 2 Certs.
    Querying the private key AT+KPRIVKSTORE? returns: +CME ERROR: 918

I then setup the the MQTT session with TLS active:
AT+KMQTTCFG=1,“a3e1k5xqxzxwj6-ats.iot.eu-west-1.amazonaws.com”,8883,4,“BX_one”,

Connecting to the broker fails after about 3 seconds:
AT+KMQTTCNX=1
OK
+KMQTT_IND: 1,0

Using the MQTT protocol to connect to non-secure brokers works and publishing data is possible.

Is there something wrong with my certs or key?

You can download stunnel and run in client mode to test your cert and key first.

Thank you, will look into using stunnel.

As the FW is constantly improved and the AT+KPRIVKSTORE? returns “FEATURE_NOT_SUPPORTED” although the AT Command Reference say it must return the key data.

I just want to confirm that the BX310x FW 2.6.3 can do MQTT with TLS? Has this been tested on a 3rd party Broker with TLS on?

i remember i tried MQTT command with TLS, I can see it can pass through the SSL layer set up by stunnel server.
But i don’t have a MQTT server, so I did not go further.

I can help with that:

Here is the root cert for Amazon:
-----BEGIN CERTIFICATE-----
MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF
ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6
b24gUm9vdCBDQSAxMB4XDTE1MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMFowOTEL
MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJv
b3QgQ0EgMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALJ4gHHKeNXj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zDlHbB37D6ELVQpB
07p44mN0tPv9wDm/HHN7VOh6YZS8M0ZG/sh4oac/085qu11lxfMHBU1gs68/sd3t
VX1gMN5W9XlfOT/sFI+9IQKBgQCTxwWMSyyWRHXC6boMgryIJgs/+BdBhy6J0Lt8
TAIxszldN/7tyt2edBd6Z5v8Kcuml0cyC0DB23w1mc6meOyetqyZWKY5y83JDY1L
Jh0QetqExoyFOWzlDzYFiNfm3oIIaPPV74tbiSBfklFtrY7Q6rcNmgjq6sz4tDDu
PzrNxQKBgQCmiqQc6XwvHn51FC8OFudf//euPOe9MNfG2kQ58xNkVPubzV+XBg0h
HdjoMWWf58ZZsrAQtkfVaxcMaXpTW8PIdAoqfVSsgHCaRonceROOX5I7UIwQ4iw9
LS938HmFrgYnr8x5NnBBa6HyKAdd+DIV1Nr0NcX/z4/LIHmL5NMgZQ==
-----END RSA PRIVATE KEY-----

And here is the server url:
a3e1k5xqxzxwj6-ats.iot.eu-west-1.amazonaws.com

The broker will accept any topic, but ““sdk/test/Python”” is given in the example code from AWS.

OK, you can try with stunnel client mode to verify the certificate and key first.

Not having any experience with stunnel, this will take a significant amount of my time to setup.

Is there any reason to believe that the certificates provided / generated by Amazon is incorrect?
These certificates work using their python example program to connect to the broker.

When uploading them to the BX3105 the module confirms “OK” after each certificate. So I am confident that the uploading process is correct.

Can you confirm that the BX3105 with FW 2.6.3 has been tested to connect to an MQTT broker using the TLS mode?

After you verify the certificate and key are correct by stunnel in client mode, you can connect the BX to this stunnel and capture the wireshark log in raw data mode.

Or you can setup a stunnel server and connect the BX to this server in TLS mode and see if it works.

Thank you very much for the quick replies, I really appreciate your assistance.

But, I’m no security expert. I’m an embedded systems engineer this will take me a significant amount of time to figure out (I have never used Stunnel or WireShark).

If I do manage to do the above mentioned steps, what do I do with the logs? I cannot interpret it ?

Won’t it be much easier for the engineer responsible for the FW on the BX to setup a free acount on AWS IOT and test MQTT with TLS on to check if it works? Or use the certs I supplied above to test if he can connect to the AWS IOT broker.

Setting up a MQTT borker is easy with AWS IOT:

i tried a TCP connection, it is failed…


Connecting to a3e1k5xqxzxwj6-ats.iot.eu-west-1.amazonaws.com
TCP connection error :10049


Hi

That is url is specifically an MQTT borker on port 8883, will it accept a TCP connection? (I’m not an IP expert)

AT+KMQTTCFG= 1 ,“a3e1k5xqxzxwj6-ats.iot.eu-west-1.amazonaws.com”,8883,4,“BX_one”,
AT+KMQTTCNX=1
OK

SSL connection is on top of TCP.
That means your server cannot be connected.

Please also verify your SSL cert and key first.

We have tested our Certs with other applications connecting to AWS IOT and the SSL Cert and Key is correct.

What is the next step?

you can setup a stunnel server and see what is the SSL connection error after
AT+KMQTTCNX=1

I’m trying to accomplish the same thing, but I cannot get the RootCA into the BX3105 using the AT+KCERTSTORE=0 command. Anything I should be looking for? Using the same file you’re using.
Thanks,
Eric

what do you mean "cannot get the RootCA into the BX3105 "?

When I copy the certificate after the CONNECT response to AT+KCERTSTORE=0, I enter +++, then get an ERROR response.

not sure if your newline character is using “CR+LF”

That’s a good thought, I’ll check it. Anything else you can think of that I’ll run into when connecting to AWS IoT?