eclipse / paho.mqtt.m2mqtt

Eclipse Public License 1.0
512 stars 303 forks source link

NetMF TLS without client cert #43

Open networkfusion opened 7 years ago

networkfusion commented 7 years ago

When trying to connect when not using a client certificate in netmf v4.3.1 e.g. MqttClient mqttc = new MqttClient(iotBrokerAddress, 8883, true, null, null, MqttSslProtocols.TLSv1_0);

An exception is thrown. This could be fixed by changing the server authentication code around line 245 in MqttNetworkChannel.cs to

// server authentication (SSL/TLS handshake)
#if (MF_FRAMEWORK_VERSION_V4_2 || MF_FRAMEWORK_VERSION_V4_3)

                if (this.clientCert != null)
                {
                    this.sslStream.AuthenticateAsClient(this.remoteHostName,
                        this.clientCert,
                        new X509Certificate[] { this.caCert },
                        SslVerification.CertificateRequired,
                        MqttSslUtility.ToSslPlatformEnum(this.sslProtocol));
                }
                else
                {
                    this.sslStream.AuthenticateAsClient(this.remoteHostName, MqttSslUtility.ToSslPlatformEnum(this.sslProtocol));
                }
#else
melzoghbi commented 6 years ago

@networkfusion i am having the same issue! but changing what you have suggested still throws an exception! do you have a full working code segment in MqttNetworkChannel.cs with your modifications?

Thanks

networkfusion commented 6 years ago

https://github.com/networkfusion/NetMfMqttClient

josesimoes commented 4 years ago

@melzoghbi know that .NET nanoFramework has just publish it's NuGet for this library. Because of the improved secure sockets implementation (over .NETMF) the above is not a problem anymore.

Check it out here.