본문 바로가기
Development

MQTT (Mosquitto) SSL/TLS 설정 방법 및 테스트 방법

by qWooWp 2020. 7. 8.
반응형

1단계 : 테스트 인증서 만들기

2단계 : Mosquitto conf 파일 설정하기

3단계 : 테스트 하기

 

1단계 : 테스트 인증서 만들기

우분투 또는 윈도우 용 openssl 을 설치해서 아래 명령을 수행해도 됩니다.

윈도우용 openssl 다운로드 (http://slproweb.com/products/Win32OpenSSL.html)

우분투 : # sudo apt-get install openssl

 

openssl genrsa -out ca.key 2048

openssl req -new -x509 -days 360 -key ca.key -out ca.crt

*제일 중요한 것은 Common Name 의 이름을 Mosquitto Broker 접속 Domain 주소 또는 컴퓨터 이름으로 해야 한다.

openssl genrsa -out server.key 2048

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

 

openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 360

openssl verify -CAfile ca.crt server.crt

 

2단계 : Mosquitto conf 파일 설정하기

1883, TLS 8883 두가지 다 살려놓기 위해서 아래와 같이 추가 포트설정을 하여야 한다.

# =================================================================
|# Extra listeners
# =================================================================

이 부분 아래에 있는 내용들을 수정해야 한다.

 

cafile  d:\cert\ca.crt

certfile d:\cert\server.crt 

keyfile d:\cert\server.key

3단계 : 테스트 하기

관리자 권한으로 기존 서비스를 중단을 합니다.

net stop mosquitto

cd C:\APPs\mosquitto

mosquitto -v -c D:\mosquitto.conf

 

TLS 테스트 명령

mosquitto_sub -t test -p 8883 -h DESKTOP-4LJ3010 --cafile D:\cert\ca.crt --cert D:\\cert\server.crt --key D:\cert\server.key

mosquitto_pub -t test -p 8883 -h DESKTOP-4LJ3010 --cafile D:\cert\ca.crt --cert D:\cert\server.crt --key D:\cert\server.key -m "test"

 

Public 테스트 명령

mosquitto_sub -t test -p 1883 -h localhost

mosquitto_pub -t test -p 1883 -h localhost -m "test1"

 

* 인증서 배포를 하여 같이 사용하게 하면 됩니다.

 

반응형

댓글