summaryrefslogtreecommitdiff
path: root/memoryhole/protection.py
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2016-04-28 00:12:23 -0300
committerRuben Pollan <meskio@sindominio.net>2016-04-28 00:12:23 -0300
commit7396398e81fda41d4cb2ea7ffbdfa8f02746cad8 (patch)
treeddd01d38a15399e516c31bdd2e7814ee9e21dc34 /memoryhole/protection.py
parent04e5136c3d2fbcfd30a374f95d8b7c5f819e0d27 (diff)
[feat] simple pgp/mime creation
Diffstat (limited to 'memoryhole/protection.py')
-rw-r--r--memoryhole/protection.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/memoryhole/protection.py b/memoryhole/protection.py
new file mode 100644
index 0000000..900b29a
--- /dev/null
+++ b/memoryhole/protection.py
@@ -0,0 +1,35 @@
+from email.mime.application import MIMEApplication
+
+from memoryhole.gpg import Gnupg
+from memoryhole.rfc3156 import PGPEncrypted, MultipartEncrypted
+
+
+def protect(msg, openpgp=Gnupg(), encrypt=True, obscure=True):
+ if encrypt:
+ return _encrypt_mime(msg, openpgp)
+
+ raise NotImplementedError()
+
+
+def _encrypt_mime(msg, openpgp):
+ newmsg = MultipartEncrypted('application/pgp-encrypted')
+ for hkey, hval in msg.items():
+ newmsg.add_header(hkey, hval)
+ del(msg[hkey])
+
+ encraddr = "" # TODO
+ signaddr = "" # TODO
+ encstr = openpgp.encrypt(msg.as_string(unixfrom=False),
+ encraddr, signaddr)
+ encmsg = MIMEApplication(
+ encstr, _subtype='octet-stream', _encoder=lambda x: x)
+ encmsg.add_header('content-disposition', 'attachment',
+ filename='msg.asc')
+
+ # create meta message
+ metamsg = PGPEncrypted()
+ metamsg.add_header('Content-Disposition', 'attachment')
+ # attach pgp message parts to new message
+ newmsg.attach(metamsg)
+ newmsg.attach(encmsg)
+ return newmsg