Skip to content

Commit

Permalink
Check org.gpgtools.common UseKeychain on MacOS (#2144)
Browse files Browse the repository at this point in the history
RELEASE_NOTES=[ENHANCENMENT] Check for MacOS Keychain storing the GPG
passphrase.

Fixes #2137

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
  • Loading branch information
dominikschulz authored Mar 7, 2022
1 parent 757aa08 commit b5236f7
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
13 changes: 13 additions & 0 deletions internal/action/reminder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"os"

"github.com/gopasspw/gopass/internal/env"
"github.com/gopasspw/gopass/internal/out"
"github.com/gopasspw/gopass/pkg/ctxutil"
)
Expand All @@ -19,6 +20,18 @@ func (s *Action) printReminder(ctx context.Context) {
return
}

// this might be printed along other reminders
if s.rem.Overdue("env") {
msg, err := env.Check(ctx)
if err != nil {
out.Warningf(ctx, "Failed to check environment: %s", err)
}
if msg != "" {
out.Warningf(ctx, "%s", msg)
}
s.rem.Reset("env")
}

// Note: We only want to print one reminder per day (at most).
// So we intentionally return after printing one, leaving the others
// for the following days.
Expand Down
42 changes: 42 additions & 0 deletions internal/env/env_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//go:build darwin
// +build darwin

package env

import (
"bytes"
"context"
"io"
"os"
"os/exec"
"strings"
)

var (
// Stdin is exported for tests.
Stdin io.Reader = os.Stdin
// Stderr is exported for tests.
Stderr io.Writer = os.Stderr
)

func Check(ctx context.Context) (string, error) {
buf := &bytes.Buffer{}

cmd := exec.CommandContext(ctx, "defaults", "read", "org.gpgtools.common", "UseKeychain")
cmd.Stdin = Stdin
cmd.Stdout = buf
cmd.Stderr = Stderr

if err := cmd.Run(); err != nil {
return "", err
}

// if the keychain is not used, we can skip the rest
if strings.ToUpper(strings.TrimSpace(buf.String())) == "NO" {
return "", nil
}

// gpg uses the keychain to store the passphrase, warn once in a while that users
// might want to change that because it's not secure.
return "pinentry-mac will use the MacOS Keychain to store your passphrase indefinitely. Consider running 'defaults write org.gpgtools.common UseKeychain NO' to disable that.", nil
}
11 changes: 11 additions & 0 deletions internal/env/env_others.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build !darwin
// +build !darwin

package env

import "context"

// Check does nothing on these OSes, yet.
func Check(ctx context.Context) (string, error) {
return "", nil
}

0 comments on commit b5236f7

Please sign in to comment.