Skip to content

Commit a08e0f6

Browse files
authored
Merge pull request #86 from gaillarddamien/mqtt-sparkplug-tls-certOpts
[mqtt-sparkplug]: fix TLS support
2 parents e0c6957 + ef30695 commit a08e0f6

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/mqtt-sparkplug/index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,19 +1012,23 @@ function getSparkplugConfig (connection) {
10121012

10131013
let secOpts = {}
10141014
if (connection.useSecurity) {
1015-
certOpts = {}
1016-
if (connection.pfxFilePath !== '') {
1015+
let certOpts = {}
1016+
if ((connection.pfxFilePath !== '') && Fs.existsSync(connection.pfxFilePath)) {
10171017
certOpts = {
10181018
pfx: Fs.readFileSync(connection.pfxFilePath),
10191019
passphrase: connection.passphrase
10201020
}
10211021
} else {
1022-
certOpts = {
1023-
ca: Fs.readFileSync(connection.rootCertFilePath),
1024-
key: Fs.readFileSync(connection.privateKeyFilePath),
1025-
cert: Fs.readFileSync(connection.localCertFilePath),
1026-
passphrase: connection.passphrase
1022+
if ((connection.rootCertFilePath !== '') && Fs.existsSync(connection.rootCertFilePath)) {
1023+
certOpts.ca = Fs.readFileSync(connection.rootCertFilePath)
1024+
}
1025+
if ((connection.privateKeyFilePath !== '') && Fs.existsSync(connection.privateKeyFilePath)) {
1026+
certOpts.key = Fs.readFileSync(connection.privateKeyFilePath)
1027+
}
1028+
if ((connection.localCertFilePath !== '') && Fs.existsSync(connection.localCertFilePath)) {
1029+
certOpts.cert = Fs.readFileSync(connection.localCertFilePath)
10271030
}
1031+
certOpts.passphrase = connection.passphrase
10281032
}
10291033

10301034
secOpts = {

0 commit comments

Comments
 (0)