mosquitto ---配置SSL/TLS

在服務器電腦上面建立myCA文件夾, 如在/home/qa/ 文件夾下使用命令,html

mkdir myCA 

而後執行如下命令,咱們將建立並使用其餘用戶沒有權限訪問的目錄。python

sudo chmod 700
cd myCA
 
進入myCA文件夾,而後執行如下命令下載生成證書用的腳本。
wget https://github.com/owntracks/tools/raw/master/TLS/generate-CA.sh

下載完以後,在myCA文件夾下面執行命令git

注:在生產環境中使用此實例以前,你應該定製the generate-CA.sh腳本github

bash ./generate-CA.sh
 
generate-CA.sh會產生3個文件:ca.crt,ca.key,ca.csr分別爲: 證書(.CRT),鑰匙(.KEY),請求(.csr文件),這三個文件是給服務器使用的
 
在myCA文件夾下面執行命令
 
bash ./generate-CA.sh client myclient
 
其中myclient是給客戶端生成證書的名稱,可隨意更改。執行完上述命令後,會新生成幾個文件。
客戶端須要使用的是ca.crt/myclient.crt/myclient.key這三個文件。
 
通過上述步驟以後,生成了服務器使用的ca.crt/localhost.crt/localhost.key文件和客戶端使用的
ca.crt/myclient.crt/myclient.key這幾個文件,其中ca.crt是同一個文件。
配置mosquitto.conf文件。該文件在mosquitto-1.4.11安裝文件夾裏面,打開該文件,修改爲以下配置:
   port 8883
    protocol mqtt
    cafile /home/myCA/ubuntu/ca.crt
    certfile /home/myCA/ubuntu/localhost.crt
    keyfile /home/myCA/ubuntu/localhost.key
    require_certificate true
    use_identity_as_username true

修改完配置文件以後,執行啓動命令mosquitto -c /home/qa/mosquitto-1.4.11/mosquitto.conf -v  ubuntu

 根據本身的mosquitto-conf文件所在的位置修改上述命令中的參數,而後服務器就以SSL/TSL的方式開始啓動。
  此時客戶端使用上述過程產生的客戶端證書鏈接該服務器,便可進行通訊。

 

 

參考頁面:https://mosquitto.org/man/mosquitto-tls-7.htmlbash

相關文章
相關標籤/搜索