From fc7a4c272edd3e20483fb16210f7f8f0c3d13be7 Mon Sep 17 00:00:00 2001 From: Greg Date: Wed, 4 Sep 2019 22:43:29 -0400 Subject: [PATCH] Improve comments, tweak default password prompt function. --- impl_darwin.go | 9 ++++++++- main.go | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/impl_darwin.go b/impl_darwin.go index 9fcf941..f730377 100644 --- a/impl_darwin.go +++ b/impl_darwin.go @@ -14,7 +14,7 @@ import ( ) func setAgentInfo() { - // get UID + // get UID of current user usr, err := user.Current() if err != nil { fmt.Printf("Error: cannot get user ID: %s\n", err) @@ -23,6 +23,7 @@ func setAgentInfo() { uid := usr.Uid // get GPG Agent PID + // look for gpg-agent running as the current user: output, err := exec.Command("pgrep", "-U", uid, "gpg-agent").Output() if err != nil { fmt.Printf("Error: %s\n", err) @@ -30,6 +31,7 @@ func setAgentInfo() { } else { fmt.Printf("gpg-agent process number is %s\n", output) } + // trim trailing /n and convert to int pid, err := strconv.Atoi(string(output[:len(output)-1])) if err != nil { fmt.Printf("Integer conversion failed: %s\n", err) @@ -37,6 +39,7 @@ func setAgentInfo() { } // find agent socket file + // find unix domain sockets opened by the current user's gpg-agent cmd := exec.Command("lsof", "-w", "-Fn", "-u", uid, "-baUcgpg-agent") stdout, err := cmd.StdoutPipe() if err != nil { @@ -49,6 +52,7 @@ func setAgentInfo() { fmt.Printf("Error: cannot run lsof: %s\n", err) } + // look for a socket named "S.gpg-agent" filename := "" for scanner.Scan() { x := scanner.Text() @@ -70,6 +74,8 @@ func setAgentInfo() { s := fmt.Sprintf("%s:%d:1", filename, pid) fmt.Printf("GPG_AGENT_INFO = %s\n", s) os.Setenv("GPG_AGENT_INFO",s) + + // gpg-agent is running, so use GPGPrompt as password prompt ask = GPGPrompt } @@ -77,6 +83,7 @@ func init() { setAgentInfo() } +//Clip copies a string to the clipboard func Clip(x string) { b := bytes.NewBuffer([]byte(x)) cmd := exec.Command("pbcopy") diff --git a/main.go b/main.go index 841baa9..7643750 100644 --- a/main.go +++ b/main.go @@ -176,7 +176,7 @@ func GPGPrompt(keys []openpgp.Key, symmetric bool) ([]byte, error) { } func (s *Store) Decrypt(name string, prompts ...func() []byte) (string,error) { - if len(prompts) > 0 { + if ask == nil { ask = AskPass(prompts...) } file := path.Join(s.Dir, strings.Join([]string{name,".gpg"},""))