3
from twisted.internet import protocol
5
import common, userauth, keys, transport, primes, connection
8
class SSHFactory(protocol.Factory):
10
'ssh-userauth':userauth.SSHUserAuthServer,
11
'ssh-connection':connection.SSHConnection
13
def startFactory(self):
14
if not hasattr(self,'publicKeys'):
15
self.publicKeys = self.getPublicKey()
16
if not hasattr(self,'privateKeys'):
17
self.privateKeys = self.getPrivateKey()
18
if not hasattr(self,'primes'):
19
self.primes = self.getPrimes()
21
def buildProtocol(self, addr):
22
t = transport.SSHServerTransport()
23
t.supportedPublicKeys = self.privateKeys.keys()
27
def getFingerprint(self):
28
return ':'.join(map(lambda c:'%02x'%ord(c),md5.new(self.publicKey).digest()))
30
def getDHPrime(self, bits):
32
return primes.getDHPrimeOfBits(self.primes, bits)
34
class OpenSSHFactory(SSHFactory):
35
dataRoot = '/usr/local/etc'
36
def getPublicKey(self):
38
for file in os.listdir(self.dataRoot):
39
if file[:9] == 'ssh_host_' and file[-8:]=='_key.pub':
41
k = keys.getPublicKeyString(self.dataRoot+'/'+file)
42
t = common.getNS(k)[0]
45
print 'bad key file', file
47
def getPrivateKey(self):
49
for file in os.listdir(self.dataRoot):
50
if file[:9] == 'ssh_host_' and file[-4:]=='_key':
52
k = keys.getPrivateKeyObject(self.dataRoot+'/'+file)
53
t = keys.objectType(k)
56
print 'bad key file', file
59
return primes.parseModuliFile(self.dataRoot+'/moduli')