보안 도구 사용방법

Mosquitto Broker를 이용한 MQTT 암호화 통신 방법 & OpenSSL 인증서 사용 방법

Security_Info 2019. 12. 29. 04:22

이전 게시글들에서는 CentOS 상에서 Mosquitto 셋업 방법과 OpenSSL 설치 방법을 알아봤습니다.

지금부터는 OpenSSL 인증서를 발급하며 암호화 통신을 위한 셋팅을 하겠습니다.

 

openSSL 인증서 셋업

openssl genrsa -out ca.key 2048

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

(

  Country Name : KR

  State or Province Name : CN

  Locality Name : Choana

  Organization Name : KongjuUniverSity

  Organization Unit Name : Comp

  Common Name : SONG

 내 pc이름이 SONG이라면 인증서 발급 시에도 COMMON NAME이라는 항목에 SONG을 작성해야합니다. 

 아주중요합니다.

  Email Address : 

)

 

openssl genrsa -out server.key 2048

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

(

  Country Name : KR

  State or Province Name : CN

  Locality Name : Choana

  Organization Name : KongjuUniverSity

  Organization Unit Name : Server

  Common Name : SONG

  Email Address : 

  Achallange password : abcd

  An optional company name :

)

 

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

 

openssl genrsa -out client.key 2048

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

(

  Country Name : KR

  State or Province Name : CN

  Locality Name : Choana

  Organization Name : KongjuUniverSity

  Organization Unit Name : Client

  Common Name : SONG

  Email Address : 

  Achallange password : abcd

  An optional company name :

)

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

openssl verify -CAfile ca.crt client.crt

 

자 이제 인증서 발급 및 인증이 모두 끝났습니다.

 

 

지금부터는 sub<->pub에서 암호화 통신을 위해mosquitto.conf 에 접근하여 수정해야할 사항들이 있습니다.

port 8883

cafile /자신의인증서설치경로/ca.crt

certfile /자신의인증서설치경로/server.crt

keyfile /자신의인증서설치경로/server.key

 

 

mosquitt.conf 파일의 수정이 완료되었다면 MQTT TLS/SSL 암호화 통신을 해보겠습니다.

MQTT TLS/SSL 8883포트를 통한 암호화 통신 수행

broker - (Mosquitto - Broker)

mosquitto -v -c mosquitto.conf

 

subscribe (구독자)

mosquitto_sub -t test -p 8883 -h SONG[위 인증서의 Common Name] --cafile /자신의인증서설치경로/ca.crt --cert /자신의인증서설치경로/client.crt --key /자신의인증서설치경로/client.key

 

pubulish (발행자)

mosquitto_pub -t test -p 8883 -h SONG[위 인증서의 Common Name] --cafile /자신의인증서설치경로/ca.crt --cert /자신의인증서설치경로/client.crt --key /자신의인증서설치경로/client.key -m "test"

 

 

암호화 통신 결과 수행 - WireShark 패킷 내용 
*TIP 로컬환경에서는 npcap을 이용해서 루프백 패킷 캡쳐가 가능합니다. 

npcap-wireshark

 

 

마지막으로 OpenSSL 인증서 발급을 자동화 하는 '인증서 자동 발급 스크립트'를 만들어봤습니다.

아래의 주소에서 확인할 수 있습니다. 수정해서 사용하셔도 됩니다.

https://github.com/LeeJuWan/IoT_openSSL_MQTT

 

LeeJuWan/IoT_openSSL_MQTT

Contribute to LeeJuWan/IoT_openSSL_MQTT development by creating an account on GitHub.

github.com