add secure password input via env var and stdin prompt
This commit is contained in:
22
main.go
22
main.go
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"golang.org/x/term"
|
||||||
"layeh.com/barnard/uiterm"
|
"layeh.com/barnard/uiterm"
|
||||||
"layeh.com/gumble/gumble"
|
"layeh.com/gumble/gumble"
|
||||||
_ "layeh.com/gumble/opus"
|
_ "layeh.com/gumble/opus"
|
||||||
@@ -15,12 +16,29 @@ func main() {
|
|||||||
// Command line flags
|
// Command line flags
|
||||||
server := flag.String("server", "localhost:64738", "the server to connect to")
|
server := flag.String("server", "localhost:64738", "the server to connect to")
|
||||||
username := flag.String("username", "", "the username of the client")
|
username := flag.String("username", "", "the username of the client")
|
||||||
password := flag.String("password", "", "the password of the server")
|
password := flag.String("password", "", "the password of the server (use MUMBLE_PASSWORD env var instead)")
|
||||||
|
passwordPrompt := flag.Bool("password-prompt", false, "prompt for server password on stdin")
|
||||||
insecure := flag.Bool("insecure", false, "skip server certificate verification")
|
insecure := flag.Bool("insecure", false, "skip server certificate verification")
|
||||||
certificate := flag.String("certificate", "", "PEM encoded certificate and private key")
|
certificate := flag.String("certificate", "", "PEM encoded certificate and private key")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
// Resolve password: env var > flag > prompt
|
||||||
|
pass := os.Getenv("MUMBLE_PASSWORD")
|
||||||
|
if pass == "" {
|
||||||
|
pass = *password
|
||||||
|
}
|
||||||
|
if pass == "" && *passwordPrompt {
|
||||||
|
fmt.Fprint(os.Stderr, "Password: ")
|
||||||
|
raw, err := term.ReadPassword(int(os.Stdin.Fd()))
|
||||||
|
fmt.Fprintln(os.Stderr)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
pass = string(raw)
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize
|
// Initialize
|
||||||
b := Barnard{
|
b := Barnard{
|
||||||
Config: gumble.NewConfig(),
|
Config: gumble.NewConfig(),
|
||||||
@@ -28,7 +46,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
b.Config.Username = *username
|
b.Config.Username = *username
|
||||||
b.Config.Password = *password
|
b.Config.Password = pass
|
||||||
|
|
||||||
if *insecure {
|
if *insecure {
|
||||||
b.TLSConfig.InsecureSkipVerify = true
|
b.TLSConfig.InsecureSkipVerify = true
|
||||||
|
|||||||
Reference in New Issue
Block a user