From a32d1e9834689596abc41653d616728047016a82 Mon Sep 17 00:00:00 2001 From: Narayan Desai Date: Fri, 30 Sep 2005 21:13:49 +0000 Subject: move to out of tree key generation, along with the proper kicking of the state machine (Logical change 1.330) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@1349 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Server/Plugins/SSHbase.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/lib/Server/Plugins/SSHbase.py b/src/lib/Server/Plugins/SSHbase.py index 125e85ad2..c8c5a4544 100644 --- a/src/lib/Server/Plugins/SSHbase.py +++ b/src/lib/Server/Plugins/SSHbase.py @@ -1,11 +1,12 @@ '''This module manages ssh key files for bcfg2''' -__revision__ = '$Revision$' +__revision__ = '$Revision: 1.56 $' from binascii import b2a_base64 from os import rename, system, popen from socket import gethostbyname, gaierror +from time import sleep -from Bcfg2.Server.Plugin import Plugin, DirectoryBacked +from Bcfg2.Server.Plugin import Plugin, DirectoryBacked, PluginExecutionError class SSHbase(Plugin): '''The sshbase generator manages ssh host keys (both v1 and v2) @@ -26,7 +27,7 @@ class SSHbase(Plugin): is regenerated each time a new key is generated. ''' __name__ = 'SSHbase' - __version__ = '$Id$' + __version__ = '$Id: SSHbase.py 1.56 05/09/27 16:06:14-05:00 desai@topaz.mcs.anl.gov $' __author__ = 'bcfg-dev@mcs.anl.gov' pubkeys = ["ssh_host_dsa_key.pub.H_%s", @@ -105,6 +106,10 @@ class SSHbase(Plugin): self.GenerateHostKeys(client) if hasattr(self, 'static_skn'): del self.static_skn + times = 0 + if not self.repository.entries.has_key(filename): + self.LogError("%s still not registered" % filename) + raise PluginExecutionError keydata = self.repository.entries[filename].data perms = '0600' if entry.get('name')[-4:] == '.pub': @@ -128,9 +133,10 @@ class SSHbase(Plugin): if hostkey not in self.repository.entries.keys(): fileloc = "%s/%s" % (self.data, hostkey) - system('ssh-keygen -q -f %s -N "" -t %s -C root@%s < /dev/null' % (fileloc, keytype, client)) - rename("%s.pub"%(fileloc),"%s/" % - (self.data, )+".".join(hostkey.split('.')[:-1]+['pub']+[hostkey.split('.')[-1]])) + publoc = self.data + '/' + ".".join([hostkey.split('.')[0]]+['pub', "H_%s" % client]) + temploc = "/tmp/%s" % hostkey + system('ssh-keygen -q -f %s -N "" -t %s -C root@%s < /dev/null' % (temploc, keytype, client)) + open(fileloc, 'w').write(open(temploc).read()) + open(publoc, 'w').write(open("%s.pub" % temploc).read()) self.repository.AddEntry(hostkey) - self.repository.AddEntry("%s.pub"%(hostkey)) - + self.repository.AddEntry(".".join([hostkey.split('.')[0]]+['pub', "H_%s" % client])) -- cgit v1.2.3-1-g7c22