Android MQTT TLS/SSL authentication

MQTT is a lightweight, flexible IoT message exchange and data transfer protocol that aims to balance flexibility with hardware/network resources for IoT developers. In order to ensure secure communication, TLS/SSL is often used for communication encryption.

This article mainly introduces how to perform TLS/SSL one-way and two-way authentication via Android and MQTT.

Preparation

This article uses Eclipse Paho Android Service and to add dependencies

Here is the core code section for Android to connect to TLS/SSL

The focus is on how to obtain the . The one-way and two-way authentication are described below.

One-way authentication

One-way authentication means that the server-side authenticates the client. The core code is as follows:

We put under and call:

Two-way authentication

Two-way authentication means that the server-side and client authenticate each other. The core code is as follows:

We need to prepare the server-side certificate, and put the client certificate and secret key under , and then call. Taking care that the password is set to an empty string.

This is how to perform TLS/SSL one-way and two-way authentication with MQTT on Android.

Copyright notice: this article was originally written by EMQ. If you want to reprint, please indicate the source clearly. The link of original article:https://www.emqx.io/blog/android-mqtt-ssl-tls-authentication

EMQ is an open-source IoT data infrastructure software provider, delivering the world’s leading open-source MQTT message broker and stream processing database.