forked from gopasspw/gopass
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check org.gpgtools.common UseKeychain on MacOS (gopasspw#2144)
RELEASE_NOTES=[ENHANCENMENT] Check for MacOS Keychain storing the GPG passphrase. Fixes gopasspw#2137 Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
- Loading branch information
1 parent
26130ac
commit 772d644
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |