Closed zhaopeiym closed 4 years ago
已解决,两种方案实现TLS连接:
1、通过WebSocket
var mqttClientOptions = new MqttClientOptionsBuilder()
.WithClientId(clientID)
.WithWebSocketServer("broker.hivemq.com:443/mqtt")
.WithCredentials(userName, password)
.WithTls();
2、只需要导入client.pfx,不需要ca.crt
var clientCert = new X509Certificate2(AppConfig.MqttPfxFile);
var mqttClient = new MqttFactory().CreateManagedMqttClient();
var mqttClientOptions = new MqttClientOptionsBuilder()
.WithClientId(clientID)
.WithTcpServer(address, port)
.WithCredentials(userName, password)
.WithTls(new MqttClientOptionsBuilderTlsParameters()
{
UseTls = true,
SslProtocol = System.Security.Authentication.SslProtocols.Tls12,
CertificateValidationHandler = (o) =>
{
return true;
},
Certificates = new []{
clientCert,
}
});
生成pfx:openssl pkcs12 -export -in client.crt -inkey client.key -out client.pfx
environment
error
It's been bothering me for a long time , Ask for help !!! thank you !!!