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
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #performance










First 5 of 5 Posts
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.
LostKobrakai
As mentioned on slack many of those setting need to be charlists instead of binaries based on the specs on the emqtt repo and ones pointed to on OTP:
You can prefix the quoted values with
~c"…"to make them charlists.clientidis speced as iodata, which is a supertype to binary, so that one is fine.tomazbracic
I did that as well.
And this still don’t work. Though now I get bunch of messages like this - reconnecting
jjcarstens
I have not used emqtt, but have 2 thoughts to try:
Outside of that, I’m unsure. I think we need the SSL debug logs here to maybe be useful. Or reach out to the library maintainers. There is nothing different starting it on server, host, or nerves device
tomazbracic
This is now what works. I found the right configuration.
Thanks for the help.