mqttmosquittoclient-certificatesazure-eventgridlibmosquitto

How to subscribe to azure event grid with mosquitto_sub and certificate


I am working on Azure event grid (using it as an MQTT Broker) following this tutorial to generate the client certificates Azure-event grid-generate-sample-client-certificate-and-thumbprint

On my machine it looks like: enter image description here

And I know everything is correct because I can publish/subscribe as described in the tutorial via MQTTX

But how in the world is it possible to pub/sub via mosquito?

I tried:

mosquitto_sub -h host.azure.net -p 8883 -t "topic/test/#" --username client-device1 --cafile /home/daniel/.step/certs/root_ca.crt

Error: A TLS error occurred.

The same error if I use the generated client-device1-auth-ID.pem

And it gets even more confusing if you want to use libmosquitto.. what do you set here:

mosquitto_username_pw_set(_mosq, kUserName.c_str(), ???);
//or here: 
mosquitto_tls_set(_mosq, cafile, capath, certfile, keyfile, callback);

So my question is how can I connect via mosquito(_sub/_pub) to my azure mqtt broker (which works via MQTTX using the generated certificates from Azure-event grid-generate-sample-client-certificate-and-thumbprint)

Could the problem be related to the passphrase one has to enter during the certificate generation?


Solution

  • 3 Steps to make it work

    1.) Client authentication has to be "subject Matches Authentication Name"

    2.) You have to set mosquitto_int_option(_mosq, MOSQ_OPT_TLS_USE_OS_CERTS, true);

    (even if you do not have any os certs installed)

    3.) mosquitto_tls_set(_mosq, nullptr, "L", pem.c_str(), key.c_str(), nullptr);