MQTTnet icon indicating copy to clipboard operation
MQTTnet copied to clipboard

MQTT Certificate connection issue

Open Leobute opened this issue 8 years ago • 7 comments

Hi

My pc must dialogue with Amazon AWS iot.

I followed amazon wizard (node js) to create a connection and certificate for my pc. It generated for me 4 certificate files. (A cert, 2 keys and a root-ca)

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

If i use raspberry and a Python script, all works correctly . It connects, publish an so on…

In the python script, i see that in the connections options, it uses and pass 3 certificate files.

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)

OK it works

I need to do the same thing on a windows pc using VB.net (but I have tried also in C++ and it is the same) On my Visual studio 2017, in my project, I installed the nuget package M2MQTT library by Paolo Patierno. So, following the connection options and the required parameters, I wrote down the code , JUST to try a connection………. Here I have noticed that the connection options, accept and works only with 2, TWO certificate and it doesn’t require and use the .KEY file (while python does) So I could use only the Ca-certificate and the client certificate, NOT the private key.

This is my code ……

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

If i make my program run, it arrives at the connect line and it fails. It cannot connect to the AWS iot MQTT server (While python with the same certificate does) I got the error below…..

{"An unknown error occurred while processing the certificate"} | System.Exception {System.ComponentModel.Win32Exception}

| "A call to SSPI failed, see inner exception." | String

I don't know what to do anymore. Tried with Openssl, to generate a p12, pfx file with private key....but nothing. I'm desperate. Anyone that can help me ???

Leobute avatar May 14 '18 13:05 Leobute

Have you read the inner exception?

biapar avatar May 15 '18 15:05 biapar

Solved by myself. Thanks to all anyway.

Leobute avatar May 19 '18 05:05 Leobute

@Leobute Could you post your solution? It could also be useful for others in the future. Thx.

biapar avatar May 19 '18 06:05 biapar

Yes, please post your solution. I'm having the same problem.

asthomas avatar May 29 '18 02:05 asthomas

@biapar @asthomas I posted my solution in #552

gregjesl avatar Feb 17 '19 11:02 gregjesl

@chkr1011 This can be closed, I guess.

SeppPenner avatar Jun 24 '19 08:06 SeppPenner

Yes. Thanks. Solved months ago.

Inviato da smartphone Samsung Galaxy.

-------- Messaggio originale -------- Da: HansM [email protected] Data: 24/06/19 10:53 (GMT+01:00) A: chkr1011/MQTTnet [email protected] Cc: Leonardo Butelli [email protected], Mention [email protected] Oggetto: Re: [chkr1011/MQTTnet] MQTT Certificate connection issue (#267)

@chkr1011https://github.com/chkr1011 This can be closed, I guess.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/chkr1011/MQTTnet/issues/267?email_source=notifications&email_token=AI2OKPIXHKRJQVBY6SHH7ZLP4CDRHA5CNFSM4E7XGNO2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYMHWGQ#issuecomment-504920858, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AI2OKPPABL3CPQCL2OGMHXDP4CDRHANCNFSM4E7XGNOQ.


This email was scanned by Bitdefender

Leobute avatar Jun 24 '19 12:06 Leobute