def check_private(self, passphrase=None): """Check for a private key match""" newkey = read_private_key('new', passphrase) self.assertEqual(newkey, self.privkey) self.assertEqual(hash(newkey), hash(self.privkey)) if passphrase: with self.assertRaises((KeyEncryptionError, KeyImportError)): read_private_key('new', 'xxx') else: run('cat new new > list') keylist = read_private_key_list('list', passphrase) self.assertEqual(keylist[0], newkey) self.assertEqual(keylist[1], newkey)
def __call__(self): database = Service.resolve("moxie.cores.database.DatabaseService") # self.alert = CronService.resolve("moxie.cores.alert.AlertService") # register an ssh callback for each thinger ssh_host_keys = asyncssh.read_private_key_list('ssh_host_keys') if MoxieSSHServer._keys is None: authorized_keys = {} for key in asyncssh.read_public_key_list('authorized_keys'): authorized_keys[key] = (yield from database.user.get_by_fingerprint( fingerprint(key))) MoxieSSHServer._keys = authorized_keys obj = yield from asyncssh.create_server(MoxieSSHServer, '0.0.0.0', 2222, server_host_keys=ssh_host_keys) return obj
def __call__(self): database = Service.resolve("moxie.cores.database.DatabaseService") # self.alert = CronService.resolve("moxie.cores.alert.AlertService") # register an ssh callback for each thinger ssh_host_keys = asyncssh.read_private_key_list('ssh_host_keys') if MoxieSSHServer._keys is None: authorized_keys = {} for key in asyncssh.read_public_key_list('authorized_keys'): authorized_keys[key] = (yield from database.user.get_by_fingerprint( fingerprint(key))) MoxieSSHServer._keys = authorized_keys obj = yield from asyncssh.create_server( MoxieSSHServer, '0.0.0.0', 2222, server_host_keys=ssh_host_keys ) return obj
# All rights reserved. # # This program and the accompanying materials are made available under # the terms of the Eclipse Public License v1.0 which accompanies this # distribution and is available at: # # http://www.eclipse.org/legal/epl-v10.html # # Contributors: # Ron Frederick - initial implementation, API, and documentation import asyncio, asyncssh, sys # To run this program, the file ssh_host_keys must exist with at least # one SSH private key to use as a server host key in it host_keys = asyncssh.read_private_key_list('ssh_host_keys') class MySSHServer(asyncssh.SSHServer): def begin_auth(self, username): # No auth in this example return False def server_requested(self, listen_host, listen_port): return listen_port == 8080 @asyncio.coroutine def start_server(): yield from asyncssh.create_server(MySSHServer, '', 8022, server_host_keys=host_keys) loop = asyncio.get_event_loop()