X-Git-Url: https://git.adam-barratt.org.uk/?p=mirror%2Fuserdir-ldap.git;a=blobdiff_plain;f=userdir_gpg.py;fp=userdir_gpg.py;h=da8abfc72374797e580bd163a76491426f91548d;hp=1b9732cc8da57fbc339cc3950db102fc73079e30;hb=4761f401f838a00cba01172eeb7183c5b7777b0f;hpb=6ee830ff583d3db2afa0044a378b1737853e54b0 diff --git a/userdir_gpg.py b/userdir_gpg.py index 1b9732c..da8abfc 100644 --- a/userdir_gpg.py +++ b/userdir_gpg.py @@ -26,44 +26,53 @@ # packets so I can tell if a signature is made by pgp2 to enable the # pgp2 encrypting mode. -import sys, StringIO, os, tempfile, re; -import time, fcntl, anydbm -import email, email.message +import sys +import StringIO +import os +import tempfile +import re +import time +import fcntl +import anydbm +import email +import email.message from userdir_exceptions import * # General GPG options GPGPath = "gpg" -# "--load-extension","rsa", -GPGBasicOptions = [ - "--no-options", - "--batch", - "--no-default-keyring", - "--secret-keyring", "/dev/null", - "--always-trust"]; -GPGKeyRings = []; -GPGSigOptions = ["--output","-"]; -GPGSearchOptions = ["--dry-run","--with-colons","--fingerprint",\ - "--fingerprint", "--fixed-list-mode"]; -GPGEncryptOptions = ["--output","-","--quiet","--always-trust",\ - "--armor","--encrypt"]; -GPGEncryptPGP2Options = ["--set-filename","","--rfc1991",\ - "--load-extension","idea",\ - "--cipher-algo","idea"] + GPGEncryptOptions; +# "--load-extension", "rsa", +GPGBasicOptions = ["--no-options", + "--batch", + "--no-default-keyring", + "--secret-keyring", "/dev/null", + "--always-trust"] +GPGKeyRings = [] +GPGSigOptions = ["--output", "-"] +GPGSearchOptions = ["--dry-run", "--with-colons", "--fingerprint", + "--fingerprint", "--fixed-list-mode"] +GPGEncryptOptions = ["--output", "-", "--quiet", "--always-trust", + "--armor", "--encrypt"] +GPGEncryptPGP2Options = ["--set-filename", "", "--rfc1991", + "--load-extension", "idea", + "--cipher-algo", "idea"] + GPGEncryptOptions # Replay cutoff times in seconds -CleanCutOff = 7*24*60*60; -AgeCutOff = 4*24*60*60; -FutureCutOff = 3*24*60*60; +CleanCutOff = 7 * 24 * 60 * 60 +AgeCutOff = 4 * 24 * 60 * 60 +FutureCutOff = 3 * 24 * 60 * 60 + def ClearKeyrings(): del GPGKeyRings[:] + # Set the keyrings, the input is a list of keyrings def SetKeyrings(Rings): for x in Rings: - GPGKeyRings.append("--keyring"); - GPGKeyRings.append(x); + GPGKeyRings.append("--keyring") + GPGKeyRings.append(x) + # GetClearSig takes an un-seekable email message stream (mimetools.Message) # and returns a standard PGP '---BEGIN PGP SIGNED MESSAGE---' bounded @@ -81,7 +90,7 @@ def SetKeyrings(Rings): # # lax_multipart: treat multipart bodies other than multipart/signed # as one big plain text body -def GetClearSig(Msg, Paranoid = 0, lax_multipart = False): +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" @@ -602,10 +611,10 @@ class ReplayCache: def process(self, sig_info): r = self.Check(sig_info); - if r != None: - raise RuntimeError, "The replay cache rejected your message: %s."%(r); - self.Add(sig_info); - self.close(); + if r is not None: + raise RuntimeError, "The replay cache rejected your message: %s." % (r,) + self.Add(sig_info) + self.close() # vim:set et: # vim:set ts=3: