X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=daklib%2Fgpg.py;h=9935c6d554a6eedc0658ed4cc14be1e5c83687ad;hb=47cd096281f1cc36dfe9818ef1fbae8d02f6ada6;hp=62bfe096510453c180acb4fda1f5b80af6581ffa;hpb=438e50fc19e566ea0c986351681d865a36862713;p=dak.git diff --git a/daklib/gpg.py b/daklib/gpg.py index 62bfe096..9935c6d5 100644 --- a/daklib/gpg.py +++ b/daklib/gpg.py @@ -19,6 +19,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +import apt_pkg +import datetime import errno import fcntl import os @@ -68,7 +70,7 @@ class SignedFile(object): def __init__(self, data, keyrings, require_signature=True, gpg="/usr/bin/gpg"): """ @param data: string containing the message - @param keyrings: seqeuence of keyrings + @param keyrings: sequence of keyrings @param require_signature: if True (the default), will raise an exception if no valid signature was found @param gpg: location of the gpg binary """ @@ -141,6 +143,17 @@ class SignedFile(object): return dict( (fd, "".join(read_lines[fd])) for fd in read_lines.keys() ) + def _parse_date(self, value): + """parse date string in YYYY-MM-DD format + + @rtype: L{datetime.datetime} + @returns: datetime objects for 0:00 on the given day + """ + year, month, day = value.split('-') + date = datetime.date(int(year), int(month), int(day)) + time = datetime.time(0, 0) + return datetime.datetime.combine(date, time) + def _parse_status(self, line): fields = line.split() if fields[0] != "[GNUPG:]": @@ -153,6 +166,7 @@ class SignedFile(object): self.valid = True self.fingerprint = fields[2] self.primary_fingerprint = fields[11] + self.signature_timestamp = self._parse_date(fields[3]) if fields[1] == "BADARMOR": raise GpgException("Bad armor.") @@ -181,7 +195,12 @@ class SignedFile(object): fcntl.fcntl(fd, fcntl.F_SETFD, old & ~fcntl.FD_CLOEXEC) os.closerange(4, _MAXFD) - args = [self.gpg, "--status-fd=3", "--no-default-keyring"] + args = [self.gpg, + "--status-fd=3", + "--no-default-keyring", + "--batch", + "--no-tty", + "--trust-model", "always"] for k in self.keyrings: args.append("--keyring=%s" % k) args.extend(["--decrypt", "-"]) @@ -190,4 +209,7 @@ class SignedFile(object): finally: os._exit(1) + def contents_sha1(self): + return apt_pkg.sha1sum(self.contents) + # vim: set sw=4 et: