~free.ekanayaka/landscape-client/karmic-1.5.4-0ubuntu0.9.10.0

« back to all changes in this revision

Viewing changes to landscape/lib/gpg.py

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2009-12-16 10:50:05 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20091216105005-bmki8i2of1dmcdkc
Tags: 1.4.0-0ubuntu0.9.10.0
* New upstream release (LP: #497351)

* Bug fixes:
  - Fix landscape daemons fail to start when too many groups are
    available (LP: #456124)
  - Fix landscape programs wake up far too much. (LP: #340843)
  - Fix Package manager fails with 'no such table: task' (LP #465846)
  - Fix test suite leaving temporary files around (LP #476418)
  - Fix the 1hr long wait for user data to be uploaded following a
    resynchronisation (LP #369000)

* Add support for Ubuntu release upgrades:
  - Add helper function to fetch many files at once (LP: #450629)
  - Handle release-upgrade messages in the packagemanager
    plugin (LP: #455217)
  - Add a release-upgrader task handler (LP: #462543)
  - Support upgrade-tool environment variables (LP: #463321)

* Add initial support for Smart package locking:
  - Detect and report changes about Smart package locks (#488108)

* Packaging fixes:
  - Turn unnecessary Pre-Depends on python-gobject into a regular Depends
  - If it's empty, remove /etc/landscape upon purge

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import shutil
 
2
import tempfile
 
3
 
 
4
from twisted.internet.utils import getProcessOutputAndValue
 
5
 
 
6
 
 
7
class InvalidGPGSignature(Exception):
 
8
    """Raised when the gpg signature for a given file is invalid."""
 
9
 
 
10
 
 
11
def gpg_verify(filename, signature, gpg="/usr/bin/gpg"):
 
12
    """Verify the GPG signature of a file.
 
13
 
 
14
    @param filename: Path to the file to verify the signature against.
 
15
    @param signature: Path to signature to use.
 
16
    @param gpg: Optionally, path to the GPG binary to use.
 
17
    @return: a C{Deferred} resulting in C{True} if the signature is
 
18
            valid, C{False} otherwise.
 
19
        """
 
20
 
 
21
    def remove_gpg_home(ignored):
 
22
        shutil.rmtree(gpg_home)
 
23
        return ignored
 
24
 
 
25
    def check_gpg_exit_code((out, err, code)):
 
26
        if code != 0:
 
27
            raise InvalidGPGSignature("%s failed (out='%s', err='%s', "
 
28
                                      "code='%d')" % (gpg, out, err, code))
 
29
 
 
30
    gpg_home = tempfile.mkdtemp()
 
31
    args = ("--no-options", "--homedir", gpg_home, "--no-default-keyring",
 
32
            "--ignore-time-conflict", "--keyring", "/etc/apt/trusted.gpg",
 
33
            "--verify", signature, filename)
 
34
 
 
35
    result = getProcessOutputAndValue(gpg, args=args)
 
36
    result.addBoth(remove_gpg_home)
 
37
    result.addCallback(check_gpg_exit_code)
 
38
    return result