- # Startup the replay cache
- ErrType = EX_TEMPFAIL;
- if ReplayCacheFile != None:
- ErrMsg = "Failed to initialize the replay cache:";
- RC = ReplayCache(ReplayCacheFile);
-
- # Get the email
- ErrType = EX_PERMFAIL;
- ErrMsg = "Failed to understand the email or find a signature:";
- email = email.parser.Parser().parse(sys.stdin);
- MsgID = email["Message-ID"]
-
- print "Inspecting message %s"%MsgID;
- verbmsg("Processing message %s" % MsgID)
- Msg = GetClearSig(email,1);
- if AllowMIME == 0 and Msg[1] != 0:
- raise Error, "PGP/MIME disallowed";
-
- ErrMsg = "Message is not PGP signed:"
- if Msg[0].find("-----BEGIN PGP SIGNED MESSAGE-----") == -1:
- raise Error, "No PGP signature";
-
- # Check the signature
- ErrMsg = "Unable to check the signature or the signature was invalid:";
- pgp = GPGCheckSig2(Msg[0])
-
- if not pgp.ok:
- raise UDFormatError, pgp.why
- if pgp.text is None:
- raise UDFormatError, "Null signature text"
-
- # Check the signature against the replay cache
- if ReplayCacheFile != None:
- RC.process(pgp.sig_info)
-
- # Do LDAP stuff
- if LDAPDn != None:
- CheckLDAP(pgp.key_fpr)
-
- ErrMsg = "Verifying message:";
- if Phrases != None:
- F = open(Phrases,"r");
- while 1:
- Line = F.readline();
- if Line == "": break;
- if pgp.text.find(Line.strip()) == -1:
- raise Error,"Phrase '%s' was not found" % (Line.strip())
-
-except:
- ErrMsg = "[%s] \"%s\" \"%s %s\"\n"%(Now,MsgID,ErrMsg,sys.exc_value);
- sys.stderr.write(ErrMsg);
-
- Trace = "==> %s: %s\n" %(sys.exc_type,sys.exc_value);
- List = traceback.extract_tb(sys.exc_traceback);
- if len(List) >= 1:
- Trace = Trace + "Python Stack Trace:\n";
- for x in List:
- Trace = Trace + " %s %s:%u: %s\n" %(x[2],x[0],x[1],x[3]);
- #print Trace;
-
- sys.exit(EX_PERMFAIL);
-
-# For Main
-print "Message %s passed"%MsgID;
-sys.exit(0);
+ # Startup the replay cache
+ ErrType = EX_TEMPFAIL
+ if ReplayCacheFile is not None:
+ ErrMsg = "Failed to initialize the replay cache:"
+ RC = ReplayCache(ReplayCacheFile)
+
+ # Get the email
+ ErrType = EX_PERMFAIL
+ ErrMsg = "Failed to understand the email or find a signature:"
+ mail = email.parser.Parser().parse(sys.stdin)
+ MsgID = mail["Message-ID"]
+
+ print "Inspecting message %s" % MsgID
+ verbmsg("Processing message %s" % MsgID)
+ Msg = GetClearSig(mail, 1)
+ if AllowMIME == 0 and Msg[1] != 0:
+ raise MessageError("PGP/MIME disallowed")
+
+ ErrMsg = "Message is not PGP signed:"
+ if Msg[0].find("-----BEGIN PGP SIGNED MESSAGE-----") == -1:
+ raise MessageError("No PGP signature")
+
+ # Check the signature
+ ErrMsg = "Unable to check the signature or the signature was invalid:"
+ pgp = GPGCheckSig2(Msg[0])
+
+ if not pgp.ok:
+ raise UDFormatError(pgp.why)
+ if pgp.text is None:
+ raise UDFormatError("Null signature text")
+
+ # Check the signature against the replay cache
+ if ReplayCacheFile is not None:
+ RC.process(pgp.sig_info)
+
+ # Do LDAP stuff
+ if LDAPDn is not None:
+ CheckLDAP(pgp.key_fpr)
+
+ ErrMsg = "Verifying message:"
+ if Phrases is not None:
+ F = open(Phrases, "r")
+ while 1:
+ Line = F.readline()
+ if Line == "":
+ break
+ if pgp.text.find(Line.strip()) == -1:
+ raise MessageError("Phrase '%s' was not found" % (Line.strip()))
+
+except Exception:
+ ErrMsg = "[%s] \"%s\" \"%s %s\"\n" % (Now, MsgID, ErrMsg, sys.exc_value)
+ sys.stderr.write(ErrMsg)
+
+ Trace = "==> %s: %s\n" % (sys.exc_type, sys.exc_value)
+ List = traceback.extract_tb(sys.exc_traceback)
+ if len(List) >= 1:
+ Trace = Trace + "Python Stack Trace:\n"
+ for x in List:
+ Trace = Trace + " %s %s:%u: %s\n" % (x[2], x[0], x[1], x[3])
+
+ sys.exit(EX_PERMFAIL)
+
+# For Main
+print "Message %s passed" % MsgID
+sys.exit(0)