X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fgovpn%2Fverifier.go;h=0dc9388188ad0e1f0c29eec611e7218cae32b687;hb=ee26626bd18e74679c46caf140772f27e5814cfa;hp=ba51846ce23eb17c42b4a9b9fcc5d0333f848bbc;hpb=28b1dc0b98cded7f97af5ad2967d97afae5c006e;p=govpn.git diff --git a/src/govpn/verifier.go b/src/govpn/verifier.go index ba51846..0dc9388 100644 --- a/src/govpn/verifier.go +++ b/src/govpn/verifier.go @@ -29,6 +29,7 @@ import ( "github.com/agl/ed25519" "github.com/magical/argon2" + "golang.org/x/crypto/ssh/terminal" ) const ( @@ -117,11 +118,26 @@ func (v *Verifier) LongForm() string { ) } -// Read string from the file, trimming newline. -func StringFromFile(path string) string { - s, err := ioutil.ReadFile(path) +// Read the key either from text file (if path is specified), or +// from the terminal. +func KeyRead(path string) (string, error) { + var p []byte + var err error + var pass string + if path == "" { + fmt.Print("Passphrase:") + p, err = terminal.ReadPassword(0) + fmt.Print("\n") + pass = string(p) + } else { + p, err = ioutil.ReadFile(path) + pass = strings.TrimRight(string(p), "\n") + } if err != nil { - log.Fatalln("Can not read string from", path, err) + return "", err + } + if len(pass) == 0 { + return "", errors.New("Empty passphrase submitted") } - return strings.TrimRight(string(s), "\n") + return pass, err }