From 1c61d3f9edc234d86354f780270f3da5d1e219b2 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 4 Nov 2015 21:48:25 -0500 Subject: [PATCH] Ignore hidden recipients when decrypting When --throw-keyids, --hidden-recipient, or --hidden-encrypt-to were used for an encrypted file, the encryption metadata uses all zeroes as the key ID. Ignore these key IDs to avoid generating extraneous messages during decryption or adding invalid IDs to the recipients list. Closes jamessan/vim-gnupg#50 Signed-off-by: James McCoy --- plugin/gnupg.vim | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/plugin/gnupg.vim b/plugin/gnupg.vim index 1a912c3..47eced1 100644 --- a/plugin/gnupg.vim +++ b/plugin/gnupg.vim @@ -514,15 +514,25 @@ function s:GPGDecrypt(bufread) let start = start + strlen("gpg: public key is ") let recipient = matchstr(output, s:keyPattern, start) call s:GPGDebug(1, "recipient is " . recipient) - let name = s:GPGNameToID(recipient) - if !empty(name) - let b:GPGRecipients += [name] - call s:GPGDebug(1, "name of recipient is " . name) - else - let b:GPGRecipients += [recipient] - echohl GPGWarning - echom "The recipient \"" . recipient . "\" is not in your public keyring!" - echohl None + " In order to support anonymous communication, GnuPG allows eliding + " information in the encryption metadata specifying what keys the file + " was encrypted to (c.f., --throw-keyids and --hidden-recipient). In + " that case, the recipient(s) will be listed as having used a key of all + " zeroes. + " Since this will obviously never actually be in a keyring, only try to + " convert to an ID or add to the recipients list if it's not a hidden + " recipient. + if recipient !~? '^0x0\+$' + let name = s:GPGNameToID(recipient) + if !empty(name) + let b:GPGRecipients += [name] + call s:GPGDebug(1, "name of recipient is " . name) + else + let b:GPGRecipients += [recipient] + echohl GPGWarning + echom "The recipient \"" . recipient . "\" is not in your public keyring!" + echohl None + end end let start = match(output, asymmPattern, start) endwhile