From: Ansgar Burchardt Date: Sun, 3 Aug 2014 15:01:00 +0000 (+0200) Subject: daklib/gpg.py: Raise an error if we see unexpected output from gpg. X-Git-Url: https://git.donarmstrong.com/?p=dak.git;a=commitdiff_plain;h=fff9d5d7917923ff2b4b327f5084ffda8096eb62 daklib/gpg.py: Raise an error if we see unexpected output from gpg. --- diff --git a/daklib/gpg.py b/daklib/gpg.py index 9935c6d5..3f96c609 100644 --- a/daklib/gpg.py +++ b/daklib/gpg.py @@ -78,8 +78,11 @@ class SignedFile(object): self.keyrings = keyrings self.valid = False + self.expired = False + self.invalid = False self.fingerprint = None self.primary_fingerprint = None + self.signature_id = None self._verify(data, require_signature) @@ -112,6 +115,9 @@ class SignedFile(object): for line in self.status.splitlines(): self._parse_status(line) + if self.invalid: + self.valid = False + if require_signature and not self.valid: raise GpgException("No valid signature found. (GPG exited with status code %s)\n%s" % (exit_code, self.stderr)) @@ -163,23 +169,43 @@ class SignedFile(object): # # if fields[1] == "VALIDSIG": + if self.fingerprint is not None: + raise GpgException("More than one signature is not (yet) supported.") self.valid = True self.fingerprint = fields[2] self.primary_fingerprint = fields[11] self.signature_timestamp = self._parse_date(fields[3]) - if fields[1] == "BADARMOR": + elif fields[1] == "BADARMOR": raise GpgException("Bad armor.") - if fields[1] == "NODATA": + elif fields[1] == "NODATA": raise GpgException("No data.") - if fields[1] == "DECRYPTION_FAILED": + elif fields[1] == "DECRYPTION_FAILED": raise GpgException("Decryption failed.") - if fields[1] == "ERROR": + elif fields[1] == "ERROR": raise GpgException("Other error: %s %s" % (fields[2], fields[3])) + elif fields[1] == "SIG_ID": + if self.signature_id is not None: + raise GpgException("More than one signature id.") + self.signature_id = fields[2] + + elif fields[1] in ('PLAINTEXT', 'GOODSIG'): + pass + + elif fields[1] in ('EXPSIG', 'EXPKEYSIG'): + self.expired = True + self.invalid = True + + elif fields[1] in ('REVKEYSIG', 'BADSIG', 'ERRSIG'): + self.invalid = True + + else: + raise GpgException("Keyword '{0}' from GnuPG was not expected.".format(fields[1])) + def _exec_gpg(self, stdin, stdout, stderr, statusfd): try: if stdin != 0: