tomazbracic

tomazbracic

EMQTT client configuration for mTLS

Dear all,

I am building a nerves based firmware where I will be using mTLS. For that I build my own CA and generated all the certificates. For shipping data I will be using emqtt client.

I have successfully connected and I am able to send messages between client and server service which is as well built with elixir. In-between there is NGINX on cloud edge for TLS termination and MQTT broker where messages go to.

WANT TO DO:
gateway <---- mTLS port: 8883 ------> Nginx <---- port: 1883 -----> EMQX broker ↔ my cloud service

TESTING:
mqttx GUI app <---- mTLS port: 8883 ------> Nginx <---- port: 1883 -----> EMQX broker ↔ my cloud service

I can use certificates and test everything with my MQTTX app. It works and I can see client connected to broker.

If I try to use the same certificates later with my “want to do” setup, so in elixir I get full of reconnections in my logs and one of the error that bothers me is something around hostname

16:52:58.810 [notice] TLS :client: In state :wait_cert at ssl_handshake.erl:2182 generated CLIENT ALERT: Fatal - Handshake Failure
 - {:bad_cert, :hostname_check_failed}

16:52:58.810 [info] Starting MQTT Client

16:52:58.811 [info] Client ID set to: testko

16:52:58.811 [debug] Timer set to 5000 milliseconds

16:52:58.944 [notice] TLS :client: In state :wait_cert at ssl_handshake.erl:2182 generated CLIENT ALERT: Fatal - Handshake Failure
 - {:bad_cert, :hostname_check_failed}

16:52:58.944 [info] Starting MQTT Client

16:52:58.944 [info] Client ID set to: testko

though... I used the same certs in MQTTX app on the same dev laptop and was successfully connected. So I guess there is still configuration issue?

My configuration is

config :testko, :emqtt,
  host: "prefix.mydomain.com",
  port: 8883,
  clientid: "testko",
  clean_start: false,
  ssl: true,
  ssl_opts: [
    cacertfile: "certs/ca-chain.cert.pem",
    certfile: "certs/client3.cert.pem",
    keyfile: "certs/client3.key.pem",
    tls_versions: [:"tlsv1.2", :"tlsv1.3"],
    verify: :verify_peer,
    fail_if_no_peer_cert: true
  ],
  name: :emqtt,
  reconnect: true,
  reconnect_interval: 10000

I even tried puthing cacertfile, certfile and keyfile in single quotes. Nothing really works.

Can anyone see anything problematic in my configuration? Does anybody have emqtt client configured with mTLS and actually works?

I would really appreciate any help/feedback/direction/blog/tutorial/doc where this would be explained.

Thanks in advance!

Tomaz

First Post!

tomazbracic

tomazbracic

I tested the certificates with openssl tool as well. Based on that PKI part is ok. mTLS works. But how to configure this with emqtt is now a mistery to me.

Most Liked

tomazbracic

tomazbracic

This is now what works. I found the right configuration.

config :testko, :emqtt,
  host: "prefix.mydomain.com",
  port: 8883,
  clientid: "testko",
  clean_start: false,
  ssl: true,
  ssl_opts: [
    cacertfile: ~c"/root/certificates/ca-chain.cert.pem",
    certfile: ~c"/root/certificates/client-nemo_gw_1.cert.pem",
    keyfile: ~c"/root/certificates/client-nemo_gw_1.key.pem",
    tls_versions: [:"tlsv1.2", :"tlsv1.3"],
    verify: :verify_peer,
    server_name_indication: ~c"prefix.mydomain.com"
  ],
  name: :emqtt,
  reconnect: true,
  reconnect_interval: 10000

Thanks for the help.

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40165 209
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

We're in Beta

About us Mission Statement