projects
/
edward.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
search text/plain for keys and encoded messages
[edward.git]
/
edward
diff --git
a/edward
b/edward
index d4321a85f797c5078c9357119fb7d2ad5e2de06a..baf3059e83d4579b92f8784adb94a4527457f251 100755
(executable)
--- a/
edward
+++ b/
edward
@@
-59,9
+59,7
@@
def main ():
gpgme_ctx = gpgme.Context()
gpgme_ctx.armor = True
gpgme_ctx = gpgme.Context()
gpgme_ctx.armor = True
- add_gpg_keys(email_text, gpgme_ctx)
-
- plaintext, keys = email_decode_flatten(email_text, gpgme_ctx)
+ plaintext, keys = email_decode_flatten(email_text, gpgme_ctx, False)
encrypt_to_key = choose_reply_encryption_key(keys)
reply_message = generate_reply(plaintext, email_from, \
encrypt_to_key = choose_reply_encryption_key(keys)
reply_message = generate_reply(plaintext, email_from, \
@@
-72,7
+70,7
@@
def main ():
print(reply_message)
print(reply_message)
-def email_decode_flatten (email_text, gpgme_ctx):
+def email_decode_flatten (email_text, gpgme_ctx
, from_decryption
):
body = ""
keys = []
body = ""
keys = []
@@
-109,10
+107,16
@@
def email_decode_flatten (email_text, gpgme_ctx):
keys += add_gpg_keys(payload, gpgme_ctx)
elif content_type == "text/plain":
keys += add_gpg_keys(payload, gpgme_ctx)
elif content_type == "text/plain":
- body += payload + "\n"
+ if from_decryption == True:
+ body += payload + "\n"
+
+ else:
+ plaintext, more_keys = decrypt_text(payload, gpgme_ctx)
+
+ body += plaintext
+ keys += more_keys
- else:
- body += payload + "\n"
+ keys += add_gpg_keys(payload, gpgme_ctx)
return body, keys
return body, keys
@@
-154,22
+158,24
@@
def get_email_subpart_info (part):
def add_gpg_keys (text, gpgme_ctx):
def add_gpg_keys (text, gpgme_ctx):
- keys = scan_and_grab(text,
- '-----BEGIN PGP PUBLIC KEY BLOCK-----',
- '-----END PGP PUBLIC KEY BLOCK-----')
+ key
_block
s = scan_and_grab(text,
+
'-----BEGIN PGP PUBLIC KEY BLOCK-----',
+
'-----END PGP PUBLIC KEY BLOCK-----')
-
fp
s = []
- for key
in key
s:
- fp = io.BytesIO(key.encode('ascii'))
+
key
s = []
+ for key
_block in key_block
s:
+ fp = io.BytesIO(key
_block
.encode('ascii'))
result = gpgme_ctx.import_(fp)
result = gpgme_ctx.import_(fp)
+ imports = result.imports
- fingerprint = result.imports[0][0]
- debug("added gpg key: " + fingerprint)
+ if imports != []:
+ fingerprint = imports[0][0]
+ keys += [gpgme_ctx.get_key(fingerprint)]
- fps += fingerprint
+ debug("added gpg key: " + fingerprint)
- return
fp
s
+ return
key
s
def decrypt_text (gpg_text, gpgme_ctx):
def decrypt_text (gpg_text, gpgme_ctx):
@@
-177,22
+183,21
@@
def decrypt_text (gpg_text, gpgme_ctx):
body = ""
keys = []
body = ""
keys = []
-
gpg_chun
ks = scan_and_grab(gpg_text,
+
msg_bloc
ks = scan_and_grab(gpg_text,
'-----BEGIN PGP MESSAGE-----',
'-----END PGP MESSAGE-----')
'-----BEGIN PGP MESSAGE-----',
'-----END PGP MESSAGE-----')
- plaintext
_and_sigs_chunks = decrypt_chunks(gpg_chun
ks, gpgme_ctx)
+ plaintext
s_and_sigs = decrypt_blocks(msg_bloc
ks, gpgme_ctx)
- for
chunk in plaintext_and_sigs_chunk
s:
- plaintext =
chunk
[0]
- sigs =
chunk
[1]
+ for
pair in plaintexts_and_sig
s:
+ plaintext =
pair
[0]
+ sigs =
pair
[1]
for sig in sigs:
for sig in sigs:
- key = get_pub_key(sig, gpgme_ctx)
- keys += [key]
+ keys += [gpgme_ctx.get_key(sig.fpr)]
# recursive for nested layers of mime and/or gpg
# recursive for nested layers of mime and/or gpg
- plaintext, more_keys = email_decode_flatten(plaintext, gpgme_ctx)
+ plaintext, more_keys = email_decode_flatten(plaintext, gpgme_ctx
, True
)
body += plaintext
keys += more_keys
body += plaintext
keys += more_keys
@@
-200,14
+205,6
@@
def decrypt_text (gpg_text, gpgme_ctx):
return body, keys
return body, keys
-def get_pub_key (sig, gpgme_ctx):
-
- fingerprint = sig.fpr
- key = gpgme_ctx.get_key(fingerprint)
-
- return key
-
-
def scan_and_grab (text, start_text, end_text):
matches = re.search('(' + start_text + '.*' + end_text + ')',
def scan_and_grab (text, start_text, end_text):
matches = re.search('(' + start_text + '.*' + end_text + ')',
@@
-221,17
+218,20
@@
def scan_and_grab (text, start_text, end_text):
return match_tuple
return match_tuple
-def decrypt_
chunks (gpg_chun
ks, gpgme_ctx):
+def decrypt_
blocks (msg_bloc
ks, gpgme_ctx):
- return [decrypt_
chunk(chunk, gpgme_ctx) for chunk in gpg_chun
ks]
+ return [decrypt_
block(block, gpgme_ctx) for block in msg_bloc
ks]
-def decrypt_
chunk (gpg_chun
k, gpgme_ctx):
+def decrypt_
block (msg_bloc
k, gpgme_ctx):
-
chunk_b = io.BytesIO(gpg_chun
k.encode('ascii'))
+
block_b = io.BytesIO(msg_bloc
k.encode('ascii'))
plain_b = io.BytesIO()
plain_b = io.BytesIO()
- sigs = gpgme_ctx.decrypt_verify(chunk_b, plain_b)
+ try:
+ sigs = gpgme_ctx.decrypt_verify(block_b, plain_b)
+ except:
+ return ("",[])
plaintext = plain_b.getvalue().decode('utf-8')
return (plaintext, sigs)
plaintext = plain_b.getvalue().decode('utf-8')
return (plaintext, sigs)