diff options
author | Daniel Kahn Gillmor <dkg@fifthhorseman.net> | 2019-11-25 16:45:45 -0500 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2019-11-28 11:09:00 -0700 |
commit | 8b9826322916cab2c795f5325fa2922c8cd0f020 (patch) | |
tree | 3d1c3ba7a3cc324f29e6a9bfae2a595b8c6a4778 /email-print-mime-structure | |
parent | de4194716f4cfbc101eea3cbc004eb589be977a7 (diff) | |
download | mailscripts-8b9826322916cab2c795f5325fa2922c8cd0f020.tar.gz |
email-print-mime-structure: decrypt PGP/MIME parts as bytes
Fully decode the encrypted part before passing it to any decryption
mechanism.
Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
Acked-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'email-print-mime-structure')
-rwxr-xr-x | email-print-mime-structure | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/email-print-mime-structure b/email-print-mime-structure index 27fb532..cdbe2ee 100755 --- a/email-print-mime-structure +++ b/email-print-mime-structure @@ -87,8 +87,8 @@ class MimePrinter(object): (parent.get_content_type().lower() == 'multipart/encrypted') and \ (str(parent.get_param('protocol')).lower() == 'application/pgp-encrypted') and \ (num == 2): - ciphertext = z.get_payload() - if not isinstance(ciphertext, str): + ciphertext = z.get_payload(decode=True) + if not isinstance(ciphertext, bytes): logging.warning('encrypted part was not a leaf mime part somehow') return if self.args.pgpkey: @@ -104,7 +104,7 @@ class MimePrinter(object): print(f'{newprefix}↧ (decrypts to)') self.print_tree(cryptopayload, newprefix + '└', z, 0) - def pgpy_decrypt(self, keys:List[str], ciphertext:str) -> Optional[Message]: + def pgpy_decrypt(self, keys:List[str], ciphertext:bytes) -> Optional[Message]: if pgpy is None: logging.warning(f'Python module pgpy is not available, not decrypting (try "apt install python3-pgpy")') return None @@ -121,11 +121,11 @@ class MimePrinter(object): pass return None - def gpg_decrypt(self, ciphertext:str) -> Optional[Message]: + def gpg_decrypt(self, ciphertext:bytes) -> Optional[Message]: inp:int outp:int inp, outp = os.pipe() - with open(outp, 'w') as outf: + with open(outp, 'wb') as outf: outf.write(ciphertext) out:subprocess.CompletedProcess[bytes] = subprocess.run(['gpg', '--batch', '--decrypt'], stdin=inp, |