pgp: test a Mutt-generated email in pgp.verify.
authorW. Trevor King <wking@tremily.us>
Fri, 31 Aug 2012 17:49:29 +0000 (13:49 -0400)
committerW. Trevor King <wking@tremily.us>
Fri, 31 Aug 2012 17:49:29 +0000 (13:49 -0400)
This way I'm not just testing against my interpretation of the RFCs,
but I'm also testing against the Mutt dev's interpretation.

pgp_mime/pgp.py

index 86a73c9ba0152422210d4378817547090021bb13..2be55c713b1d3891160f3a40180aa4f3a96724e6 100644 (file)
@@ -509,6 +509,85 @@ def verify(message):
       </verify-result>
     </gpgme>
     <BLANKLINE>
+
+    Test a message generated by Mutt (for sanity):
+
+    >>> from email import message_from_bytes
+    >>> message_bytes = b'\n'.join([
+    ...   b'Return-Path: <pgp-mime@invalid.com>',
+    ...   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 <pgp-mime@invalid.com',
+    ...   b'To: pgp-mime@invalid.com',
+    ...   b'Subject: test',
+    ...   b'Message-ID: <20120424233415.GA27788@invalid>',
+    ...   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
+    <BLANKLINE>
+    ping!
+    <BLANKLINE>
+    >>> verified
+    False
+    >>> print(str(result, 'utf-8').replace('\x00', ''))
+    ... # doctest: +REPORT_UDIFF, +ELLIPSIS
+    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+    <gpgme>
+      <verify-result>
+        <signatures>
+          <signature>
+            <summary value="0x0" />
+            <fpr>B2EDBE0E771A4B8708DD16A7511AEDA64332B6E3</fpr>
+            <status value="0x0">Success &lt;Unspecified source&gt;</status>
+            <timestamp unix="..." />
+            <exp-timestamp unix="0i" />
+            <wrong-key-usage value="0x0" />
+            <pka-trust value="0x0" />
+            <chain-model value="0x0" />
+            <validity value="0x0" />
+            <validity-reason value="0x0">Success &lt;Unspecified source&gt;</validity-reason>
+            <pubkey-algo value="0x1">RSA</pubkey-algo>
+            <hash-algo value="0x2">SHA1</hash-algo>
+          </signature>
+        </signatures>
+      </verify-result>
+    </gpgme>
+    <BLANKLINE>
     """
     ct = message.get_content_type()
     if ct == 'multipart/encrypted':