diff options
author | Thais Siqueira <thais.siqueira@gmail.com> | 2017-01-24 18:48:08 -0200 |
---|---|---|
committer | drebs <drebs@leap.se> | 2017-01-27 08:34:40 -0200 |
commit | c02c73fea4901edd4002c3a317295c252ae426ca (patch) | |
tree | e44cc6a3b8b35482afa23de210b3c7194f2c5122 /src/leap | |
parent | 7a870fdc4471702146fc4ff8a6acae1d560b2984 (diff) |
Returns doc as None if we have some error during the encryption
When we had an error during encryption, the doc property "_enc_json" was empty and
we were saving this empty data on CouchDb.
Then it was causing the [GNUPG:] NODATA 2 error during decryption.
Related with: https://github.com/pixelated/pixelated-user-agent/issues/908
with @tayanefernandes
Diffstat (limited to 'src/leap')
-rw-r--r-- | src/leap/mx/mail_receiver.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/leap/mx/mail_receiver.py b/src/leap/mx/mail_receiver.py index 7c5a368..b8eb2ae 100644 --- a/src/leap/mx/mail_receiver.py +++ b/src/leap/mx/mail_receiver.py @@ -202,14 +202,22 @@ class MailReceiver(Service): with openpgp.TempGPGWrapper(gpgbinary='/usr/bin/gpg') as gpg: gpg.import_keys(pubkey) key = gpg.list_keys().pop() + + encryption_result = gpg.encrypt( + json.dumps(data, ensure_ascii=False), + key["fingerprint"], + symmetric=False) + + if encryption_result.ok == False: + log.msg("_encrypt_message: Encryption Failed" + "Status: %r" % (encryption_result.status,)) + return None + doc.content = { self.INCOMING_KEY: True, self.ERROR_DECRYPTING_KEY: False, ENC_SCHEME_KEY: EncryptionSchemes.PUBKEY, - ENC_JSON_KEY: str(gpg.encrypt( - json.dumps(data, ensure_ascii=False), - key["fingerprint"], - symmetric=False)) + ENC_JSON_KEY: str(encryption_result) } return doc |