示例#1
0
class SspkdPull(object):
    def __init__(self):
        self.cf = SspkdConfig()
        self.util = SspkdUtil()

    def _pull(self):
        if self.cf.server.enabled:
            with open(self.cf.server.database, "r") as f:
                return f.read()

        cmdline = [ 
            'ssh', '-o IdentityFile=%s' % self.cf.client.pushkey, 
            '-o IdentitiesOnly=yes',
            self.cf.client.keyserver, 'fetch'
        ]
        
        ssh = subprocess.Popen(cmdline, stdin=subprocess.PIPE, 
                               stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        
        out, err = ssh.communicate()
        return out
    
    def pull(self, install=False, verify=True):
        signed_keys = self._pull()

        if verify:
            sshkeys = self.util.verify_keys(signed_keys)

            if install:
                self.util.install_keys(sshkeys)
        else:
            sshkeys = signed_keys

        return sshkeys
示例#2
0
文件: push.py 项目: kmdm/sspkd
class SspkdPush(object):
    def __init__(self):
        self.cf = SspkdConfig()
        self.util = SspkdUtil()

    def _push(self, server, sshkeys, relay=False):
        print "pushing updated ssh public keys to %s%s..." % (server, " (relay)" if relay else "")

        # FIXME: Assume server installpath == client installpath
        cmdline = ["ssh", "-o IdentityFile=%s" % self.cf.client.pushkey, "-o IdentitiesOnly=yes", server, "receive"]

        ssh = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

        out, err = ssh.communicate(input=sshkeys)
        print out

    def push(self, sshkeys, sign=True, relay=False):
        if sign:
            sshkeys = self.util.sign_keys(sshkeys)

        if relay:
            servers = self.cf.server.pushto
        else:
            servers = [self.cf.client.keyserver]

        for server in servers:
            if server:
                self._push(server, sshkeys, relay=relay)
示例#3
0
文件: receive.py 项目: kmdm/sspkd
class SspkdReceive:
    def __init__(self):
        self.cf = SspkdConfig()
        self.util = SspkdUtil()

    def receive(self, signed_keys):
        sshkeys = self.util.verify_keys(signed_keys)
        
        if self.cf.server.enabled:
            f = open(self.cf.server.database, "w")
            f.write(signed_keys)
            f.close()
            
            SspkdPush().push(signed_keys, sign=False, relay=True)
            
            if self.cf.server.onlystore:
                return
        
        self.util.install_keys(sshkeys)
示例#4
0
class SspkdReceive:
    def __init__(self):
        self.cf = SspkdConfig()
        self.util = SspkdUtil()

    def receive(self, signed_keys):
        sshkeys = self.util.verify_keys(signed_keys)

        if self.cf.server.enabled:
            f = open(self.cf.server.database, "w")
            f.write(signed_keys)
            f.close()

            SspkdPush().push(signed_keys, sign=False, relay=True)

            if self.cf.server.onlystore:
                return

        self.util.install_keys(sshkeys)
示例#5
0
class SspkdPush(object):
    def __init__(self):
        self.cf = SspkdConfig()
        self.util = SspkdUtil()

    def _push(self, server, sshkeys, relay=False):
        print "pushing updated ssh public keys to %s%s..." % (
            server, " (relay)" if relay else "")

        # FIXME: Assume server installpath == client installpath
        cmdline = [
            'ssh',
            '-o IdentityFile=%s' % self.cf.client.pushkey,
            '-o IdentitiesOnly=yes', server, 'receive'
        ]

        ssh = subprocess.Popen(cmdline,
                               stdin=subprocess.PIPE,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)

        out, err = ssh.communicate(input=sshkeys)
        print out

    def push(self, sshkeys, sign=True, relay=False):
        if sign:
            sshkeys = self.util.sign_keys(sshkeys)

        if relay:
            servers = self.cf.server.pushto
        else:
            servers = [self.cf.client.keyserver]

        for server in servers:
            if server:
                self._push(server, sshkeys, relay=relay)
示例#6
0
 def __init__(self):
     self.cf = SspkdConfig()
     self.util = SspkdUtil()