Initial import to Tizen
[profile/ivi/python-twisted.git] / twisted / plugins / cred_sshkeys.py
1 # -*- test-case-name: twisted.test.test_strcred -*-
2 #
3 # Copyright (c) Twisted Matrix Laboratories.
4 # See LICENSE for details.
5
6 """
7 Cred plugin for ssh key login
8 """
9
10 from zope.interface import implements
11
12 from twisted import plugin
13 from twisted.cred.strcred import ICheckerFactory
14 from twisted.cred.credentials import ISSHPrivateKey
15
16
17 sshKeyCheckerFactoryHelp = """
18 This allows SSH public key authentication, based on public keys listed in
19 authorized_keys and authorized_keys2 files in user .ssh/ directories.
20 """
21
22
23 try:
24     from twisted.conch.checkers import SSHPublicKeyDatabase
25
26     class SSHKeyCheckerFactory(object):
27         """
28         Generates checkers that will authenticate a SSH public key
29         """
30         implements(ICheckerFactory, plugin.IPlugin)
31         authType = 'sshkey'
32         authHelp = sshKeyCheckerFactoryHelp
33         argStringFormat = 'No argstring required.'
34         credentialInterfaces = SSHPublicKeyDatabase.credentialInterfaces
35
36
37         def generateChecker(self, argstring=''):
38             """
39             This checker factory ignores the argument string. Everything
40             needed to authenticate users is pulled out of the public keys
41             listed in user .ssh/ directories.
42             """
43             return SSHPublicKeyDatabase()
44
45
46
47     theSSHKeyCheckerFactory = SSHKeyCheckerFactory()
48
49 except ImportError:
50     # if checkers can't be imported, then there should be no SSH cred plugin
51     pass