openssl 生成自签证书如下:
openssl genrsa -out ca.key 2048
openssl req -x509 -new -nodes -key ca.key -sha256 -days 36500 -subj “/CN=www.emqx.io” -out ca.pem
openssl genrsa -out server.key 2048
openssl req -new -key ./server.key -out server.csr -subj “/CN=192.168.0.12”
openssl x509 -req -in ./server.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out server.pem -days 36500 -sha256
openssl genrsa -out client.key 2048
openssl req -new -key ./client.key -out client.csr -subj “/CN=192.168.0.9”
openssl x509 -req -in ./client.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out client.pem -days 36500 -sha256
emqx.conf
listener.ssl.external.keyfile = /home/certs/server.key
listener.ssl.external.certfile = /home/certs/server.pem
listener.ssl.external.cacertfile = /home/certs/ca.pem
listener.ssl.external.verify = verify_peer
listener.ssl.external.fail_if_no_peer_cert = true
MQTTX 日志:
[2023-04-14 17:49:12] [INFO] MQTTX client with ID 2c6c03f2-a328-4a3f-a6d2-7766249e264e assigned
[2023-04-14 17:49:12] [INFO] Connect client ssl:192.168.0.12, MQTT/SSL connection: mqtts://192.168.0.12:8883
[2023-04-14 17:49:22] [INFO] ssl:192.168.0.12 connect close, MQTT.js onClose trigger