pakerfeldt / knx-mqtt-bridge

Apache License 2.0
39 stars 19 forks source link

support for mqtt over ssl #12

Closed systeemgod closed 3 years ago

systeemgod commented 3 years ago

Hi,

my mqtt server requires a secure connection. I tried enabling it by adding the following section in the config.yaml:

mqtt:
    url: 'mqtts://...'
    options:
            key:  'knx-mqtt-bridge.key'
            cert: 'knx-mqtt-bridge.crt'
            ca:  'ca.crt'

However it appears knx.js expect the certificate to be provided as file streams in stead of a simple path. I made the following modifications to knx-mqtt-bridge. Note: I'm not a node.js programmer, this is just a quick hack that worked in my particular case but will probably break non-ssl connections. I hope it is usefull:

...
const fs = require('fs');
...
config.mqtt.options.key = fs.readFileSync( config.mqtt.options.key );
config.mqtt.options.cert = fs.readFileSync( config.mqtt.options.cert );
config.mqtt.options.ca = fs.readFileSync( config.mqtt.options.ca );

let mqttClient  = mqtt.connect(config.mqtt.url, config.mqtt.options);
...
pakerfeldt commented 3 years ago

Would you be able to test this branch by any chance before I merge? https://github.com/pakerfeldt/knx-mqtt-bridge/pull/13

systeemgod commented 3 years ago

Will try that a.s.a.p.

On Sat, 21 Nov 2020, 22:32 Patrik Åkerfeldt, notifications@github.com wrote:

Would you be able to test this branch by any chance before I merge? #13 https://github.com/pakerfeldt/knx-mqtt-bridge/pull/13

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pakerfeldt/knx-mqtt-bridge/issues/12#issuecomment-731639819, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIVOAKJ3Q7ITESSF75XPRLTSRAWVLANCNFSM4T54NE7A .

systeemgod commented 3 years ago

I can confirm the patch seems to work. Thanks for the quick fix!

Nico

On Sun, Nov 22, 2020 at 12:50 PM Nico De Ranter nico.deranter@gmail.com wrote:

Will try that a.s.a.p.

On Sat, 21 Nov 2020, 22:32 Patrik Åkerfeldt, notifications@github.com wrote:

Would you be able to test this branch by any chance before I merge? #13 https://github.com/pakerfeldt/knx-mqtt-bridge/pull/13

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pakerfeldt/knx-mqtt-bridge/issues/12#issuecomment-731639819, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIVOAKJ3Q7ITESSF75XPRLTSRAWVLANCNFSM4T54NE7A .

-- Nico & Ann De Ranter - Van Aelst

pakerfeldt commented 3 years ago

I've just now published 0.1.1 with this fix.