mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-06-06 14:16:39 +00:00
TLS support for planetmint (#381)
* added TSL support for mqtt * added configuration value mqtt-tls (bool) to support tls and non-tls connections (testing) Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
43d152fcf6
commit
b45c381b3b
@ -23,6 +23,7 @@ mqtt-domain = "{{ .PlmntConfig.MqttDomain }}"
|
|||||||
mqtt-port = {{ .PlmntConfig.MqttPort }}
|
mqtt-port = {{ .PlmntConfig.MqttPort }}
|
||||||
mqtt-user = "{{ .PlmntConfig.MqttUser }}"
|
mqtt-user = "{{ .PlmntConfig.MqttUser }}"
|
||||||
mqtt-password = "{{ .PlmntConfig.MqttPassword }}"
|
mqtt-password = "{{ .PlmntConfig.MqttPassword }}"
|
||||||
|
mqtt-tls = "{{ .PlmntConfig.MqttTLS }}"
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
@ -40,6 +41,7 @@ type Config struct {
|
|||||||
MqttPort int `json:"mqtt-port" mapstructure:"mqtt-port"`
|
MqttPort int `json:"mqtt-port" mapstructure:"mqtt-port"`
|
||||||
MqttUser string `json:"mqtt-user" mapstructure:"mqtt-user"`
|
MqttUser string `json:"mqtt-user" mapstructure:"mqtt-user"`
|
||||||
MqttPassword string `json:"mqtt-password" mapstructure:"mqtt-password"`
|
MqttPassword string `json:"mqtt-password" mapstructure:"mqtt-password"`
|
||||||
|
MqttTLS bool `json:"mqtt-tls" mapstructure:"mqtt-tls"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// cosmos-sdk wide global singleton
|
// cosmos-sdk wide global singleton
|
||||||
@ -63,6 +65,7 @@ func DefaultConfig() *Config {
|
|||||||
MqttPort: 1885,
|
MqttPort: 1885,
|
||||||
MqttUser: "user",
|
MqttUser: "user",
|
||||||
MqttPassword: "password",
|
MqttPassword: "password",
|
||||||
|
MqttTLS: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package monitor
|
package monitor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -51,11 +52,19 @@ func LazyLoadMonitorMQTTClient() {
|
|||||||
conf := config.GetConfig()
|
conf := config.GetConfig()
|
||||||
hostPort := net.JoinHostPort(conf.MqttDomain, strconv.FormatInt(int64(conf.MqttPort), 10))
|
hostPort := net.JoinHostPort(conf.MqttDomain, strconv.FormatInt(int64(conf.MqttPort), 10))
|
||||||
uri := "tcp://" + hostPort
|
uri := "tcp://" + hostPort
|
||||||
|
if conf.MqttTLS {
|
||||||
|
uri = "ssl://" + hostPort
|
||||||
|
}
|
||||||
|
|
||||||
opts := mqtt.NewClientOptions().AddBroker(uri)
|
opts := mqtt.NewClientOptions().AddBroker(uri)
|
||||||
opts.SetClientID(conf.ValidatorAddress + "-monitor")
|
opts.SetClientID(conf.ValidatorAddress + "-monitor")
|
||||||
opts.SetUsername(conf.MqttUser)
|
opts.SetUsername(conf.MqttUser)
|
||||||
opts.SetPassword(conf.MqttPassword)
|
opts.SetPassword(conf.MqttPassword)
|
||||||
|
if conf.MqttTLS {
|
||||||
|
tlsConfig := &tls.Config{}
|
||||||
|
opts.SetTLSConfig(tlsConfig)
|
||||||
|
}
|
||||||
|
|
||||||
MonitorMQTTClient = mqtt.NewClient(opts)
|
MonitorMQTTClient = mqtt.NewClient(opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -42,11 +43,19 @@ func LazyLoadMQTTClient() {
|
|||||||
conf := config.GetConfig()
|
conf := config.GetConfig()
|
||||||
hostPort := net.JoinHostPort(conf.MqttDomain, strconv.FormatInt(int64(conf.MqttPort), 10))
|
hostPort := net.JoinHostPort(conf.MqttDomain, strconv.FormatInt(int64(conf.MqttPort), 10))
|
||||||
uri := "tcp://" + hostPort
|
uri := "tcp://" + hostPort
|
||||||
|
if conf.MqttTLS {
|
||||||
|
uri = "ssl://" + hostPort
|
||||||
|
}
|
||||||
|
|
||||||
opts := mqtt.NewClientOptions().AddBroker(uri)
|
opts := mqtt.NewClientOptions().AddBroker(uri)
|
||||||
opts.SetClientID(conf.ValidatorAddress)
|
opts.SetClientID(conf.ValidatorAddress)
|
||||||
opts.SetUsername(conf.MqttUser)
|
opts.SetUsername(conf.MqttUser)
|
||||||
opts.SetPassword(conf.MqttPassword)
|
opts.SetPassword(conf.MqttPassword)
|
||||||
|
if conf.MqttTLS {
|
||||||
|
tlsConfig := &tls.Config{}
|
||||||
|
opts.SetTLSConfig(tlsConfig)
|
||||||
|
}
|
||||||
|
|
||||||
MQTTClient = mqtt.NewClient(opts)
|
MQTTClient = mqtt.NewClient(opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user