Skip to content

Commit

Permalink
Depending on how the .gpg-ids file was written, we may not match agai…
Browse files Browse the repository at this point in the history
…nst the string itself. (#2147)

* Depending on how the .gpg-ids file was written, we may not match against the string itself.

We may need to do a query to crypto.FindRecipients to get their details to match against when removing. Fix for #1964

RELEASE_NOTES=[BUGFIX] Fixes an issue where recipients remove may fail
with "recipient not in store"

Signed-off-by: Ben Phegan <benphegan@gmail.com>

* Fixed variable naming and Printf to Warningf as per PR.

    RELEASE_NOTES=[BUGFIX] Fixes an issue where recipients remove may fail
    with "recipient not in store"

    Signed-off-by: Ben Phegan <benphegan@gmail.com>
  • Loading branch information
BenPhegan authored Mar 4, 2022
1 parent 57be868 commit 1f44d5d
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions internal/store/leaf/recipients.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (s *Store) SetRecipients(ctx context.Context, rs []string) error {
func (s *Store) RemoveRecipient(ctx context.Context, id string) error {
keys, err := s.crypto.FindRecipients(ctx, id)
if err != nil {
out.Printf(ctx, "Warning: Failed to get GPG Key Info for %s: %s", id, err)
out.Warningf(ctx, "Warning: Failed to get GPG Key Info for %s: %s", id, err)
}

rs, err := s.GetRecipients(ctx, "")
Expand All @@ -111,16 +111,37 @@ func (s *Store) RemoveRecipient(ctx context.Context, id string) error {
nk := make([]string, 0, len(rs)-1)
RECIPIENTS:
for _, k := range rs {

// First lets try a simple match of the stored ids
if k == id {
debug.Log("removing recipient based on id match %s", k)
continue RECIPIENTS
}

// If we don't match immediately, we may need to loop through the recipient keys to try and match.
// To do this though, we need to ensure that we also do a FindRecipients on the id name from the stored ids.
recipientIds, err := s.crypto.FindRecipients(ctx, k)
if err != nil {
out.Warningf(ctx, "Warning: Failed to get GPG Key Info for %s: %s", k, err)
}
debug.Log("returned the following ids for recipient %s: %s", k, recipientIds)

// if the key is available locally we can also match the id against
// the fingerprint
// the fingerprint or failing that we can try against the recipientIds
for _, key := range keys {
if strings.HasSuffix(key, k) {
debug.Log("removing recipient based on id suffix match: %s %s", key, k)
continue RECIPIENTS
}

for _, recipientID := range recipientIds {
if recipientID == key {
debug.Log("removing recipient based on recipient id match %s", recipientID)
continue RECIPIENTS
}
}
}

nk = append(nk, k)
}

Expand Down

0 comments on commit 1f44d5d

Please sign in to comment.