X-Git-Url: https://git.adam-barratt.org.uk/?p=mirror%2Fuserdir-ldap.git;a=blobdiff_plain;f=userdir_gpg.py;h=d89b78eaa8caef834251359cca13929026afb8fc;hp=a6bfa550b1ae1de1802d184a94e0fdb72442038b;hb=b22af6dffb85542441935a2c117105b38f0b53b5;hpb=a4df7e3989cce6bdc8e30badc53e88ccb59cb429 diff --git a/userdir_gpg.py b/userdir_gpg.py index a6bfa55..d89b78e 100644 --- a/userdir_gpg.py +++ b/userdir_gpg.py @@ -77,13 +77,23 @@ def SetKeyrings(Rings): # # Paranoid will check the message text to make sure that all the plaintext is # in fact signed (bounded by a PGP packet) -def GetClearSig(Msg,Paranoid = 0): +# +# lax_multipart: treat multipart bodies other than multipart/signed +# as one big plain text body +def GetClearSig(Msg, Paranoid = 0, lax_multipart = False): if not Msg.__class__ == email.message.Message: raise RuntimeError, "GetClearSign() not called with a email.message.Message" + if Paranoid and lax_multipart: + raise RuntimeError, "Paranoid and lax_multipart don't mix well" + # See if this is a MIME encoded multipart signed message if Msg.is_multipart(): if not Msg.get_content_type() == "multipart/signed": + if lax_multipart: + payloads = Msg.get_payload() + msg = "\n".join(map( lambda p: p.get_payload(decode=True), payloads)) + return (msg, 0) raise UDFormatError, "Cannot handle multipart messages not of type multipart/signed"; if Paranoid: @@ -98,10 +108,10 @@ def GetClearSig(Msg,Paranoid = 0): (Signed, Signature) = payloads - if Signed.get_content_type() != "text/plain": - raise UDFormatError, "Invalid pgp/mime encoding [wrong plaintext type]"; + if Signed.get_content_type() != "text/plain" and not lax_multipart: + raise UDFormatError, "Invalid pgp/mime encoding for first part[wrong plaintext type]"; if Signature.get_content_type() != "application/pgp-signature": - raise UDFormatError, "Invalid pgp/mime encoding [wrong signature type]"; + raise UDFormatError, "Invalid pgp/mime encoding for second part [wrong signature type]"; # Append the PGP boundary header and the signature text to re-form the # original signed block [needs to convert to \r\n]