aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2013-08-22 14:16:55 +0200
committerMichał Górny <mgorny@gentoo.org>2013-08-25 22:45:10 +0200
commitc8c41f930089a519fb2c53a3efb6a37801719a3d (patch)
treeb06cfd41aad245a5c777f6673df28b8b0261a63f /okupy/accounts/ssh.py
parentReset RNG in @postfork. (diff)
downloadidentity.gentoo.org-c8c41f930089a519fb2c53a3efb6a37801719a3d.tar.gz
identity.gentoo.org-c8c41f930089a519fb2c53a3efb6a37801719a3d.tar.bz2
identity.gentoo.org-c8c41f930089a519fb2c53a3efb6a37801719a3d.zip
Support authentication using SSH.
Diffstat (limited to 'okupy/accounts/ssh.py')
-rw-r--r--okupy/accounts/ssh.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/okupy/accounts/ssh.py b/okupy/accounts/ssh.py
index 83d1f10..37ec5c1 100644
--- a/okupy/accounts/ssh.py
+++ b/okupy/accounts/ssh.py
@@ -1,8 +1,34 @@
# vim:fileencoding=utf8:et:ts=4:sts=4:sw=4:ft=python
+from django.contrib.auth import authenticate, login
+
+from ..common.test_helpers import set_request
+from ..crypto.ciphers import sessionrefcipher
+from ..otp import init_otp
+
+
ssh_handlers = {}
def ssh_handler(f):
ssh_handlers[f.__name__] = f
return f
+
+
+@ssh_handler
+def auth(session_id, key):
+ try:
+ session = sessionrefcipher.decrypt(session_id)
+ except ValueError:
+ return None
+
+ request = set_request('/')
+
+ user = authenticate(ssh_key=key)
+ if user and user.is_active:
+ login(request, user)
+ init_otp(request)
+ session.update(request.session)
+ session.save()
+ return 'Authenticated.'
+ return None