def __init__(self, address, key_path, server_pub_key, command): self.keyobj = load_key(key_path) logger.debug("client init_box pk: {}".format(self.keyobj.pk)) logger.debug("client init_box sk: {}".format(self.keyobj.sk)) self.command = command PomaresProtocol.route = self.route self.host, self.port = address self.server_pub_key = server_pub_key self.do_handshake_init()
def __init__(self, key_path, address='0.0.0.0', port=8080, admin_sock=admin_sock_file, io_sock=io_sock_file): self.keyobj = load_key(key_path) PomaresProtocol.route = self.route self.loop = asyncio.get_event_loop() self.server = self.loop.create_server(PomaresProtocol, address, port) PomaresAdminProtocol.route = admin.route self.admin_server = self.loop.create_unix_server(PomaresAdminProtocol, path=admin_sock) self.io_server = self.loop.create_unix_server(PomaresIOProtocol, path=io_sock)
def about(): keyobj = crypto.load_key(config.key_file) print('key_file:', config.key_file) print('public_key:', crypto.pubkey_base64(keyobj)) print('public_sum:', crypto.pubkey_sum(keyobj))
def keypairs(dirname): """Lists keypair files in keypath""" for f in os.listdir(config.key_path): keyobj_path = os.path.join(config.key_path, f) keyobj = crypto.load_key(keyobj_path) print('{}: {}'.format(f, crypto.pubkey_base64(keyobj)))
@asyncio.coroutine def send(self, payload): self.writer.write(bytes('{}\n'.format(payload).encode())) yield from self.writer.drain() @asyncio.coroutine def read(self): answer = yield from self.reader.readline() logger.debug('got data: {}'.format(answer)) return answer def run(self): "runs event loop" loop = asyncio.get_event_loop() tasks = asyncio.async(self.talk()) loop.run_until_complete(tasks) loop.close() if __name__ == '__main__': import sys server_pub_key = load_key(key_path+'/local.key').pk my_key = key_path+'/my.key' if len(sys.argv) > 1: command = sys.argv[1] else: command = "default first command message" c = PomaresClient(('127.0.0.1', 8080), my_key, server_pub_key, Ack(command)) c.run()