mirror of
https://github.com/shirou/mqttcli.git
synced 2025-04-26 13:49:17 +08:00
add key option to specify private key
This commit is contained in:
parent
5c2b371a30
commit
ff7b2758d6
1
main.go
1
main.go
@ -133,6 +133,7 @@ func main() {
|
||||
cli.IntFlag{"q", 0, "QoS", ""},
|
||||
cli.StringFlag{"cafile", "", "CA certificates", ""},
|
||||
cli.StringFlag{"cert", "", "Client certificates", ""},
|
||||
cli.StringFlag{"key", "", "Client private key", ""},
|
||||
cli.StringFlag{"i", "", "ClientiId. Defaults random.", ""},
|
||||
cli.StringFlag{"m", "test message", "Message body", ""},
|
||||
cli.BoolFlag{"r", "message should be retained.", ""},
|
||||
|
12
mqtt.go
12
mqtt.go
@ -137,6 +137,18 @@ func NewOption(c *cli.Context) (*MQTT.ClientOptions, error) {
|
||||
TLSConfig.ClientAuth = tls.RequireAndVerifyClientCert
|
||||
TLSConfig.ClientCAs = certPool
|
||||
}
|
||||
key := c.String("key")
|
||||
if key != "" {
|
||||
scheme = "ssl"
|
||||
if cert == "" {
|
||||
return nil, fmt.Errorf("key specified but cert is not specified")
|
||||
}
|
||||
cert, err := tls.LoadX509KeyPair(cert, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
TLSConfig.Certificates = []tls.Certificate{cert}
|
||||
}
|
||||
insecure := c.Bool("insecure")
|
||||
if insecure {
|
||||
TLSConfig.InsecureSkipVerify = true
|
||||
|
Loading…
x
Reference in New Issue
Block a user