1
0
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:
Shirou WAKAYAMA 2015-10-09 13:44:25 +09:00
parent 5c2b371a30
commit ff7b2758d6
2 changed files with 13 additions and 0 deletions

View File

@ -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
View File

@ -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