From 86f3ef11e54fd74a8e2cc5398fa14cf00b0855be Mon Sep 17 00:00:00 2001 From: Dominik Schulz Date: Tue, 16 Mar 2021 21:56:28 +0100 Subject: [PATCH] Allow subkeys Fixes #1841 Fixes #1842 Signed-off-by: Dominik Schulz --- internal/action/recipients.go | 8 ++++---- internal/backend/crypto/gpg/cli/keyring.go | 8 ++++++-- internal/backend/crypto/gpg/key_list.go | 3 +++ internal/store/leaf/recipients.go | 3 ++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/internal/action/recipients.go b/internal/action/recipients.go index 357bf4ef1d..cd6e797e46 100644 --- a/internal/action/recipients.go +++ b/internal/action/recipients.go @@ -84,6 +84,7 @@ 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 @@ -91,6 +92,7 @@ func (s *Action) RecipientsAdd(c *cli.Context) error { recipients = r } + debug.Log("adding recipients: %+v", recipients) for _, r := range recipients { keys, err := crypto.FindRecipients(ctx, r) if err != nil { @@ -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 } diff --git a/internal/backend/crypto/gpg/cli/keyring.go b/internal/backend/crypto/gpg/cli/keyring.go index 621eb81091..66818d6eed 100644 --- a/internal/backend/crypto/gpg/cli/keyring.go +++ b/internal/backend/crypto/gpg/cli/keyring.go @@ -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 diff --git a/internal/backend/crypto/gpg/key_list.go b/internal/backend/crypto/gpg/key_list.go index 6ca57ae98f..18a7b3e808 100644 --- a/internal/backend/crypto/gpg/key_list.go +++ b/internal/backend/crypto/gpg/key_list.go @@ -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 } diff --git a/internal/store/leaf/recipients.go b/internal/store/leaf/recipients.go index d11dbb1220..be5413a833 100644 --- a/internal/store/leaf/recipients.go +++ b/internal/store/leaf/recipients.go @@ -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") @@ -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