1
from twisted.conch.ssh import keys, factory, common
2
from twisted.python import log
6
class OpenSSHFactory(factory.SSHFactory):
7
dataRoot = '/usr/local/etc'
8
moduliRoot = '/usr/local/etc' # for openbsd which puts moduli in a different
10
def getPublicKeys(self):
12
for file in os.listdir(self.dataRoot):
13
if file[:9] == 'ssh_host_' and file[-8:]=='_key.pub':
15
k = keys.getPublicKeyString(self.dataRoot+'/'+file)
16
t = common.getNS(k)[0]
19
log.msg('bad public key file %s: %s' % (file,e))
21
def getPrivateKeys(self):
23
euid,egid = os.geteuid(), os.getegid()
24
os.setegid(0) # gain priviledges
26
for file in os.listdir(self.dataRoot):
27
if file[:9] == 'ssh_host_' and file[-4:]=='_key':
29
k = keys.getPrivateKeyObject(self.dataRoot+'/'+file)
30
t = keys.objectType(k)
33
log.msg('bad private key file %s: %s' % (file, e))
34
os.setegid(egid) # drop them just as quickily
40
return primes.parseModuliFile(self.moduliRoot+'/moduli')