MQTT TLS连接Python---Vb.net

MQTT TLS连接Python---Vb.net,mqtt,Mqtt,我的电脑必须与亚马逊AWS物联网对话 我按照amazon向导(NodeJS)为我的电脑创建连接和证书。 它为我生成了4个证书文件。(一个证书、两个密钥和一个根ca) Pippo.cert.pem,Pippo.private.key,Pippo.public.key,Root-ca.crt 如果我使用raspberry和Python脚本,所有这些都可以正常工作。它连接、发布等等 在python脚本中,我看到在连接选项中,它使用并传递3个证书文件 cert_path=“/home/pi/iot/ce

我的电脑必须与亚马逊AWS物联网对话

我按照amazon向导(NodeJS)为我的电脑创建连接和证书。 它为我生成了4个证书文件。(一个证书、两个密钥和一个根ca)

Pippo.cert.pem,Pippo.private.key,Pippo.public.key,Root-ca.crt

如果我使用raspberry和Python脚本,所有这些都可以正常工作。它连接、发布等等

在python脚本中,我看到在连接选项中,它使用并传递3个证书文件

cert_path=“/home/pi/iot/certs/”
host=“xxxxxxxxx.iot.us-west-2.amazonaws.com”
topic=“Domotica”
root\u cert=cert\u path+“root-CA.crt”
证书文件=证书路径+“pippo.cert.pem”
key\u file=cert\u path+“pippo.private.key”
client.tls_集(root_cert,certfile=cert_file,keyfile=key_file,cert_reqs=ssl.cert_REQUIRED,tls_version=ssl.PROTOCOL_TLSv1_2,密码=None)
client.connect(主机,8883,60)
好的,它起作用了

我需要在VB.NET上在Windows PC上做同样的事情(但是我也尝试过C++,而且是一样的) 在我的Visual studio 2017项目中,我安装了Paolo Patierno提供的nuget软件包M2MQTT库。 因此,按照连接选项和所需参数,我写下了代码,只是为了尝试连接………。 在这里,我注意到连接选项accept只适用于2,2证书,它不需要并使用.KEY文件(而python需要) 因此,我只能使用Ca证书和客户端证书,而不能使用私钥

这是我的密码

Dim端点为String=“xxxxxxxxxxxxxx.iot.us-west-2.amazonaws.com”
Dim端口为整数=8883
Dim clientCert作为新的X509证书(“D:\Optoteam\pippo.cert.pem”)
Dim cacert作为新的X509证书(“D:\Optoteam\root-ca.crt”)
Dim Client=新MqttClient(端点、端口、True、cacert、clientCert、MqttSslProtocols.TLSv1_2,无)
Client.ProtocolVersion=MqttProtocolVersion.Version\u 3\u 1\u 1
Dim connesso作为字节=Client.Connect(“testtest”)
如果(客户端已断开连接),则
Subscribe(新字符串(){“Domotica”},新字节(){MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE})
Publish(“Domotica”,Encoding.UTF8.GetBytes(“Prova”))
如果结束
如果我让我的程序运行,它到达连接线并失败。 我尝试了所有的nuget软件包,深入研究了每个软件包的连接选项,但我不知道如何使用TLS进行连接,以及是否有一些不同的库使用并接受第三个文件..一个密钥文件

它无法连接到AWS iot MQTT服务器(而具有相同证书的python则无法连接) 我得到了下面的错误

uPLibrary.Networking.M2Mqtt.Exceptions.MqttConnectionException:“连接到代理的异常” Win32Exception:收到的消息意外或格式错误

如果我用FALSE而不是TRUE更改连接指令

Dim Client=New MqttClient(端点、端口、false、cacert、clientCert、MqttSslProtocols.TLSv1_2,无)
我收到了这个错误消息

StackTrace  "   at uPLibrary.Networking.M2Mqtt.MqttClient.SendReceive(Byte[] msgBytes, Int32 timeout) in c:\Users\ppatierno\Source\Repos\m2mqtt\M2Mqtt\MqttClient.cs:line 1094" 
 "   at uPLibrary.Networking.M2Mqtt.MqttClient.SendReceive(MqttMsgBase msg, Int32 timeout) in c:\Users\ppatierno\Source\Repos\m2mqtt\M2Mqtt\MqttClient.cs:line 1117" 
 "   at uPLibrary.Networking.M2Mqtt.MqttClient.Connect(String clientId, String username, String password, Boolean willRetain, Byte willQosLevel, Boolean willFlag, String willTopic, String willMessage, Boolean cleanSession, UInt16 keepAlivePeriod) in c:\Users\ppatierno\Source\Repos\m2mqtt\M2Mqtt\MqttClient.cs:line 567" 
 "   at uPLibrary.Networking.M2Mqtt.MqttClient.Connect(String clientId, String username, String password, Boolean cleanSession, UInt16 keepAlivePeriod) in c:\Users\ppatierno\Source\Repos\m2mqtt\M2Mqtt\MqttClient.cs:line 512" 
 "   at MQTT.Form1.Form1_Load(Object sender, EventArgs e) in C:\Users\Leonardo\Documents\Visual Studio 2017\Projects\MQTT\MQTT\Form1.vb:line 25" 
 "   at System.EventHandler.Invoke(Object sender, EventArgs e)" 
 "   at System.Windows.Forms.Form.OnLoad(EventArgs e)" 
 "   at DevExpress.XtraEditors.XtraForm.OnLoad(EventArgs e)" 
 "   at System.Windows.Forms.Form.OnCreateControl()" 
 "   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)" 
 "   at System.Windows.Forms.Control.CreateControl()" 
 "   at System.Windows.Forms.Control.WmShowWindow(Message& m)" 
 "   at System.Windows.Forms.Control.WndProc(Message& m)" 
 "   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)" 
 "   at System.Windows.Forms.Form.WmShowWindow(Message& m)" 
 "   at System.Windows.Forms.Form.WndProc(Message& m)" 
 "   at DevExpress.XtraEditors.XtraForm.WndProc(Message& msg)" 
 "   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)" 
 "   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)" 
 "   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)" String
你能帮我吗?? 私钥文件中缺少的参数选项是否存在问题?我说的那个著名的第三个文件

请帮帮我。非常感谢