MQTT SSL setup

Using Delphi 12.1 and TTMSMQTTClient 2.0.8.0

I'm trying to use SSL for my connection. I have my certificate, but reading the documentation and the support forum I'm unfortunately still lost on how to connect using SSL.

Is there, or could you provide a simple step by step for a simple MQTT client connection using SSL with a certificate?

Thank you.

Set MQTTClient.UseSSL = true and then perform the settings of the SSL IO handler via event handler MQTTClient.OnSSLIOHandlerConfiguration.
This gives you access to the SSLIOHandler and from this event handler you can control its settings. Note that this concerns the Indy SSLIOHandler and as such, you can follow Indy documentation for all settings related to this.

Thank you for the pointers Bruno. I've tried to read up on the Indy documentation, and google for examples, but this is the best I've come up with so far:

For my mqtt cllient I set the correct broker, port and UseSSL. Then in SSLIOHandlerConfiguration event of my MqttClient, I now have this code:

  var FileCert := 'mqtt_ca.crt'; // 'My Root Cert file';
  ASSLIOHandler.SSLOptions.CertFile := FileCert;
  //ASSLIOHandler.SSLOptions.KeyFile := ;

  ASSLIOHandler.SSLOptions.Mode := sslmClient;
  ASSLIOHandler.SSLOptions.Method := sslvSSLv23;

When connecting, I keep getting: exception class EIdSocketError with message 'Socket Error # 10054

Ps. when I do not use SSL I'm able to connect.

Any hints or suggestions greatly appriciated.

Seems similar to

Solved, and sorry for maybe wasting your time.
What happened (short story), was that IT department had added a firewall rule to allow data on port 8883 (For SSL). But, unfortunately they forgot to activate it!

So for anyone reading, remember to have the dll's with your exe:

Libeay32.dll and ssleay32.dll

and then (in my case) the following code was all that was required:

  mqttClient.BrokerHostName       := MQTT_BROKER_REMOTE_HOST;
  mqttClient.BrokerPort           := 8883;
  mqttClient.Credentials.Username := MQTT_BROKER_USERNAME;
  mqttClient.Credentials.Password := MQTT_BROKER_PASSWORD;
  mqttClient.UseSSL := true;

// and then implement this event:
procedure TfrmMain.mqttClientSSLIOHandlerConfiguration(ASender: TObject; var ASSLIOHandler: TIdSSLIOHandlerSocketOpenSSL);
begin
  ASSLIOHandler.SSLOptions.CertFile := 'mqtt_ca.crt'; // 'My Root Cert file';
  ASSLIOHandler.SSLOptions.Mode := sslmClient;
  ASSLIOHandler.SSLOptions.Method := sslvTLSv1_2;
end;

Many thanks for sharing these details!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.