【问题标题】:self signed x509 certificate issue in MQTT mosquitto using c#使用 c# 在 MQTT mosquitto 中自签名 x509 证书问题
【发布时间】:2015-07-27 12:58:40
【问题描述】:

我在 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 中实现证书。

【问题讨论】:

  • 内部异常是什么?
  • 控制台错误:- C:\Program Files\mosquitto>mosquitto -c mosquitto.conf -v 1438076057:mosquitto 版本 1.4(构建日期 27/02/2015 21:01:03.50)从 1438076057 开始:从 mosquitto.conf 加载的配置。 1438076057:在端口 8883 上打开 ipv4 侦听套接字。输入 PEM 密码:1438076075:在端口 8883 上从 10.112.154.82 建立新连接。1438076093:客户端 上的套接字错误,正在断开连接。
  • C#中:--{"根据验证程序,远程证书无效。"}

标签: c# mqtt mosquitto


【解决方案1】:

似乎 mosquitto 代理正在等待客户端证书进行客户端身份验证。 M2Mqtt 仅支持上面文章中描述的服务器身份验证。在此处阅读 mosquitto 文档:http://mosquitto.org/man/mosquitto-conf-5.html 似乎“require_certificate”设置为 true(需要客户端证书)。您需要将其设置为 false。

保罗。

【讨论】:

  • 客户端上的套接字错误,发生断开连接错误,通过实施 require_certificate false 相同的问题。我遵循相同的文章相同的步骤,但我的服务器证书是此证书具有无效的数字签名。而我正在将其导入证书。
【解决方案2】:

我知道现在回答为时已晚,但任何人都面临过类似的问题。解决方案: Install certificate in Local machine as Root Certificate 并将两个证书文件参数都传递为 null 并将加密设置为 TLSV1.2 示例:

var client = new MqttClient(IPAddress.Parse(mqttBrokerHost), 8883, true,null, null, MqttSslProtocols.TLSv1_2);

【讨论】:

    【解决方案3】:

    对于客户端证书,您需要从您的 CA、证书和私钥创建一个 PFX 文件。 在命令行使用 openssl:

    openssl pkcs12 -export -out <OutputName>.pfx -inkey client.key -in client.crt -certfile mosquitto.org.cer
    

    连接M2MQTT的C#代码:(本例中的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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-25
      • 2021-11-19
      • 2021-08-24
      • 1970-01-01
      • 2015-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多