Suppress password prompt when using -extpass
Also, add color to the error messages.
This commit is contained in:
parent
e799ae672d
commit
1030522fe6
4
main.go
4
main.go
@ -96,7 +96,9 @@ func loadConfig(args *argContainer) (masterkey []byte, confFile *cryptfs.ConfFil
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(ERREXIT_LOADCONF)
|
os.Exit(ERREXIT_LOADCONF)
|
||||||
}
|
}
|
||||||
fmt.Printf("Password: ")
|
if args.extpass == "" {
|
||||||
|
fmt.Printf("Password: ")
|
||||||
|
}
|
||||||
pw := readPassword(args.extpass)
|
pw := readPassword(args.extpass)
|
||||||
cryptfs.Info.Printf("Decrypting master key... ")
|
cryptfs.Info.Printf("Decrypting master key... ")
|
||||||
cryptfs.Warn.Enabled = false // Silence DecryptBlock() error messages on incorrect password
|
cryptfs.Warn.Enabled = false // Silence DecryptBlock() error messages on incorrect password
|
||||||
|
27
password.go
27
password.go
@ -10,15 +10,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func readPasswordTwice(extpass string) string {
|
func readPasswordTwice(extpass string) string {
|
||||||
fmt.Printf("Password: ")
|
if extpass == "" {
|
||||||
p1 := readPassword(extpass)
|
fmt.Printf("Password: ")
|
||||||
fmt.Printf("Repeat: ")
|
p1 := readPassword("")
|
||||||
p2 := readPassword(extpass)
|
fmt.Printf("Repeat: ")
|
||||||
if p1 != p2 {
|
p2 := readPassword("")
|
||||||
fmt.Printf("Passwords do not match\n")
|
if p1 != p2 {
|
||||||
os.Exit(ERREXIT_PASSWORD)
|
fmt.Println(colorRed + "Passwords do not match" + colorReset)
|
||||||
|
os.Exit(ERREXIT_PASSWORD)
|
||||||
|
}
|
||||||
|
return p1
|
||||||
|
} else {
|
||||||
|
return readPassword(extpass)
|
||||||
}
|
}
|
||||||
return p1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// readPassword - get password from terminal
|
// readPassword - get password from terminal
|
||||||
@ -33,10 +37,9 @@ func readPassword(extpass string) string {
|
|||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
output, err = cmd.Output()
|
output, err = cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("extpass program returned error: %v\n", err)
|
fmt.Printf(colorRed+"extpass program returned error: %v\n"+colorReset, err)
|
||||||
os.Exit(ERREXIT_PASSWORD)
|
os.Exit(ERREXIT_PASSWORD)
|
||||||
}
|
}
|
||||||
fmt.Printf("(extpass)\n")
|
|
||||||
// Trim trailing newline like terminal.ReadPassword() does
|
// Trim trailing newline like terminal.ReadPassword() does
|
||||||
if output[len(output)-1] == '\n' {
|
if output[len(output)-1] == '\n' {
|
||||||
output = output[:len(output)-1]
|
output = output[:len(output)-1]
|
||||||
@ -45,14 +48,14 @@ func readPassword(extpass string) string {
|
|||||||
fd := int(os.Stdin.Fd())
|
fd := int(os.Stdin.Fd())
|
||||||
output, err = terminal.ReadPassword(fd)
|
output, err = terminal.ReadPassword(fd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error: Could not read password from terminal: %v\n", err)
|
fmt.Printf(colorRed+"Could not read password from terminal: %v\n"+colorReset, err)
|
||||||
os.Exit(ERREXIT_PASSWORD)
|
os.Exit(ERREXIT_PASSWORD)
|
||||||
}
|
}
|
||||||
fmt.Printf("\n")
|
fmt.Printf("\n")
|
||||||
}
|
}
|
||||||
password = string(output)
|
password = string(output)
|
||||||
if password == "" {
|
if password == "" {
|
||||||
fmt.Printf("Error: password is empty\n")
|
fmt.Printf(colorRed + "Password is empty\n" + colorReset)
|
||||||
os.Exit(ERREXIT_PASSWORD)
|
os.Exit(ERREXIT_PASSWORD)
|
||||||
}
|
}
|
||||||
return password
|
return password
|
||||||
|
Loading…
Reference in New Issue
Block a user