Porovnávané verzie

Kľúč

  • Tento riadok sa pridal
  • Riadok je odstránený.
  • Formátovanie sa zmenilo.

...

About Eclipse Mosquitto

...


Eclipse Mosquitto je  is an open-source MQTT broker s podporou supporting the MQTT protokolu protocol 5.0, 3.1.1 a , and 3.1. Podporuje autentifikáciu, certifikáty a je malý a jednoducho konfigurovateľný. Je použiteľný aj na vytvorenie redundantného riešenia s nasledovnou konfiguráciou:It supports authentication, certificates, and is small and easy to configure. It can also be used to create a redundant solution with the following configuration:

  • There are two redundant application servers (physical or virtualized) - Windows or Linux.
  • On both servers, D2000 Servers are running as a redundant application
  • Sú dva redundantné aplikačné servery (fyzické alebo virtualizované) - Windows alebo Linux.
  • Na oboch serveroch sú spustené D2000 Servery ako redundantná aplikácia (Master/Standby).Na oboch serveroch sú spustené MQTT brokery
  • On both servers, Eclipse Mosquitto , nakonfigurované v režime TLS s certifikátom podpísaným certifikačnou autoritou. Sú spustené bez konfigurácie výmeny správ medzi sebou, t.j. každý z nich je úplne nezávislý.MQTT brokers are running, configured in TLS mode with a certificate signed by a certification authority. They are running without configuring message exchange between them, i.e., each of them is completely independent.
  • D2000 Kom process has a configured D2000 Kom proces s nakonfigurovanou linkou TCP/IP-TCP Redundant, s nakonfigurovaným overovaním certifikátu MQTT servera a s nakonfigurovanými certifikátmi. D2000 KOM je teda pripojený k obidvom MQTT serverom súčasne.
  • Ostatní klient (PLC a iné) sú pripojení aspoň k jednému z MQTT serverov (t.j. umožňujú nakonfigurovať 2 IP adresy MQTT serverov, voči ktorým sa snažia striedavo nadviazať spojenie).
  • Na overovanie totožnosti všetkých klientov sa používajú TLS certifikáty podpísaným certifikačnou autoritou.

Tento dokument uvádza príklad základnej konfigurácie MQTT brokera Eclipse Mosquitto.

Konfiguračný súbor mosquitto.conf

  • line, with configured MQTT server certificate verification, and with configured certificates. D2000 KOM is therefore connected to both MQTT servers simultaneously.
  • Other MQTT clients (PLC and other devices) are connected to at least one of the MQTT servers (i.e., they allow you to configure 2 IP addresses of MQTT servers to which they try to establish a connection alternately).
  • TLS certificates signed by a certification authority are used to verify the identity of all clients.

This document provides an example of a basic configuration of the Eclipse Mosquitto MQTT broker.

Configuration file mosquitto.conf

