From b17a3ae372714dd7fc1b3e195526fde16635194b Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Fri, 1 Mar 2024 22:11:59 -0500 Subject: [PATCH] Implement password hiding in entry readouts --- main.go | 6 +++--- src/cli/entryReader.go | 15 ++++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 9277ce6..c697fbd 100644 --- a/main.go +++ b/main.go @@ -26,12 +26,13 @@ func main() { // entry reader shortcut (if no other arguments are supplied) if argsCount == 1 { - cli.EntryReaderShortcut(targetLocation) + cli.EntryReaderShortcut(targetLocation, true) // perform other operations on the entry (if other arguments are supplied) } else if argsCount == 2 { switch args[1] { - + case "show", "-s": + cli.EntryReaderShortcut(targetLocation, false) case "shear": // TODO offline.Shear(targetLocation), exit after run case "gen": // TODO offline.Gen(targetLocation), exit after run case "copy": @@ -42,7 +43,6 @@ func main() { cli.HelpAdd() default: cli.HelpMain() - } } else if argsCount == 3 { diff --git a/src/cli/entryReader.go b/src/cli/entryReader.go index 67cbcd6..9d993b0 100644 --- a/src/cli/entryReader.go +++ b/src/cli/entryReader.go @@ -6,9 +6,10 @@ import ( "os" ) +const ansiShownPassword = "\033[38;5;10m" + // EntryReader prints the decrypted contents of a libmutton entry in a human-readable format -// TODO implement password hiding -func EntryReader(decryptedEntry []string) { +func EntryReader(decryptedEntry []string, hidePassword bool) { fmt.Println() // track if extended notes have been printed (to avoid printing an extra newline) @@ -30,7 +31,11 @@ func EntryReader(decryptedEntry []string) { case 1: // if the first field (password) is not empty, print it if decryptedEntry[0] != "" { - fmt.Print(ansiDirectoryHeader + "Password:" + offline.AnsiReset + "\n" + decryptedEntry[0] + "\n\n") + if !hidePassword { + fmt.Print(ansiDirectoryHeader + "Password:" + offline.AnsiReset + "\n" + ansiShownPassword + decryptedEntry[0] + offline.AnsiReset + "\n\n") + } else { + fmt.Print(ansiDirectoryHeader + "Password:" + offline.AnsiReset + "\n" + ansiEmptyDirectoryWarning + "End command in \"show\" or \"-s\" to view" + offline.AnsiReset + "\n\n") + } } case 2: // if the third field (url) is not empty, print it @@ -59,9 +64,9 @@ func EntryReader(decryptedEntry []string) { os.Exit(0) } -func EntryReaderShortcut(targetLocation string) { +func EntryReaderShortcut(targetLocation string, hidePassword bool) { if isFile, _ := offline.TargetIsFile(targetLocation, true); isFile { - EntryReader(offline.DecryptGPG(targetLocation)) + EntryReader(offline.DecryptGPG(targetLocation), hidePassword) } else { fmt.Println(offline.AnsiError + "Failed to read \"" + targetLocation + "\" - it is a directory" + offline.AnsiReset) }