diff options
| author | Michael Vogt <mvo@debian.org> | 2013-12-31 23:25:13 +0100 |
|---|---|---|
| committer | Michael Vogt <mvo@debian.org> | 2014-01-05 20:04:30 +0100 |
| commit | 3bf9c3fe4d19ed4d985dc8b7747a737699f46a7e (patch) | |
| tree | 75ad948c351605fd7ac50b176f1149c4e2a513e4 /apt/auth.py | |
| parent | e3c26754af1891d2c50993730467fc9335ec5f09 (diff) | |
| download | python-apt-3bf9c3fe4d19ed4d985dc8b7747a737699f46a7e.tar.gz | |
make test_pep8.py pass
Diffstat (limited to 'apt/auth.py')
| -rw-r--r-- | apt/auth.py | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/apt/auth.py b/apt/auth.py index d5a66b4a..acc612a9 100644 --- a/apt/auth.py +++ b/apt/auth.py @@ -67,7 +67,8 @@ def _call_apt_key_script(*args, **kwargs): # configuration from the chroot to the apt-key script by using # a temporary APT_CONFIG file. The apt-key script uses apt-config # shell internally - conf = tempfile.NamedTemporaryFile(prefix="apt-key", suffix=".conf") + conf = tempfile.NamedTemporaryFile( + prefix="apt-key", suffix=".conf") conf.write(apt_pkg.config.dump().encode("UTF-8")) conf.flush() env["APT_CONFIG"] = conf.name @@ -84,11 +85,12 @@ def _call_apt_key_script(*args, **kwargs): output, stderr = proc.communicate(content) if proc.returncode: - raise AptKeyError("The apt-key script failed with return code %s:\n" - "%s\n" - "stdout: %s\n" - "stderr: %s" % (proc.returncode, " ".join(cmd), - output,stderr)) + raise AptKeyError( + "The apt-key script failed with return code %s:\n" + "%s\n" + "stdout: %s\n" + "stderr: %s" % ( + proc.returncode, " ".join(cmd), output, stderr)) elif stderr: sys.stderr.write(stderr) # Forward stderr @@ -97,6 +99,7 @@ def _call_apt_key_script(*args, **kwargs): if conf is not None: conf.close() + def add_key_from_file(filename): """Import a GnuPG key file to trust repositores signed by it. @@ -109,6 +112,7 @@ def add_key_from_file(filename): raise AptKeyError("Key file cannot be accessed: %s" % filename) _call_apt_key_script("add", filename) + def add_key_from_keyserver(keyid, keyserver): """Import a GnuPG key file to trust repositores signed by it. @@ -125,8 +129,9 @@ def add_key_from_keyserver(keyid, keyserver): finally: shutil.rmtree(tmp_keyring_dir) + def _add_key_from_keyserver(keyid, keyserver, tmp_keyring_dir): - if len(keyid) < 160/8: + if len(keyid) < (160 / 8): raise AptKeyError("Only long keyids (v4, 160bit) are supported") # create a temp keyring dir tmp_secret_keyring = os.path.join(tmp_keyring_dir, "secring.gpg") @@ -136,14 +141,14 @@ def _add_key_from_keyserver(keyid, keyserver, tmp_keyring_dir): "gpg", "--no-default-keyring", "--no-options", "--homedir", tmp_keyring_dir, - ] + ] # download the key to a temp keyring first res = subprocess.call(gpg_default_options + [ "--secret-keyring", tmp_secret_keyring, "--keyring", tmp_keyring, "--keyserver", keyserver, "--recv", keyid, - ]) + ]) if res != 0: raise AptKeyError("recv from '%s' failed for '%s'" % ( keyserver, keyid)) @@ -154,7 +159,7 @@ def _add_key_from_keyserver(keyid, keyserver, tmp_keyring_dir): "--keyring", tmp_keyring, "--output", tmp_export_keyring, "--export", keyid, - ]) + ]) if res != 0: raise AptKeyError("export of '%s' failed", keyid) # now verify the fingerprint, this is probably redundant as we @@ -166,10 +171,10 @@ def _add_key_from_keyserver(keyid, keyserver, tmp_keyring_dir): "--fingerprint", "--batch", "--with-colons", - ], - stdout=subprocess.PIPE, - universal_newlines=True).communicate()[0] - got_fingerprint=None + ], + stdout=subprocess.PIPE, + universal_newlines=True).communicate()[0] + got_fingerprint = None for line in output.splitlines(): if line.startswith("fpr:"): got_fingerprint = line.split(":")[9] @@ -185,6 +190,7 @@ def _add_key_from_keyserver(keyid, keyserver, tmp_keyring_dir): # finally add it add_key_from_file(tmp_export_keyring) + def add_key(content): """Import a GnuPG key to trust repositores signed by it. @@ -194,6 +200,7 @@ def add_key(content): _call_apt_key_script("adv", "--quiet", "--batch", "--import", "-", stdin=content) + def remove_key(fingerprint): """Remove a GnuPG key to no longer trust repositores signed by it. @@ -202,6 +209,7 @@ def remove_key(fingerprint): """ _call_apt_key_script("rm", fingerprint) + def export_key(fingerprint): """Return the GnuPG key in text format. @@ -210,6 +218,7 @@ def export_key(fingerprint): """ return _call_apt_key_script("export", fingerprint) + def update(): """Update the local keyring with the archive keyring and remove from the local keyring the archive keys which are no longer valid. The @@ -218,6 +227,7 @@ def update(): """ return _call_apt_key_script("update") + def net_update(): """Work similar to the update command above, but get the archive keyring from an URI instead and validate it against a master key. @@ -228,6 +238,7 @@ def net_update(): """ return _call_apt_key_script("net-update") + def list_keys(): """Returns a list of TrustedKey instances for each key which is used to trust repositories. |
