Improve comments, tweak default password prompt function.

This commit is contained in:
Greg 2019-09-04 22:43:29 -04:00
parent 9c711e9022
commit fc7a4c272e
2 changed files with 9 additions and 2 deletions

View File

@ -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")

View File

@ -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"},""))