MQTT one-way SSL authentication
Tags: mqtt, ssl, authentication, tutorial
Published: 2021-08-26 09:13:47

---
title: MQTT one-way SSL authentication
published: true
date: 2021-05-04 06:35:23 UTC
tags: #mqtt, #ssl, #authentication, #tutorial
canonical_url: https://tech.forums.softwareag.com/t/mqtt-one-way-ssl-authentication/241021
---

About MQTT(Tech Community): [Mqtt-support-and-configuring-integration-server-for-mqtt-messagin](https://tech.forums.softwareag.com/t/mqtt-support-and-configuring-integration-server-for-mqtt-messaging-on-is-10-5/237326)

## Introduction:  
Using the MQTT broker, user should be able to create MQTT connection using one-way authentication (only mqtt server authenticates via the certificate). This article details the steps on creating the MQTT one-way connection alias and publish and subscribe messages using Integration server.

## Pre-Requisites:  
• Download “mosquitto-1.6.9-install-windows-x64” from [https://mosquitto.org/files/binary/win64](https://mosquitto.org/files/binary/win64/%E2%80%9D) site on your Windows machine and run the installer file as Administrator  
• To monitor and administer the “Mosquitto Broker” you can download and install client tools “mqtt-1.7.1-windows-x64.exe” from [Download](https://mqttfx.jensd.de/index.php/download) you can then connect to MQTT server  
• Using below openssl commands, generate Client certificate, Server certificate, Server key and truststore file  
a) openssl genrsa -des3 -out ca.key 2048  
b) openssl req -new -x509 -days 1826 -key ca.key -out ca.crt  
c) openssl genrsa -out server.key 2048  
d) openssl req -new -out server.csr -key server.key  
e) openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 360  
f) Import Client cert to truststore file in /common/conf location by using below command:  
keytool -import -alias teiid -file ca.crt -storetype JKS -keystore platform\_truststore.jks  
• Copy ca.crt, server.crt and server.key files to mosquito installation folder (C:\ProgramFiles\mosquitto)  
• Replace the existing truststore file with updated file platform\_truststore.jks in location /common/conf.  
• Edit mosquitto. Conf file in mosquitto installation directory with the below changes in default listener section  
a) port 8883  
b) cafile C:\Program Files\mosquitto\ca.crt  
c) keyfile C:\Program Files\mosquitto\server.key  
d) certfile C:\Program Files\mosquitto\server.crt  
e) tls\_version tlsv1.1  
• Go to windows services and start “Mosquitto Broker” service if already “Running” then “Restart” the service  
• Check if the Mosquitto broker is running on port 8883 by command  
netstat -an or netstat - an|find “8883”  
 ![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/4/c/4cc12aec40c65ad63d8d9d84201e8b393f84a798.png)  
• Also check the connectivity by launching mqttfx client tools (mqttfx-1.7.1-windows-x64.exe)and connect to “Mosquitto Broker”, publish message on the selected topic and subscribe to the messages on the same topic as shown below  
 ![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/a/e/aeefef94f31427c81b34e8476691ed427e908313.png)

![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/3/e/3e95d6a0856b2ae5ef3cf790eecab2fbc58c0044.png)

![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/4/9/49dea95887b159faed19389d63ae04c5baba8451.png)

![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/4/d/4d1edfb61bd44439ad236dd25e16fa03f7f06379.png)

## Creating MQTT one-way SSL connection alias in IS:

In one- way SSL authentication, mqtt sever authenticates the client via certificate. Here we are using the truststore file (platform\_truststore.jks) generated using the ca.crt in pre-requisites step.  
Below steps details on creation of truststore alias and creation of MQTT connection alias in IS:
1. Update the truststore alias by providing the proper passphrase
![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/8/0/80cb2cbfaf1c4c38632245a2a9a52ebef7fbbcd1.png)
2. Create MQTT connection with SSL enabled and Truststore key  
 ![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/8/e/8e183a81548611d7950801404c90ab35e69cc51e.png)  
3. Verifying publish and Subscribe of messages to topic on MQTT broker using Integration Server  
• Launch designer and connect to integration sever.  
• Create package and folder MQTTDemov10\_5 in designer  
• Create publish flow service in MQTTDemov10\_5 folder using the built-in service **pub.mqtt:publish**.
![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/6/f/6f7dd3fbe117353b65fab2e51db7ceec57b9fd2d.png)
![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/a/8/a8d529f7f064e19e7b504308eae4bb62adafc850.png)
• Create another flow service subscribe to check the server log in integration server if the message is successfully subscribed from MQTT Server Topic
![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/9/7/97759ab73b6b6d410c6fef5b97dd5623ee637f7c.png)
![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/e/5/e5d95b55a1add757e0c4a84bb3e280a596438c04.png)
![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/9/c/9cf52b801066869888f0baa8590c5c5969885bc4.png)
• Integration Server can subscribe to topics by creating an MQTT trigger. The MQTT trigger receives messages published to the topic on the MQTT server and then invokes a trigger service to process the messages.  
• Integration Server uses an MQTT connection alias to create a connection to the MQTT server. An invocation of the pub.mqtt:publish service requires the MQTT connection alias to publish the message to the MQTT server. Similarly, an MQTT trigger specifies the MQTT connection alias that it uses to identify the MQTT server from which it retrieves messages and on which the trigger creates subscriptions.
![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/b/6/b6c5af3549e2aa08f2b7c44812283ff44b0088e5.png)
• Run the Publisher service
![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/b/9/b9212d47ecb22b8b346956b2e1a9e678799bc7f2.png)
4. Verify message in server log of integration server
![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/4/3/437a439ed17686908851445d58e2d4d21ceeb5c4.png)
5. Messages in mqttfx client  
 ![image](https://aws1.discourse-cdn.com/techcommunity/original/3X/a/9/a9c7b3c9d079133139c768bc78d357ab25d0f776.png)

[Read full topic](https://tech.forums.softwareag.com/t/mqtt-one-way-ssl-authentication/241021)