[英]self signed x509 certificate issue in MQTT mosquitto using c#
我在C#中使用mqtt庫,並遵循此URL。 http://www.embedded101.com/Blogs/PaoloPatierno/entryid/366/mqtt-over-ssl-tls-with-the-m2mqtt-library-and-the-mosquitto-broker ,當我連接我的網絡時,通過實現此URL客戶端到本地服務器發生以下錯誤:-
C:\Program Files\mosquitto>mosquitto -c mosquitto.conf -v
1438001198: mosquitto version 1.4 (build date 27/02/2015 21:01:03.50) starting
1438001198: Config loaded from mosquitto.conf.
1438001198: Opening ipv4 listen socket on port 8883.
Enter PEM pass phrase:
1438001224: New connection from 10.112.154.82 on port 8883.
1438001224: OpenSSL Error: error:140890C7:SSL routines:ssl3_get_client_certifica
te:peer did not return a certificate
1438001224: Socket error on client <unknown>, disconnecting.
我的代碼是:-
X509Certificate certificate = new X509Certificate(@"D:\POC\Abhinav\cert\cert\m2mqtt_ca.crt", "india@123");
MqttClient client = new MqttClient("10.112.154.82", 8883, true, new X509Certificate(certificate));
string clientId = new Guid("b0ca37b1-8a90-4a59-9665-fd8504357165").ToString();
client.Connect(clientId);
錯誤:
c# Error:-{"A call to SSPI failed, see inner exception."}
誰能建議我如何使用mosquitto在mqtt中實施證書。
似乎mosquitto代理正在等待用於客戶端身份驗證的客戶端證書。 如上所述,M2Mqtt僅支持服務器身份驗證。 在此處閱讀mosquitto文檔: http ://mosquitto.org/man/mosquitto-conf-5.html似乎“ require_certificate”設置為true(需要客戶端證書)。 您需要將其設置為false。
保羅
對於客戶端證書,您需要根據您的CA,證書和私鑰創建PFX文件。 在命令行上使用openssl:
openssl pkcs12 -export -out <OutputName>.pfx -inkey client.key -in client.crt -certfile mosquitto.org.cer
代碼C#與M2MQTT連接:(此示例中的OutputName為client.pfx)
X509Certificate certRootCa = X509Certificate.CreateFromCertFile(Application.StartupPath + "/caRoot.crt");
X509Certificate2 certClient = new X509Certificate2(Application.StartupPath + "/client.pfx", "password");
MqttClient client = new MqttClient("10.112.154.82", 8883, true, certRootCa, certClient, MqttSslProtocols.TLSv1_2);
string clientId = new Guid("b0ca37b1-8a90-4a59-9665-fd8504357165").ToString();
client.Connect(clientId);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.