Hi I am using M2Mqtt C# library and I want to connect to the hive MQ broker via security. Hive MQ is ssl enabled, I edited the config.xml to use the java Key store(.jks) for enabling ssl.
I am using self signed certificates. I have got certificates from my organization, from which I have generated java key store.
ClientLocal = new MqttClient(IPAddress.Parse("127.0.0.1"), 8883,
true, new X509Certificate(@"C:\Users\310208195\root.crt")
, new X509Certificate(@"C:\Users\310208195\root.crt")
MqttSslProtocols.TLSv1_2);
public MqttClient(IPAddress brokerIpAddress, int brokerPort, bool secure, X509Certificate caCert, X509Certificate clientCert, MqttSslProtocols sslProtocol);
this is library which requires the following parameters.
I have the root.crt which I am passing for CA.crt while connecting. what should I upload for Client certificate and is the .crt format correct for X509 format.
//so after some try I got the below
ClientLocal = new MqttClient(IPAddress.Parse("127.0.0.1"), 8883, false, new X509Certificate(@"C:\Users\310208195\Documents\root.crt"), new X509Certificate2(), MqttSslProtocols.TLSv1_2);
I have left blank but I get exception connecting to broker
. "The remote certificate is invalid according to the validation procedure."}
this is mqtt code
public void Initialize()
{
Client_ID = Guid.NewGuid().ToString();
//ClientLocal.ProtocolVersion = MqttProtocolVersion.Version_3_1;
ClientLocal = new MqttClient(“127.0.0.1”, 8883, true, new X509Certificate(Resources.root), MqttSslProtocols.TLSv1_2); ///root.crt is the certificate
//ClientLocal.Connect(Client_ID, “admin”, “admin”, false, MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE,
// true, “drlastwill”, “hey, it’s me DR-service app,please restart me!”, true, 60);
ClientLocal.Connect(Client_ID, “admin”, “admin”);
MessageBox.Show(“Connection has been established succesully “);
ushort byt = ClientLocal.Subscribe(new string[] { “event” }, new byte[] { MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE }); // QOS -2
ushort byt2 = ClientLocal.Subscribe(new string[] { “report” }, new byte[] { MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE });
ClientLocal.MqttMsgSubscribed += Client_MqttMsgSubscribed;
// ClientLocal.MqttMsgPublishReceived += Client_MqttMsgPublishReceived;
}