我的电脑必须与亚马逊AWS iot对话。
我按照亚马逊向导(节点js)为我的电脑创建连接和证书。 它为我生成了4个证书文件。 (证书,2个密钥和root-ca)
Pippo.cert.pem,Pippo.private.key,Pippo.public.key,根ca.crt
如果我使用raspberry和Python脚本,一切正常。它连接,发布等......
在python脚本中,我看到在连接选项中,它使用并传递3个证书文件。
cert_path = "/home/pi/iot/certs/"
host = "xxxxxxxxx.iot.us-west-2.amazonaws.com"
topic = "Domotica"
root_cert = cert_path + "root-CA.crt"
cert_file = cert_path + "pippo.cert.pem"
key_file = cert_path + "pippo.private.key"
client.tls_set(root_cert,certfile = cert_file,keyfile = key_file,cert_reqs=ssl.CERT_REQUIRED,tls_version=ssl.PROTOCOL_TLSv1_2,ciphers=None)
client.connect(host, 8883, 60)
确定无误
我需要在使用VB.net的Windows PC上做同样的事情(但我也尝试过在C ++中也是如此) 在我的Visual Studio 2017上,在我的项目中,我安装了Paolo Patierno的nuget包M2MQTT库。 因此,按照连接选项和所需参数,我写下代码,JUST尝试连接.......... 在这里我注意到连接选项,只接受和使用2,TWO证书,它不需要和使用.KEY文件(而python一样) 所以我只能使用Ca证书和客户端证书,而不是私钥。
这是我的代码......
Dim Endpoint As String = "xxxxxxxxxxxxxxxx.iot.us-west-2.amazonaws.com"
Dim Port As Integer = 8883
Dim clientCert As New X509Certificate("D:\Optoteam\pippo.cert.pem")
Dim cacert As New X509Certificate("D:\Optoteam\root-ca.crt")
Dim Client = New MqttClient(Endpoint, Port, True, cacert, clientCert, MqttSslProtocols.TLSv1_2, Nothing)
Client.ProtocolVersion = MqttProtocolVersion.Version_3_1_1
Dim connesso As Byte = Client.Connect("TestTestTest")
If (Client.IsConnected) Then
Client.Subscribe(New String() {"Domotica"}, New Byte() {MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE})
Client.Publish("Domotica", Encoding.UTF8.GetBytes("Prova"))
End If
如果我让我的程序运行,它会到达连接线并失败。 我已经尝试了所有的nuget包,深入到每个的连接选项,但我还没有理解如何连接使用TLS,如果有一些不同的库使用和接受第三个文件..一个密钥文件。< / p>
它无法连接到AWS iot MQTT服务器(虽然具有相同证书的python可以) 我收到了以下错误...... ..
uPLibrary.Networking.M2Mqtt.Exceptions.MqttConnectionException:'连接到代理的异常' Win32Exception:收到的消息是意外的或格式错误的
如果我用FALSE而不是TRUE
更改连接指令Dim Client = New MqttClient(Endpoint, Port, false, cacert, clientCert, MqttSslProtocols.TLSv1_2, Nothing)
我收到此错误消息。
StackTrace " at uPLibrary.Networking.M2Mqtt.MqttClient.SendReceive(Byte[] msgBytes, Int32 timeout) in c:\Users\ppatierno\Source\Repos\m2mqtt\M2Mqtt\MqttClient.cs:line 1094" & vbCrLf & " at uPLibrary.Networking.M2Mqtt.MqttClient.SendReceive(MqttMsgBase msg, Int32 timeout) in c:\Users\ppatierno\Source\Repos\m2mqtt\M2Mqtt\MqttClient.cs:line 1117" & vbCrLf & " 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" & vbCrLf & " 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" & vbCrLf & " at MQTT.Form1.Form1_Load(Object sender, EventArgs e) in C:\Users\Leonardo\Documents\Visual Studio 2017\Projects\MQTT\MQTT\Form1.vb:line 25" & vbCrLf & " at System.EventHandler.Invoke(Object sender, EventArgs e)" & vbCrLf & " at System.Windows.Forms.Form.OnLoad(EventArgs e)" & vbCrLf & " at DevExpress.XtraEditors.XtraForm.OnLoad(EventArgs e)" & vbCrLf & " at System.Windows.Forms.Form.OnCreateControl()" & vbCrLf & " at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)" & vbCrLf & " at System.Windows.Forms.Control.CreateControl()" & vbCrLf & " at System.Windows.Forms.Control.WmShowWindow(Message& m)" & vbCrLf & " at System.Windows.Forms.Control.WndProc(Message& m)" & vbCrLf & " at System.Windows.Forms.ScrollableControl.WndProc(Message& m)" & vbCrLf & " at System.Windows.Forms.Form.WmShowWindow(Message& m)" & vbCrLf & " at System.Windows.Forms.Form.WndProc(Message& m)" & vbCrLf & " at DevExpress.XtraEditors.XtraForm.WndProc(Message& msg)" & vbCrLf & " at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)" & vbCrLf & " at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)" & vbCrLf & " at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)" String
你帮我吗?
私钥文件缺少参数选项中的问题是什么?那个着名的第三档我在说什么?
请帮帮我。非常感谢