envelope: test first for old style PGP, as this kind of message also contains 'BEGIN PGP SIGNATURE' matched earlier instead

This commit is contained in:
nemunaire 2018-03-18 14:06:32 +01:00
parent 64be054961
commit 4df7393069

View File

@ -74,7 +74,16 @@ def check(msg, GNUPG_DIRECTORY, accept_public_key=True, beta=False):
# Looking for signed content
for part in msg.walk():
payload = part.get_payload()
if part.get_content_type() == "application/pgp-signature" or (
if payload is not None and not part.is_multipart() and part.get_payload(decode=True).find(b"-----BEGIN PGP SIGNED MESSAGE-----") >= 0:
res = re.match(".*(-----BEGIN PGP SIGNED MESSAGE-----(.*)-----BEGIN PGP SIGNATURE-----(.*)-----END PGP SIGNATURE-----).*", payload, re.DOTALL)
if res is not None:
yield from assume_oldstyle(payload)
else:
res = re.match(b".*(-----BEGIN PGP SIGNED MESSAGE-----(.*)-----BEGIN PGP SIGNATURE-----(.*)-----END PGP SIGNATURE-----).*", part.get_payload(decode=True), re.DOTALL)
if res is not None:
yield from assume_oldstyle(part.get_payload(decode=True))
elif part.get_content_type() == "application/pgp-signature" or (
payload is not None and not part.is_multipart() and part.get_payload(decode=True).find(b"-----BEGIN PGP SIGNATURE-----") >= 0
):
if part.get_content_type() != "application/pgp-signature":
@ -91,12 +100,3 @@ def check(msg, GNUPG_DIRECTORY, accept_public_key=True, beta=False):
yield MailTest("Public key file discovered, but content-type mismatched: got %s instead of application/pgp-keys." % part.get_content_type(), 2)
yield from import_pubkey(part.get_payload(decode=True), GNUPG_DIRECTORY)
return
elif payload is not None and not part.is_multipart() and part.get_payload(decode=True).find(b"-----BEGIN PGP SIGNED MESSAGE-----") >= 0:
res = re.match(".*(-----BEGIN PGP SIGNED MESSAGE-----(.*)-----BEGIN PGP SIGNATURE-----(.*)-----END PGP SIGNATURE-----).*", payload, re.DOTALL)
if res is not None:
yield from assume_oldstyle(payload)
else:
res = re.match(b".*(-----BEGIN PGP SIGNED MESSAGE-----(.*)-----BEGIN PGP SIGNATURE-----(.*)-----END PGP SIGNATURE-----).*", part.get_payload(decode=True), re.DOTALL)
if res is not None:
yield from assume_oldstyle(part.get_payload(decode=True))