aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2007-12-22 22:52:44 -0800
committerRobin H. Johnson <robbat2@gentoo.org>2007-12-22 22:52:44 -0800
commit76691f813a844e8c18d8de5fd2cc2d0117a9602e (patch)
treefaf5b28af2984305060501f366b2ab1929f732af /gitosis/ssh.py
parentExpand SSH authorized_keys option parsing. (diff)
downloadgitosis-gentoo-76691f813a844e8c18d8de5fd2cc2d0117a9602e.tar.gz
gitosis-gentoo-76691f813a844e8c18d8de5fd2cc2d0117a9602e.tar.bz2
gitosis-gentoo-76691f813a844e8c18d8de5fd2cc2d0117a9602e.zip
Move the SSH username extraction to the ssh class, and the tests over as well.
Diffstat (limited to 'gitosis/ssh.py')
-rw-r--r--gitosis/ssh.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/gitosis/ssh.py b/gitosis/ssh.py
index f552255..10784fa 100644
--- a/gitosis/ssh.py
+++ b/gitosis/ssh.py
@@ -17,6 +17,20 @@ def isSafeUsername(user):
match = _ACCEPTABLE_USER_RE.match(user)
return (match is not None)
+class InsecureSSHKeyUsername(Exception):
+ """Username contains not allowed characters"""
+
+ def __str__(self):
+ return '%s: %s' % (self.__doc__, ': '.join(self.args))
+
+def extract_user(pubkey):
+ """Find the username for a given SSH public key line."""
+ _, user = pubkey.rsplit(None, 1)
+ if isSafeUsername(user):
+ return user
+ else:
+ raise InsecureSSHKeyUsername(repr(user))
+
def readKeys(keydir):
"""
Read SSH public keys from ``keydir/*.pub``