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?
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:
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;