summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2012-10-01 13:56:32 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2012-10-01 13:56:32 +0200
commit06f7a9c25dff9dc6d5da1ecdfa0ab59d2cb0c3ab (patch)
tree7a161ec375909cba28cd77994f4df1f56efad463
parentd3d4d322614a44cf84a6f2b40bc21d09bbfb2405 (diff)
downloadpython-apt-06f7a9c25dff9dc6d5da1ecdfa0ab59d2cb0c3ab.tar.gz
support only downloading long keyids (160bit) in add_key_from_keyserver()
-rw-r--r--apt/auth.py12
-rw-r--r--tests/test_auth.py3
2 files changed, 11 insertions, 4 deletions
diff --git a/apt/auth.py b/apt/auth.py
index e088ae85..b523d36f 100644
--- a/apt/auth.py
+++ b/apt/auth.py
@@ -35,6 +35,10 @@ import apt_pkg
from apt_pkg import gettext as _
+class AptKeyError(Exception):
+ pass
+
+
class TrustedKey(object):
"""Represents a trusted key."""
@@ -79,7 +83,7 @@ def _call_apt_key_script(*args, **kwargs):
output, stderr = proc.communicate(content)
if proc.returncode:
- raise SystemError("The apt-key script failed with return code %s:\n"
+ raise AptKeyError("The apt-key script failed with return code %s:\n"
"%s\n"
"stdout: %s\n"
"stderr: %s" % (proc.returncode, " ".join(cmd),
@@ -99,9 +103,9 @@ def add_key_from_file(filename):
filename -- the absolute path to the public GnuPG key file
"""
if not os.path.abspath(filename):
- raise SystemError("An absolute path is required: %s" % filename)
+ raise AptKeyError("An absolute path is required: %s" % filename)
if not os.access(filename, os.R_OK):
- raise SystemError("Key file cannot be accessed: %s" % filename)
+ raise AptKeyError("Key file cannot be accessed: %s" % filename)
_call_apt_key_script("add", filename)
def add_key_from_keyserver(keyid, keyserver):
@@ -111,6 +115,8 @@ def add_key_from_keyserver(keyid, keyserver):
keyid -- the identifier of the key, e.g. 0x0EB12DSA
keyserver -- the URL or hostname of the key server
"""
+ if len(keyid) < 160/8:
+ raise AptKeyError("Only v4 keyids (160bit) are supported")
_call_apt_key_script("adv", "--quiet", "--keyserver", keyserver,
"--recv", keyid)
diff --git a/tests/test_auth.py b/tests/test_auth.py
index 99c40db5..7c43d473 100644
--- a/tests/test_auth.py
+++ b/tests/test_auth.py
@@ -190,7 +190,8 @@ class TestAuthKeys(unittest.TestCase):
self._start_keyserver()
self.addCleanup(self._stop_keyserver)
- apt.auth.add_key_from_keyserver("46925553", "hkp://localhost:19191")
+ apt.auth.add_key_from_keyserver(
+ "A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553", "hkp://localhost:19191")
ret = apt.auth.list_keys()
self.assertEqual(len(ret), 1)