From 0a064403232f5427f74b53947ed9f7bb5726c5fa Mon Sep 17 00:00:00 2001 From: Andrew Engelbrecht Date: Mon, 20 Jul 2015 15:10:25 -0400 Subject: [PATCH] added the beginning of a testing suite to edward automated testing is helpful. --- .gitignore | 1 - edward | 42 ++++++++++++++++++++++--------- edward_config.py | 4 +-- tests/out1.txt | 23 +++++++++++++++++ tests/test1.eml | 43 ++++++++++++++++++++++++++++++++ tests/testgnupghome/pubring.gpg | Bin 0 -> 696 bytes tests/testgnupghome/random_seed | Bin 0 -> 600 bytes tests/testgnupghome/secring.gpg | Bin 0 -> 1360 bytes tests/testgnupghome/trustdb.gpg | Bin 0 -> 1280 bytes 9 files changed, 98 insertions(+), 15 deletions(-) create mode 100644 tests/out1.txt create mode 100644 tests/test1.eml create mode 100644 tests/testgnupghome/pubring.gpg create mode 100644 tests/testgnupghome/random_seed create mode 100644 tests/testgnupghome/secring.gpg create mode 100644 tests/testgnupghome/trustdb.gpg diff --git a/.gitignore b/.gitignore index 060a8e5..5236e1e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ *~ -tests diff --git a/edward b/edward index 6b189b6..8fc2613 100755 --- a/edward +++ b/edward @@ -52,24 +52,41 @@ def main (): handle_args() + gpgme_ctx = get_gpg_context(edward_config.gnupghome, + edward_config.sign_with_key) + email_text = sys.stdin.read() email_from, email_subject = email_from_subject(email_text) - os.environ['GNUPGHOME'] = edward_config.gnupghome - gpgme_ctx = gpgme.Context() - gpgme_ctx.armor = True - 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, \ email_subject, encrypt_to_key, - edward_config.sign_with_key, gpgme_ctx) print(reply_message) +def get_gpg_context (gnupghome, sign_with_key_fp): + + os.environ['GNUPGHOME'] = gnupghome + + gpgme_ctx = gpgme.Context() + gpgme_ctx.armor = True + + try: + sign_with_key = gpgme_ctx.get_key(sign_with_key_fp) + except: + error("unable to load signing key. is the gnupghome " + + "and signing key properly set in the edward_config.py?") + exit(1) + + gpgme_ctx.signers = [sign_with_key] + + return gpgme_ctx + + def email_decode_flatten (email_text, gpgme_ctx, from_decryption): body = "" @@ -250,7 +267,7 @@ def choose_reply_encryption_key (keys): def generate_reply (plaintext, email_from, email_subject, encrypt_to_key, - sign_with_fingerprint, gpgme_ctx): + gpgme_ctx): reply = "To: " + email_from + "\n" @@ -272,7 +289,6 @@ def generate_reply (plaintext, email_from, email_subject, encrypt_to_key, encrypted_text = encrypt_sign_message(plaintext_mime.as_string(), encrypt_to_key, - sign_with_fingerprint, gpgme_ctx) control_mime = MIMEApplication("Version: 1", @@ -310,10 +326,7 @@ def email_quote_text (text): return quoted_message -def encrypt_sign_message (plaintext, encrypt_to_key, sign_with_fingerprint, gpgme_ctx): - - sign_with_key = gpgme_ctx.get_key(sign_with_fingerprint) - gpgme_ctx.signers = [sign_with_key] +def encrypt_sign_message (plaintext, encrypt_to_key, gpgme_ctx): plaintext_bytes = io.BytesIO(plaintext.encode('ascii')) encrypted_bytes = io.BytesIO() @@ -325,10 +338,15 @@ def encrypt_sign_message (plaintext, encrypt_to_key, sign_with_fingerprint, gpgm return encrypted_txt +def error (error_msg): + + sys.stderr.write(progname + ": " + error_msg + "\n") + + def debug (debug_msg): if edward_config.debug == True: - sys.stderr.write(progname + ": " + debug_msg + "\n") + error(debug_msg) def handle_args (): diff --git a/edward_config.py b/edward_config.py index 5523f3d..a1c1b47 100644 --- a/edward_config.py +++ b/edward_config.py @@ -25,8 +25,8 @@ Code sourced from these projects: """ -gnupghome = "/home/e/edward/.gnupg/" -sign_with_key = "F357AA1A5B1FA42CFD9FE52A9FF2194CC09A61E8" +gnupghome = "./tests/testgnupghome/" +sign_with_key = "2470F96DB3CB20D2A39F89BA88611B2A4205FDDF" debug = False diff --git a/tests/out1.txt b/tests/out1.txt new file mode 100644 index 0000000..265c9d2 --- /dev/null +++ b/tests/out1.txt @@ -0,0 +1,23 @@ +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: quoted-printable + +thanks for the message! + + +> thanks for the message! +>=20 +> > =C3=9Cber Spa=C3=9F. +> >=20 +> > qual =C3=A8 il suono di una mano sola? +> >=20 +> > =E3=81=93=E3=82=93=E3=81=AB=E3=81=A1=E3=81=AF=E3=80=81=E3=81=8A=E5=85= +=83=E6=B0=97=E3=81=A7=E3=81=99=E3=81=8B=EF=BC=9F +> >=20 +>=20 +> test. +>=20 +> -andrew +>=20 +>=20 +>=20 diff --git a/tests/test1.eml b/tests/test1.eml new file mode 100644 index 0000000..7dc9339 --- /dev/null +++ b/tests/test1.eml @@ -0,0 +1,43 @@ +From: No One +MIME-Version: 1.0 +To: No One +Subject: =?UTF-8?B?44GT44KT44Gr44Gh44Gv44CB44GK5YWD5rCX44Gn44GZ44GL77yf?= +Content-Type: multipart/encrypted; + protocol="application/pgp-encrypted"; + boundary="x2iAciceo0NrKsl4uFVFGTgJ6k0ocg8FW" + +This is an OpenPGP/MIME encrypted message (RFC 4880 and 3156) +--x2iAciceo0NrKsl4uFVFGTgJ6k0ocg8FW +Content-Type: application/pgp-encrypted +Content-Description: PGP/MIME version identification + +Version: 1 + +--x2iAciceo0NrKsl4uFVFGTgJ6k0ocg8FW +Content-Type: application/octet-stream; name="encrypted.asc" +Content-Description: OpenPGP encrypted message +Content-Disposition: inline; filename="encrypted.asc" + +-----BEGIN PGP MESSAGE----- +Version: GnuPG v1 + +hIwDWouAYlp2iv8BA/sEjt5WzTB5XjR1ya3gb9q2bAhyn/KqxTX12K6/ZgiyVwO4 +1MW8MaVx1l9+RTeWj1mWYo7snTGsKYvUjnrFaL25LghxTcqiiIgrQbXS+94nbmmJ +l5XUOND4Z9sLutWZ12edAZCPXONuvsRpjKbJ0COo2xT8dRG/nYPch5l+iQbW9tLp +AYA+g74i8gOOvGubE9EAtcTCODfH/ZOeDfwBZx0DzyhJ8/WkDcgSTUX5O64o53z9 +ps4jcyw2usX74iNNiBvFsYLlFe3ouHnPgXidLCmuHGKm+NYSe2IHFaBNuMn9sjzm +nkzuN5DxC5bnm4VsAY4hqh3JBlU9KhYse8z2JANNqe3ykF350mC5HZ7vldtiYzyI +gAOJjkisIclt4W7S+zNXlAe+wtDjRadWAjLB1NO41ByBSqOTXo2HnLIE/wjZYAcO ++6AcCykXcnpgPbcpWxtmStVrUdCOhHJHyHxZaOtmym0+5ZxwEx3ZTNZI01LNUJ72 +6WGgEA7VnwYZpIONWpHiFE5R4nn/C/O465R60EM9V8rS7JyVNP/YBRVVVl1EyjDZ +scOoTiV3dX1+42Mhhn7CrwrgADSID00gPrYWRiVjJZFfDIJoKShk4LxhoKCwiNr3 +lTFGV37BBQvAi5Ff38IhDF9maHlq1zNWYicQ1gt4IiWPToXCwEkAPvuBJngBoD7v +y+BdGLSHDBM0aaM9XrUdIjp2JGDMkDu0omXluXDsy5arhdOPDz7DlKcRiNvdYc1P +oR+Efnj6REgGXX7H/xwmD9+ZK2PBFMUMOOMV39o+SyP+10CV4OCD6B9vzYw0tCTK +zzB1haHF1oHT2ywgtgM6eFeuc1XBbuEGTOToEC8VDuAug38k0ucFWdQHg++qzYnb +K5sKzzl40UDdLDIU1bD3VIkqAufAr886CAvKDzGseA== +=FfqK +-----END PGP MESSAGE----- + +--x2iAciceo0NrKsl4uFVFGTgJ6k0ocg8FW-- + diff --git a/tests/testgnupghome/pubring.gpg b/tests/testgnupghome/pubring.gpg new file mode 100644 index 0000000000000000000000000000000000000000..f455159cf96a1d0addd109dff1961d18d288ae82 GIT binary patch literal 696 zcmbQy%M!ZQLY1f%yvUB?`sgKXh>FO%f5lyy%3u ztxa~D(2AGWUoPAh;90ymo9ER;j|OQ|8M(IBNiQPyX4>gJuxm`da%r1I&Amb+zn?0l zE0VtED9JIcy)I#LV()BDOI_j3i&_ltp19ZU_AtFL%#v@@liz}l#UIZy2r@D-ZZY-D zD^5)=ElO4JPOVhX2u@8dN-Y7i14@%}GK(`(Q#2K9^78ZZQXO*glM{0?@{3FCI(D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<>XAr*8#NprhJ}*oSiNaJF5o_aW7N{NIDFo5GEVs< zb*N(XY$6^4t=AYd$i15hIV}^jqJ%Ns$lixW;b(DHIS#Vq`w>BN@y!4c0RRC21N|BE z-x_|OW2t96&LPN2tlOD97n*EwEb}?c3M2w8o*p?*K7gYc_zRjo_fIP|B_SF27(kVX zfGFBE#5$7|6PSblBb%?w$64p-dYs9sq0p2s}W$iJN8ovB;(JtpcWqUDkWW z`yF~E2kx+#aGK}qS|8EX$s*%_X-xtEz|T|6ZBMj!PwC4O+gN%ojSJ7J5ZQpp!w+`( z9U{#hJxp5aB^V>m0@0YP7VZFEeNmU}_+k2bur|ZTMwST=0s!s>>3hcnJQ+%F$)*w# zUUVJPpCT53TZpTXzSIs#Ld!aKJ4_QxD(*0TY1kWa(R${e`5jw z#)UQN3-oLGd^L15c`$Wr1)W+do%8ZIJV~s1Pv5p^SBHq4JX0S~*pCL7hZ)0I>Xm4|LK8Uyk69EDMA_W3ftvDwF8v_Ol2?z%R0tOWb0tpHW1Qr4V z0RkQY0vCV)3JDO1VH+w!1^wUb+ynrI4FSUKnz)0ssJ= z0oVjptvDwE1OUR9R@3zK4s6iiY#^aBmT@Q>x!ed7cJw5{$n(B&AaoIr8auq+WP{bp z34dfmEIlSdSGDqmni0zIyk2xyd!i?7(12?wEwEu3)AtcETs)72l~sH?!p&PJeQ>kk}9i2H`KJLFP|uX z7;YXnpcaUq1Q-DV00{*GRjoKD0vikf3JDO1VH+w!1^wR#)&u~u`(ci+{f7&xdX)mE z6GOnG0!8jlscX%v9ZtVj3OAj?-L>qf!LT_dXQXddjfL%;V{K!Bz26wCV9ViISMDp4 zO69+uWJ8KAWhUuf3Hi<_VI--zl>l^4g`~qDef4lJj-FQBE9kT2-KBS3((35jDKZOd S0~FONB#}m9OQ0gK0ssJ>CSn=@ literal 0 HcmV?d00001 diff --git a/tests/testgnupghome/trustdb.gpg b/tests/testgnupghome/trustdb.gpg new file mode 100644 index 0000000000000000000000000000000000000000..35137131caa2b5a2968dc6e2f9faf9458a61474e GIT binary patch literal 1280 zcmZQfFGy!*W@Ke#VqgeeYcZbzJ7DC(E{-8Opz7o>oP!}SpzgzP4W_`T`!K@>c_M}!eCgXblV9$txauOkoL;QP7M P_Scbf3!0(o5Xu+;Fi08& literal 0 HcmV?d00001 -- 2.25.1