From: W. Trevor King Date: Fri, 31 Aug 2012 17:49:29 +0000 (-0400) Subject: pgp: test a Mutt-generated email in pgp.verify. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=13a3246015742ab4771a6578fada25a599b07711;p=pgp-mime.git pgp: test a Mutt-generated email in pgp.verify. This way I'm not just testing against my interpretation of the RFCs, but I'm also testing against the Mutt dev's interpretation. --- diff --git a/pgp_mime/pgp.py b/pgp_mime/pgp.py index 86a73c9..2be55c7 100644 --- a/pgp_mime/pgp.py +++ b/pgp_mime/pgp.py @@ -509,6 +509,85 @@ def verify(message): + + Test a message generated by Mutt (for sanity): + + >>> from email import message_from_bytes + >>> message_bytes = b'\n'.join([ + ... b'Return-Path: ', + ... b'Received: by invalid; Tue, 24 Apr 2012 19:46:59 -0400', + ... b'Date: Tue, 24 Apr 2012 19:46:59 -0400', + ... b'From: pgp-mime-test ', + ... b'MIME-Version: 1.0', + ... b'Content-Type: multipart/signed; micalg=pgp-sha1;', + ... b' protocol="application/pgp-signature";', + ... b' boundary="kORqDWCi7qDJ0mEj"', + ... b'Content-Disposition: inline', + ... b'User-Agent: Mutt/1.5.21 (2010-09-15)', + ... b'Content-Length: 740', + ... b'', + ... b'', + ... b'--kORqDWCi7qDJ0mEj', + ... b'Content-Type: text/plain; charset=us-ascii', + ... b'Content-Disposition: inline', + ... b'', + ... b'ping!', + ... b'', + ... b'--kORqDWCi7qDJ0mEj', + ... b'Content-Type: application/pgp-signature; name="signature.asc"', + ... b'Content-Description: OpenPGP digital signature', + ... b'', + ... b'-----BEGIN PGP SIGNATURE-----', + ... b'Version: GnuPG v2.0.17 (GNU/Linux)', + ... b'', + ... b'iQEcBAEBAgAGBQJPlztxAAoJEFEa7aZDMrbjwT0H/i9eN6CJ2FIinK7Ps04XYEbL', + ... b'PSQV1xCxb+2bk7yA4zQnjAKOPSuMDXfVG669Pbj8yo4DOgUqIgh+lK+voec9uwsJ', + ... b'ZgUJcMozSmEFSTPO+Fiyx0S+NjnaLsas6IQrQTVDc6lWiIZttgxuN0crH5DcLomB', + ... b'Ip90+ELbzVN3yBAjMJ1Y6xnKd7C0IOKm7VunYu9eCzJ/Rik5qZ0+IacQQnnrFJEN', + ... b'04nDvDUzfaKy80Ke7VAQBIRi85XCsM2h0KDXOGUZ0xPQ8L/4eUK9tL6DJaqKqFPl', + ... b'zNiwfpue01o6l6kngrQdXZ3tuv0HbLGc4ACzfz5XuGvE5PYTNEsylKLUMiSCIFc=', + ... b'=xP0S', + ... b'-----END PGP SIGNATURE-----', + ... b'', + ... b'--kORqDWCi7qDJ0mEj--', + ... b'']) + >>> message = message_from_bytes(message_bytes) + >>> decrypted,verified,result = verify(message) + >>> print(decrypted.as_string()) # doctest: +ELLIPSIS, +REPORT_UDIFF + Content-Type: text/plain; charset=us-ascii + Content-Disposition: inline + + ping! + + >>> verified + False + >>> print(str(result, 'utf-8').replace('\x00', '')) + ... # doctest: +REPORT_UDIFF, +ELLIPSIS + + + + + + + B2EDBE0E771A4B8708DD16A7511AEDA64332B6E3 + Success <Unspecified source> + + + + + + + Success <Unspecified source> + RSA + SHA1 + + + + + """ ct = message.get_content_type() if ct == 'multipart/encrypted':