about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2017-02-11T15·30+0100
committerVincent Ambo <tazjin@gmail.com>2017-02-11T15·30+0100
commit393cff48479e3cb065c00fc542c353c5ac29f0af (patch)
tree69efbe1f2ac0154b623213ac4d803bd984a56451
parente6c3212018b6bcbe4a83c3e7c557fc43b0e7571d (diff)
feat: Don't echo password while inputting
-rw-r--r--README.md2
-rw-r--r--main.go28
2 files changed, 24 insertions, 6 deletions
diff --git a/README.md b/README.md
index 95e53115dcf0..1846a8beab7e 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ will be linked here in the future.
 ## Installation
 
 Make sure you have Go installed and `GOPATH` configured, then simply
-`go get github.com/tazjin/watchblob`.
+`go get github.com/tazjin/watchblob/...`.
 
 ## Usage
 
diff --git a/main.go b/main.go
index b556d606dd86..93a85324f192 100644
--- a/main.go
+++ b/main.go
@@ -7,6 +7,7 @@ import (
 	"net/http"
 	"os"
 	"strings"
+	"golang.org/x/crypto/ssh/terminal"
 )
 
 // The XML response returned by the WatchGuard server
@@ -21,16 +22,20 @@ type Resp struct {
 func main() {
 	args := os.Args[1:]
 
-	if len(args) != 3 {
-		fmt.Fprintf(os.Stderr, "Usage: watchblob <vpn-host> <username> <password>\n")
+	if len(args) != 1 {
+		fmt.Fprintln(os.Stderr, "Usage: watchblob <vpn-host>")
 		os.Exit(1)
 	}
 
 	host := args[0]
-	username := args[1]
-	password := args[2]
 
-	challenge, err := triggerChallengeResponse(&host, &username, &password)
+	username, password, err := readCredentials()
+	if err != nil {
+		fmt.Fprintf(os.Stderr, "Could not read credentials: %v\n", err)
+	}
+
+	fmt.Println("Requesting challenge from %s as user %s\n", host, *username)
+	challenge, err := triggerChallengeResponse(&host, username, password)
 
 	if err != nil || challenge.LogonStatus != 4 {
 		fmt.Fprintln(os.Stderr, "Did not receive challenge from server")
@@ -49,6 +54,19 @@ func main() {
 	fmt.Printf("Login succeeded, you may now (quickly) authenticate OpenVPN with %d as your password\n", token)
 }
 
+func readCredentials() (*string, *string, error) {
+	fmt.Printf("Username: ")
+	reader := bufio.NewReader(os.Stdin)
+	username, err := reader.ReadString('\n')
+
+	fmt.Printf("Password: ")
+	passwordBytes, err := terminal.ReadPassword(1)
+	password := string(passwordBytes)
+
+	// If an error occured, I don't care about which one it is.
+	return &username, &password, err
+}
+
 func triggerChallengeResponse(host *string, username *string, password *string) (r Resp, err error) {
 	return request(templateUrl(host, templateChallengeTriggerUri(username, password)))
 }