Project

General

Profile

Feature #6184

Feature #6183: Use multiple PGP/MIME attachments for text snippets and OpenPGP public key included in Whisperback reports

Find Python library to do PGP/MIME

Added by intrigeri about 6 years ago. Updated over 4 years ago.

Status:
Resolved
Priority:
Low
Assignee:
Category:
-
Target version:
-
Start date:
07/23/2013
Due date:
% Done:

100%

Feature Branch:
Type of work:
Research
Blueprint:
Starter:
Yes
Affected tool:

Description

We need multiple PGP/MIME attachments for the parent ticket.

History

#1 Updated by alant almost 6 years ago

  • Assignee set to alant

https://pypi.python.org/pypi/pgp-mime/ seems the only candidate. It is not in Debian yet. Next step is to review it.

#2 Updated by alant about 5 years ago

https://pypi.python.org/pypi/pgp-mime/ seems the only candidate. It is not in Debian yet. Next step is to review it.

Looks unmaintained, but doing PGP/MIME with email.mime which is in the standard library seems easy (http://www.physics.drexel.edu/~wking/code/python/send_pgp_mime):


        enc = MIMEApplication(_data=encrypted, _subtype='octet-stream',
                              _encoder=encode_7or8bit)
        enc.set_charset('us-ascii')

        control = MIMEApplication(_data='Version: 1\n',
                                  _subtype='pgp-encrypted',
                                  _encoder=encode_7or8bit)

        msg = MIMEMultipart('encrypted', micalg='pgp-sha1',
                            protocol='application/pgp-encrypted')
        msg.attach(control)
        msg.attach(enc)

        msg['Content-Disposition'] = 'inline'

#3 Updated by alant over 4 years ago

  • % Done changed from 0 to 20

The following works:

#!/usr/bin/python

import email.mime.application
import email.mime.multipart
import email.mime.text
import email.encoders

import gnupg

text="Test" 
keyid="alan@boum.org" 

def pgp_mime(message, recepients):
    encrypted_content = gpg.encrypt(message.as_string(), recepients)

    enc = email.mime.application.MIMEApplication(
            _data=str(encrypted_content),
            _subtype='octet-stream; name="encrypted.asc"',
            _encoder=email.encoders.encode_7or8bit)
    enc['Content-Description'] = 'OpenPGP encrypted message'
    enc.set_charset('us-ascii')

    control = email.mime.application.MIMEApplication(
            _data='Version: 1\n',
            _subtype='pgp-encrypted',
            _encoder=email.encoders.encode_7or8bit)
    control.set_charset('us-ascii')

    encmsg = email.mime.multipart.MIMEMultipart(
            'encrypted',
            protocol='application/pgp-encrypted')
    encmsg.attach(control)
    encmsg.attach(enc)
    encmsg['Content-Disposition'] = 'inline'

    return encmsg

gpg = gnupg.GPG()
message = email.mime.text.MIMEText(_text=text)
encrypted_message = pgp_mime(message, keyid)
print(encrypted_message.as_string())

#4 Updated by alant over 4 years ago

The result should conform to https://tools.ietf.org/html/rfc3156.

#5 Updated by alant over 4 years ago

  • Status changed from Confirmed to Resolved
  • % Done changed from 20 to 100

The above code works as looks simple enough to maintain ourselves.

Also available in: Atom PDF