From 550d1e1e02e2171b1a4872afca7b22d171c6f9a2 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Fri, 6 Jul 2018 23:46:02 +0800 Subject: [PATCH] Modify MQTTClient service to support tls certs #154 --- .env.dist | 4 ++-- config/services.yaml | 1 + src/Service/MQTTClient.php | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.env.dist b/.env.dist index c72e5da2..2829219e 100644 --- a/.env.dist +++ b/.env.dist @@ -26,5 +26,5 @@ RT_SHORTCODE=1234 # mosquitto client MQTT_IP_ADDRESS=localhost -MQTT_PORT=1883 - +MQTT_PORT=8883 +MQTT_CERT=/location/of/cert/file.crt diff --git a/config/services.yaml b/config/services.yaml index 57b8885e..ebf834ed 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -69,3 +69,4 @@ services: arguments: $ip_address: "%env(MQTT_IP_ADDRESS)%" $port: "%env(MQTT_PORT)%" + $cert: "%env(MQTT_CERT)%" diff --git a/src/Service/MQTTClient.php b/src/Service/MQTTClient.php index b4bacc75..23a0f140 100644 --- a/src/Service/MQTTClient.php +++ b/src/Service/MQTTClient.php @@ -12,9 +12,11 @@ class MQTTClient protected $mclient; - public function __construct($ip_address, $port) + public function __construct($ip_address, $port, $cert) { $this->mclient = new MosquittoClient(); + $this->mclient->setTlsCertificates($cert); + $this->mclient->setTlsOptions(MosquittoClient::SSL_VERIFY_NONE, 'tlsv1'); $this->mclient->connect($ip_address, $port); }