paho.mqtt.c-master 作客户端 volantmq 作mqtt服务器 wss 认证测试

1, 以前go 的wss认证测试都client是 tlsConfig := &tls.Config{InsecureSkipVerify: true, ClientAuth: tls.NoClientCert}
    opts.SetTLSConfig(tlsConfig) 
   即设置了InsecureSkipVerify: true 用于跳过证书认证.


2, 现在因为 paho.mqtt.c-master 暂时不知道哪里可以设置跳过, 只好来真正认证了.


3, 首先我们来建立我们自己的CA,需要生成一个CA私钥和一个CA的数字证书:

$openssl genrsa -out ca.key 2048
Generating RSA private key, 2048 bit long modulus
……….+++
………………………….+++
e is 65537 (0×10001)

$openssl req -x509 -new -nodes -key ca.key -subj "/CN=tonybai.com" -days 5000 -out ca.crt

接下来,生成server端的私钥,生成数字证书请求,并用我们的ca私钥签发server的数字证书:

openssl genrsa -out server.key 2048
Generating RSA private key, 2048 bit long modulus
….+++
…………………….+++
e is 65537 (0×10001)

$openssl req -new -key server.key -subj "/CN=localhost" -out server.csr


 
$openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 5000
Signature ok
subject=/CN=localhost
Getting CA Private Key

现在我们的工作目录下有如下一些私钥和证书文件:
CA:
    私钥文件 ca.key
    数字证书 ca.crt

Server:
    私钥文件 server.key
    数字证书 server.crt

接下来,我们就来完成我们的程序。


4, 将ca.crt 重命令为 lwc_ca.crt  

 [root@localhost paho.mqtt.c-master]# ./build/output/samples/paho_c_pub -t  topicdd -V 31 -P lwc -u lwc --connection wss://192.168.1.40:4444 --cafile lwc_ca.crt  
dsfa
123
456789

5,
 [root@localhost paho.mqtt.c-master]# ./build/output/samples/paho_c_sub -t  topicdd -V 31 -P lwc -u lwc --connection wss://192.168.1.40:4444 --cafile lwc_ca.crt  
123
456789


6,
将server.crt 重命令为 cert.crt   将server.key 重命令为 cert.key  
mqttserver]# ./main -config config.yaml 

猜你喜欢

转载自blog.csdn.net/weixin_40592935/article/details/83543600