Skip to content

Commit

Permalink
Allow subkeys
Browse files Browse the repository at this point in the history
Fixes gopasspw#1841
Fixes gopasspw#1842

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
  • Loading branch information
dominikschulz committed Mar 20, 2021
1 parent 2fdeb0f commit 86f3ef1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
8 changes: 4 additions & 4 deletions internal/action/recipients.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@ func (s *Action) RecipientsAdd(c *cli.Context) error {
// select recipient
recipients := []string(c.Args().Slice())
if len(recipients) < 1 {
debug.Log("no recipients given, asking for selection")
r, err := s.recipientsSelectForAdd(ctx, store)
if err != nil {
return err
}
recipients = r
}

debug.Log("adding recipients: %+v", recipients)
for _, r := range recipients {
keys, err := crypto.FindRecipients(ctx, r)
if err != nil {
Expand All @@ -109,11 +111,9 @@ func (s *Action) RecipientsAdd(c *cli.Context) error {
}

recp := r
if len(keys) > 0 {
recp = crypto.Fingerprint(ctx, keys[0])
}
debug.Log("found recipients for %q: %+v", r, keys)

if !termio.AskForConfirmation(ctx, fmt.Sprintf("Do you want to add %q as a recipient to the store %q?", crypto.FormatKey(ctx, recp, ""), store)) {
if !termio.AskForConfirmation(ctx, fmt.Sprintf("Do you want to add %q (key %q) as a recipient to the store %q?", crypto.FormatKey(ctx, recp, ""), recp, store)) {
continue
}

Expand Down
8 changes: 6 additions & 2 deletions internal/backend/crypto/gpg/cli/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,14 @@ func (g *GPG) FindRecipients(ctx context.Context, search ...string) ([]string, e
if err != nil || kl == nil {
return nil, err
}

recp := kl.UseableKeys(gpg.IsAlwaysTrust(ctx)).Recipients()
if gpg.IsAlwaysTrust(ctx) {
return kl.Recipients(), nil
recp = kl.Recipients()
}
return kl.UseableKeys(gpg.IsAlwaysTrust(ctx)).Recipients(), nil

debug.Log("found useable keys for %+v: %+v (all: %+v)", search, recp, kl.Recipients())
return recp, nil
}

// ListIdentities returns a parsed list of GPG secret keys
Expand Down
3 changes: 3 additions & 0 deletions internal/backend/crypto/gpg/key_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ func (kl KeyList) Recipients() []string {
sort.Sort(kl)
for _, k := range kl {
l = append(l, k.ID())
for sid := range k.SubKeys {
l = append(l, sid)
}
}
return l
}
Expand Down
3 changes: 2 additions & 1 deletion internal/store/leaf/recipients.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (s *Store) AddRecipient(ctx context.Context, id string) error {
return fmt.Errorf("failed to read recipient list: %w", err)
}

debug.Log("new recipient: %q - existing: %+v", id, rs)
for _, k := range rs {
if k == id {
return fmt.Errorf("recipient already in store")
Expand Down Expand Up @@ -181,7 +182,7 @@ func (s *Store) getRecipients(ctx context.Context, idf string) ([]string, error)
if fp == "" {
fp = r
}
finalRecps = append(finalRecps, fp)
finalRecps = append(finalRecps, fp+" key: "+r)
}
sort.Strings(finalRecps)
return finalRecps, nil
Expand Down

0 comments on commit 86f3ef1

Please sign in to comment.