The example shows the configuration on Windows; the paths on Linux OS need to be adjusted (the configuration file itself can be located, for example, in Príklad ukazuje konfiguráciu na Windows, cesty na OS Linux je nutné upraviť (samotný konfiguračný súbor sa môže nachádzať napr. v /etc/mosquitto/mosquitto.conf).

Info
titlemosquitto.conf
#MQTTS listener on port 8883
listener 8883
#broker certificate
certfile c:\Program Files (x86)\mosquitto\broker.crt
#broker private key
keyfile c:\Program Files (x86)\mosquitto\broker.key
#require valid certificates of clients
require_certificate true
#file with certificate authority's public key(s)
cafile c:\Program Files (x86)\mosquitto\caMQTT.crt
#use CN (Common Name) of client certificate as username (and ignore MQTT username+password)
use_identity_as_username true
#password file is not used for username/password verification (due to use_identity_as_username true)
#password_file pwfile
#acl file with defined access rights
acl_file c:\Program Files (x86)\mosquitto\myacl.conf

Poznámka: Je možné overovať MQTT klientov aj na základe mena a hesla. V tom prípade musí byť vypnuté použitie identity a zadefinovaný súbor s heslamiNote: It is also possible to authenticate MQTT clients based on name and password. In this case, the use of identity must be disabled and a password file must be defined:

use_identity_as_username false
password_file c:\Program Files (x86)\mosquitto\pwfile

V súbore pwfile je nutné zadefinovať mená a heslá užívateľov pomocou utility In the pwfile file, you need to define usernames and passwords using the mosquitto_passwd . Pri prvom použití je nutné použiť prepínač -c  na vytvorenie súboru, pri ďalších to už nie je potrebné. Parameter -b aktivuje dávkový režim, ktorý umožňuje zadávanie hesiel z príkazového riadkuutility. The first time you use it, you need to use the -c switch to create the file, but this is not necessary for subsequent uses. The -b parameter activates batch mode, which allows you to enter passwords on the command line:

mosquitto_passwd.exe -b -c pwfile myuser1 mypassword1
mosquitto_passwd.exe -b pwfile myuser2 mypassword2

PozorWarning: Ak sa overujú MQTT klienti na základe mena a hesla a zároveň sú vyžadované certifikáty, nikde nie je definovaná väzba medzi užívateľom a certifikátom.  Takže ak by užívateľ získal certifikát (a súkromný kľúč) iného užívateľa, mohol by ho použiť na pripojenie k MQTT brokeru.

Konfiguračný súbor myacl.conf

Konfiguračný súbor obsahuje pravidlá pre MQTT klientov, ktoré definujú, aké MQTT topicy môžu čítať (subscribe) a zapisovať.

Príklad pre jednoduchých MQTT klientov:

If MQTT clients are authenticated based on name and password, and certificates are required, there is no defined binding between the user and the certificate. So if somebody were to obtain another user's certificate (and private key), they could use it to connect to the MQTT broker.

Configuration file myacl.conf

The configuration file contains rules for MQTT clients that define which MQTT topics they can read (subscribe to) and write to.

Example for simple MQTT clients:

  • MQTT client with certificate containing Common Name=myPLC, publishing data with topic PLC1/out and receiving commands with topic PLC1/cmd
  • MQTT client with certificate containing Common Name=myD2000, reading data with topic PLC1/out and sending commands with topic
  • MQTT klient s certifikátom Common Name=myPLC, zverejňujúci dáta s topicom PLC1/out a prijímajúci príkazy s topicom PLC1/cmd
  • MQTT klient s certifikátom Common Name=myD2000, čítajúci dáta s topicom PLC1/out a posielajúci príkazy s topicom PLC1/cmd


Info
titlemyacl.conf
#user without username: anonymous is forbidden, but just to make sure: deny everything
topic deny

#MQTT client myPLC: writes to PLC1/out, subscribes to PLC1/cmd
user myPLC
topic write PLC1/out
topic read PLC1/cmd

#MQTT client myD2000: reads from PLC1/out, writes to PLC1/cmd
user myD2000
topic read PLC1/out
topic write PLC1/cmd

...

Example for MQTT Sparkplug

...

clients:

  • MQTT Host Application s certifikátom with certificate containing Common Name=myHost, so with Sparkplug Host ID=D2000komHA
  • MQTT Edge Node s certifikátom with certificate containing Common Name=myEdge, s with group_id=myGroup, s with edge_node_id=myEdgeNode


Info
titlemyacl.conf
#user without username: anonymous is forbidden, but just to make sure: deny everything
topic deny

#MQTT Edge Node: writes to NDATA/DDATA/NBIRTH/DBIRTH for myGroup/myEdgeNode (and its subdevices), subscribes NCMD a DCMD and queries the state of Host Application
user myEdge
topic write spBv1.0/myGroup/NDATA/myEdgeNode/#
topic write spBv1.0/myGroup/DDATA/myEdgeNode/# 
topic write spBv1.0/myGroup/NBIRTH/myEdgeNode/#
topic write spBv1.0/myGroup/DBIRTH/myEdgeNode/# 
topic read spBv1.0/myGroup/NCMD/myEdgeNode/#
topic read spBv1.0/myGroup/DCMD/myEdgeNode/#
topic read spBv1.0/STATE/D2000komHA

#MQTT Host Application: reads/writes its STATE, reads everything (this might be more precisely specified), writes commands for myEdgeNode (and its subdevices)
user myHost
topic readwrite spBv1.0/STATE/D2000komHA
topic read spBv1.0/#
topic write spBv1.0/myGroup/NCMD/myEdgeNode
topic write spBv1.0/myGroup/DCMD/myEdgeNode/#

...

Generating and signing TLS certificates

To generate keys and TLS certificates and sign them, you must have the OpenSSL package installed. On Windows, you can use, for example, the Na generovanie kľúčov a TLS certifikátov a ich podpisovanie je nutné mať nainštalovaný OpenSSL balík. Na platforme Windows je možné použiť napr. Win32/Win64 OpenSSL Installation Project  (na inštalovaný do installed in c:\Program Files\OpenSSL-Win64\bin).

Nasledovný postup popisuje vytvorenie kľúčov a TLS certifikátov pre MQTT brokera, MQTT klienta myPLC (PLC alebo iné zariadenie) a MQTT klienta The following procedure describes how to create keys and TLS certificates for the MQTT broker, the MQTT client myPLC (PLC or other device), and the MQTT client myD2000 (D2000 KOM procesprocess).

1.

...

Creating a certification authority

This step can be skipped if you already have an existing certification authority, or if someone else signs your certificates. The -days parameter specifies the validity period of the certificate. The -keyout parameter defines the name of the private key file (which must be protected from theft), and the -out parameter defines the name of the certificate (which must be publishedTento krok je možné preskočiť, ak už máte existujúcu certifikačnú autoritu, prípadne vaše certifikáty podpisuje niekto iný. Parametrom -days sa určuje doba platnosti certifikátu. Parameter -keyout definuje názov súboru so súkromným kľúčom (ktorý je nutné chrániť pred odcudzením) a parameter -out  definuje názov certifikátu (ktorý je potrebné zverejniť).

openssl req -new -x509 -days 1000 -extensions v3_ca -keyout caMQTT.key -out caMQTT.crt

Pri vytváraní kľúča je nutné zadať heslo, ktoré je jeho ochranouWhen creating a key, you must enter a password to protect it.

2.1

...

Key creation and certificate signing request for the MQTT broker

This step must be repeated for each of the MQTT brokers.

Creating a key (2048 bits

Tento krok treba zopakovať pre každý z MQTT brokerov. 

Vytvorenie kľúča (s veľkosťou 2048 bitov):

openssl genrsa -out broker.key 2048

Vytvorenie požiadavky na podpísanie (csr - Creating a certificate signing request ). Je nutné zadať viacero parametrov, hodnoty udávané v príklade je nutné upraviť. Odporúčané je, aby CN (Canonic Name) zodpovedalo názvu počítača s MQTT brokerom(csr). Several parameters must be entered; the values given in the example must be modified. It is recommended that the CN (Common Name) match the name of the computer with the MQTT broker.

openssl req -out broker.csr -key broker.key -new        
    
        Country Name (2 letter code) [AU]:SK
        State or Province Name (full name) [Some-State]:Slovakia
        Locality Name (eg, city) []:Žilina
        Organization Name (eg, company) [Internet Widgits Pty Ltd]:Ipesoft
        Organizational Unit Name (eg, section) []:D2000
        Common Name (e.g. server FQDN or YOUR name) []:myserver
        Email Address []:ipesoft@ipesoft.sk
        
        Please enter the following 'extra' attributes
        to be sent with your certificate request
        A challenge password []:
        An optional company name []:

2.2

...

Creating a certificate for the MQTT broker

This step must be repeated for each of the MQTT brokers.

If you created a certification authority above, you are creating a certificate (signing a

Tento krok treba zopakovať pre každý z MQTT brokerov. 

Ak ste vyššie vytvorili certifikačnú autoritu, vytvárate certifikát (podpisujete certificate signing request). V opačnom prípade pošlete súbor Otherwise, you send the broker.csr na podpis príslušnej certifikačnej autorita (napr. IT oddelenie firmy file for signing to the appropriate certification authority (e.g., the company's IT department).Parameter 

The -days udáva dobu platnosti certifikátu v dňoch parameter specifies the certificate validity period in days.

 openssl x509 -req -in broker.csr -CA caMQTT.crt -CAkey caMQTT.key -CAcreateserial -out broker.crt -days 1000

Súbor The broker.crt file (certifikát MQTT brokera) je spolu so súborom broker certificate) must be copied to the MQTT server, along with the broker.key file (súkromný kľúč MQTT brokera) a s certifikátom certifikačnej autority broker private key) and the certification authority certificate (caMQTT.crt) potrebné nakopírovať na MQTT server. Súbor . It is also recommended to protect the broker.key je navyše odporúčané chrániť (prístupovými právami, kryptovaním) tak, aby k nemu mal prístup iba užívateľ, pod ktorým beží MQTT broker. file (with access rights, encryption) so that only the user under whom the MQTT broker is running has access to it.

The certification authority certificate (caMQTT.crt) must be copied so that the D2000 KOM has access to it (the easiest way is to put it in the application directory) and set the path to it as the "Partner certificate" parameter Certifikát certifikačnej autority (caMQTT.crt) je nutné nakopírovať tak, aby k nemu mal prístup D2000 KOM (najjednoduchšie do aplikačného adresára) a nastaviť cestu k nemu ako parameter "Certifikát partnera"  (#APPDIR#\caMQTT.crt) v konfigurácii linky in the TCP/IP-TCP Redundant line configuration.

3.1

...

Creating a key and certificate signing request for the MQTT client

Similar to the MQTT broker, you need to create a key and a certificate signing request for the MQTT client. The procedure is the same, only the file names are different.

Creating a key (with a size of 2048 bits

Podobne ako pre MQTT brokera, aj pre MQTT klienta je nutné vytvoriť kľúč a požiadavku na podpísanie certifikátu. Postup je ten istý, líšia sa iba názvy súborov.

Vytvorenie kľúča (s veľkosťou 2048 bitov):

openssl genrsa -out myPLC.key 2048

Vytvorenie požiadavky na podpísanie (csr - Creating a certificate signing request (csr). Je nutné zadať viacero parametrov, hodnoty udávané v príklade je nutné upraviť. Nutné je zadať také CN (Canonic Name), ktoré zodpovedá názvu MQTT užívateľaIt is necessary to enter several parameters, the values given in the example must be modified. It is necessary to enter a CN (Common Name) that corresponds to the MQTT user name:

openssl req -out myPLC.csr -key myPLC.key -new

       Country Name (2 letter code) [AU]:SK
        State or Province Name (full name) [Some-State]:Slovakia
        Locality Name (eg, city) []:Žilina
        Organization Name (eg, company) [Internet Widgits Pty Ltd]:Ipesoft
        Organizational Unit Name (eg, section) []:D2000
        Common Name (e.g. server FQDN or YOUR name) []:myPLC
        Email Address []:ipesoft@ipesoft.sk
        
        Please enter the following 'extra' attributes
        to be sent with your certificate request
        A challenge password []:
        An optional company name []:       

3.2

...

Creating a certificate for the MQTT client

If you created a certification authority above, you are creating a certificate (signing a Ak ste vyššie vytvorili certifikačnú autoritu, vytvárate certifikát (podpisujete certificate signing request). V opačnom prípade pošlete súbor Otherwise, you send the myPLC.csr na podpis príslušnej certifikačnej autorita (napr. IT oddelenie firmy file for signing to the appropriate certification authority (e.g., the company's IT department).
Parameter The -days udáva dobu platnosti certifikátu v dňochparameter specifies the certificate validity period in days.

 openssl openssl x509 -req -inmyPLC.csr -CA caMQTT.crt -CAkey caMQTT.key -CAcreateserial -out myPLCout myPLC.crt -days 1000

Súbor The myPLC.crt file (certifikát MQTT klienta) je spolu so súborom client certificate) must be copied to the MQTT client, along with the myPLC.key file (súkromný kľúč MQTT klienta) a s certifikátom certifikačnej autority client private key) and the certificate authority certificate (caMQTT.crt) potrebné nakopírovať na MQTT klienta. Súbor . It is also recommended to protect the myPLC.key je navyše odporúčané chrániť (prístupovými právami, kryptovaním) tak, aby k nemu mal prístup iba užívateľ, pod ktorým beží MQTT klient. Súbor myPLC.crt je nutné nakopírovať aj na MQTT broker; pomocou neho bude overovaná totožnosť MQTT klienta. file (with access rights, encryption) so that only the user under whom the MQTT client is running has access to it. The myPLC.crt file must also be copied to the MQTT broker; it will be used to verify the identity of the MQTT client.


4 Repeating the procedure for the D2000 MQTT client

Just as the key for the myPLC MQTT client was created and signed, it is necessary to create and sign the key for the myD2000 MQTT client. Its public certificate (myD2000.crt) must again be copied to the MQTT broker directory. The public certificate (myD2000.crt) and private key (myD2000.key) must be copied so that D2000 KOM can access them (the easiest way is to the application directory) and set the path to them as the parameters "My certificateRovnako, ako bol vytvorený a podpísaný kľúč pre MQTT klienta myPLC, je nutné vytvoriť a podpísať kľúč pre MQTT klienta myD2000. Jeho verejný certifikát (myD2000.crt) je opäť nutné nakopírovať do adresára MQTT brokera. Verejný certifikát (myD2000.crt) aj súkromný kľúč (myD2000.key) je nutné nakopírovať tak, aby k ním mal prístup D2000 KOM (najjednoduchšie do aplikačného adresára) a nastaviť cestu k ním ako parametre "Môj certifikát" (#APPDIR#\myD2000.crt) a and "Môj kľúčMy key" (#APPDIR#\myD2000.key) v konfigurácii linky in the TCP/IP-TCP Redundant configuration.



Info
titleSúvisiace stránky:

Komunikačné protokoly

Protokol MQTT Client (Message Queue Telemetry Transport)

...