Skip to content

Commit

Permalink
Warn when throw-keyids is set (gopasspw#1759)
Browse files Browse the repository at this point in the history
Fixes gopasspw#1756

RELEASE_NOTES=[BUGFIX] Warn about --throw-keyids

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
  • Loading branch information
dominikschulz committed Feb 1, 2021
1 parent 02e7ebd commit d1af426
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
4 changes: 2 additions & 2 deletions internal/backend/crypto/age/unsupported.go
Expand Up @@ -73,7 +73,7 @@ func (a *Age) ReadNamesFromKey(ctx context.Context, buf []byte) ([]string, error
return nil, fmt.Errorf("not implemented")
}

// RecipientIDs is TODO
// RecipientIDs is not supported by design
func (a *Age) RecipientIDs(ctx context.Context, buf []byte) ([]string, error) {
return nil, fmt.Errorf("not supported by backend")
return nil, fmt.Errorf("reading recipient IDs is not supported by the age backend by design")
}
10 changes: 8 additions & 2 deletions internal/backend/crypto/gpg/cli/gpg.go
Expand Up @@ -33,6 +33,7 @@ type GPG struct {
pubKeys gpg.KeyList
privKeys gpg.KeyList
listCache *lru.TwoQueueCache
throwKids bool
}

// Config is the gpg wrapper config
Expand All @@ -56,8 +57,9 @@ func New(ctx context.Context, cfg Config) (*GPG, error) {
}

g := &GPG{
binary: "gpg",
args: append(defaultArgs, cfg.Args...),
binary: "gpg",
args: append(defaultArgs, cfg.Args...),
throwKids: fileContains(gpgConfigLoc(), "throw-keyids"),
}

debug.Log("initializing LRU cache")
Expand Down Expand Up @@ -111,6 +113,10 @@ func (g *GPG) RecipientIDs(ctx context.Context, buf []byte) ([]string, error) {
}
}

if g.throwKids {
// TODO shouldn't log here
out.Warning(ctx, "gpg option throw-keyids is set. some features might not work.")
}
return recp, nil
}

Expand Down
36 changes: 36 additions & 0 deletions internal/backend/crypto/gpg/cli/gpgcfg.go
@@ -0,0 +1,36 @@
package cli

import (
"bufio"
"os"
"path/filepath"
"strings"

"github.com/gopasspw/gopass/pkg/debug"
)

func gpgConfigLoc() string {
if sv := os.Getenv("GNUPGHOME"); sv != "" {
return filepath.Join(sv, "gpg.conf")
}

uhd, _ := os.UserHomeDir()
return filepath.Join(uhd, ".gnupg", "gpg.conf")
}

func fileContains(path, needle string) bool {
fh, err := os.Open(path)
if err != nil {
debug.Log("failed to open %q for reading: %s", path, err)
return false
}
defer fh.Close()

s := bufio.NewScanner(fh)
for s.Scan() {
if strings.Contains(s.Text(), needle) {
return true
}
}
return false
}

0 comments on commit d1af426

Please sign in to comment.