Skip to content

Commit

Permalink
Do not display (missing public key) for age identities (gopasspw#2166)
Browse files Browse the repository at this point in the history
They are fully defined by the public key.

RELEASE_NOTES=[BUGFIX] Do not print missing public key for age.

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
  • Loading branch information
dominikschulz authored Mar 17, 2022
1 parent 4caa582 commit 84e656f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
8 changes: 4 additions & 4 deletions internal/backend/crypto/gpg/cli/identities.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ func (g *GPG) FindIdentities(ctx context.Context, search ...string) ([]string, e
return kl.UseableKeys(gpg.IsAlwaysTrust(ctx)).Recipients(), nil
}

func (g *GPG) findKey(ctx context.Context, id string) gpg.Key {
func (g *GPG) findKey(ctx context.Context, id string) (gpg.Key, bool) {
kl, _ := g.listKeys(ctx, "secret", id)
if len(kl) >= 1 {
return kl[0]
return kl[0], true
}
kl, _ = g.listKeys(ctx, "public", id)
if len(kl) >= 1 {
return kl[0]
return kl[0], true
}
return gpg.Key{
Fingerprint: id,
}
}, false
}
22 changes: 18 additions & 4 deletions internal/backend/crypto/gpg/cli/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (g *GPG) listKeys(ctx context.Context, typ string, search ...string) (gpg.K
}
}
cmd := exec.CommandContext(ctx, g.binary, args...)
var errBuf = bytes.Buffer{}
errBuf := bytes.Buffer{}
cmd.Stderr = &errBuf

debug.Log("%s %+v\n", cmd.Path, cmd.Args)
Expand All @@ -46,7 +46,11 @@ func (g *GPG) listKeys(ctx context.Context, typ string, search ...string) (gpg.K

// Fingerprint returns the fingerprint.
func (g *GPG) Fingerprint(ctx context.Context, id string) string {
return g.findKey(ctx, id).Fingerprint
k, found := g.findKey(ctx, id)
if !found {
return ""
}
return k.Fingerprint
}

// FormatKey formats the details of a key id
Expand All @@ -55,16 +59,26 @@ func (g *GPG) Fingerprint(ctx context.Context, id string) string {
// - EmailFromKey: {{ .Email }}.
func (g *GPG) FormatKey(ctx context.Context, id, tpl string) string {
if tpl == "" {
return g.findKey(ctx, id).OneLine()
k, found := g.findKey(ctx, id)
if !found {
return ""
}
return k.OneLine()
}

tmpl, err := template.New(tpl).Parse(tpl)
if err != nil {
return ""
}

var gid gpg.Identity
k, found := g.findKey(ctx, id)
if found {
gid = k.Identity()
}

buf := &bytes.Buffer{}
if err := tmpl.Execute(buf, g.findKey(ctx, id).Identity()); err != nil {
if err := tmpl.Execute(buf, gid); err != nil {
debug.Log("Failed to render template %q: %s", tpl, err)
return ""
}
Expand Down
3 changes: 3 additions & 0 deletions internal/store/root/recipients.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ func (r *Store) RemoveRecipient(ctx context.Context, store, rec string) error {
func (r *Store) addRecipient(ctx context.Context, prefix string, root *tree.Root, recp string, pretty bool) error {
sub, _ := r.getStore(prefix)
key := fmt.Sprintf("%s (missing public key)", recp)
if v := sub.Crypto().FormatKey(ctx, recp, ""); v != "" {
key = v
}
kl, err := sub.Crypto().FindRecipients(ctx, recp)
if err == nil {
if len(kl) > 0 {
Expand Down

0 comments on commit 84e656f

Please sign in to comment.