zeyple
zeyple copied to clipboard
End to End Encryption for using K-9 Mail/Open Keychain
I made a simple bodged example of how I made a "encrypt, sign and forward everything to 1 email" setup for reading on K-9 Mail/Open Keychain which didn't like zeyple's attachment style of encryption. I used "os.popen" instead of the gpg module (which seems lacking). (Using curl with Gmail also requires allowing less secure transfers for the account which isn't ideal).
Perhaps this will be helpful in making a more robust solution as I'm not really familiar with python.
/usr/local/bin/zeyple.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
try:
from configparser import SafeConfigParser # Python 3
except ImportError:
from ConfigParser import SafeConfigParser # Python 2
# Boiler plate to avoid dependency on six
# BBB: Python 2.7 support
PY3K = sys.version_info > (3, 0)
#if __name__ == '__main__':
if True:
recipients = sys.argv[1:]
# BBB: Python 2.7 support
binary_stdin = sys.stdin.buffer if PY3K else sys.stdin
message = binary_stdin.read()
f = open("/home/zeyple/.gnupg/message.enc", "w")
text = message
posa = text.find("Subject: ")
subject = text[posa:].split("\n",1)
subject = subject[0]
text = text.partition("\n\n")
f.write( text[2] )
f.close()
os.popen("gpg --homedir /home/zeyple/.gnupg --batch --yes --passphrase=CERTPASSGOESHERE --pinentry-mode loopback --always-trust -ea --sign -u \"John Smith <[email protected]>\" -r \"John Smith <[email protected]>\" -o - /home/zeyple/.gnupg/message.enc > /home/zeyple/.gnupg/message2.enc")
#Needed for curl
os.popen('sed -i -E \":a;N;$!ba;s/\r{0,1}\n/\\n/g\" /home/zeyple/.gnupg/message2.enc')
f = open("/home/zeyple/.gnupg/message2.enc", "r")
text = f.read()
text = text.partition("-----")
body = text[2]
f.close()
os.popen("echo \"" + subject + " \n\n-----" + body + "\" | /usr/bin/cur l--retry 5 --url smtps://smtp.gmail.com:465 --mail-from [email protected] --mail-rcpt [email protected] --user [email protected]:fakeemailpassword --ssl-reqd --insecure --silent --ciphers ECDHE-RSA-AES128-GCM-SHA256 -T -")
os.remove('/home/zeyple/.gnupg/message.enc')
os.remove('/home/zeyple/.gnupg/message2.enc')