1、參考《https://blog.csdn.net/JKL852qaz/article/details/84034829》
https://blog.csdn.net/weixin_43025071/article/details/82491560
https://blog.csdn.net/houjixin/article/details/24305613
http://mosquitto.org/man/mosquitto-tls-7.html
2、證書(shū)校驗(yàn)
3、注意ca ,server,client,comm選項(xiàng),ca需要和client,server不同
4、注意pub,sub用root賬戶
5、主題客戶端輸入密碼和證書(shū)密碼要相同
6、注意127.0.0.1不能用,得用注冊(cè)時(shí)候client -comm選項(xiàng)ipd
測(cè)試:
啟動(dòng)服務(wù)?
sub:mosquitto_sub -h 192.168.65.131 -p 51883 -t "mqtt/server/topic" --cafile /etc/mosquitto/tls/ca.crt --cert /etc/mosquitto/tls/client.crt --key /etc/mosquitto/tls/client.key
pub:mosquitto_pub -h 192.168.65.131 -p 8883 -t "mqtt/server/topic" --cafile /etc/mosquitto/tls/ca.crt --cert /etc/mosquitto/tls/client.crt --key /etc/mosquitto/tls/client.key -m "ddddddddddd"

1、?注意事項(xiàng)
(1)??制作簽發(fā)證書(shū)的請(qǐng)求文件時(shí),需要輸入Common Name參數(shù),此參數(shù)一定為當(dāng)前主機(jī)的IP地址,否則將會(huì)顯示證書(shū)錯(cuò)誤。
(2)??如果不想SSL在身份認(rèn)證的時(shí)候檢查主機(jī)名(也即上面不檢查第1條中Common Name參數(shù)),則需要在啟動(dòng)訂閱端的時(shí)候,加上“--insecure”參數(shù),例如:
./mosquitto_sub-h 192.168.4.223 -i 111 -p 8883 -t "111" --cafile/home/jason.hou/ssl/ca.crt --cert /home/jason.hou/ssl/client.crt --key/home/jason.hou/ssl/client.key??--insecure
(3)??自測(cè)過(guò)程中,server端與所有客戶端所使用的證書(shū)必須由一個(gè)CA簽發(fā),否則,將會(huì)提示CA不識(shí)別的問(wèn)題。
問(wèn)題提示為:
1398166026:New connection from 192.168.4.221 on port 8883.
1398166026:OpenSSL Error: error:14094418:SSL routines:SSL3_READ_BYTES:tlsv1 alert unknownca
1398166026:OpenSSL Error: error:140940E5:SSL routines:SSL3_READ_BYTES:ssl handshakefailure
1398166026:Socket error on client (null), disconnecting.