summaryrefslogtreecommitdiff
path: root/alot/crypto.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2017-09-22 10:00:29 -0700
committerDylan Baker <dylan@pnwbakers.com>2017-09-22 10:00:29 -0700
commita8a4b7904f4f1b18a32665193d9dea98395af2ac (patch)
tree0886066d8cfc9f3faa8095d9ef22f56e1c34dcd0 /alot/crypto.py
parentc6b8efc1f6784d757c601036e0ff982487fe0d29 (diff)
crypto: Handle message that is encrypted, but the signature is invalid
One case of this would be not having the public key of the signer. If the verification of the signatures fails, then use the signatures from the error, and try to redecrypt without verification. I have no tests yet, and this probably deserves tests. Fixes #1157
Diffstat (limited to 'alot/crypto.py')
-rw-r--r--alot/crypto.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/alot/crypto.py b/alot/crypto.py
index 6e3e8fa6..e8595d90 100644
--- a/alot/crypto.py
+++ b/alot/crypto.py
@@ -202,12 +202,15 @@ def decrypt_verify(encrypted):
"""
ctx = gpg.core.Context()
try:
- (plaintext, _, verify_result) = ctx.decrypt(encrypted, verify=True)
+ plaintext, _, verify_result = ctx.decrypt(encrypted, verify=True)
+ sigs = verify_result.signatures
except gpg.errors.GPGMEError as e:
raise GPGProblem(str(e), code=e.getcode())
- # what if the signature is bad?
+ except gpg.errors.BadSignatures as e:
+ plaintext, _, _ = ctx.decrypt(encrypted, verify=False)
+ sigs = e.result.signatures
- return verify_result.signatures, plaintext
+ return sigs, plaintext
def validate_key(key, sign=False, encrypt=False):