def setUpClass(cls):
        # Prepare server
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.bind(('127.0.0.1', 12345))
        sock.listen(10)
        cls.server_sock = sock
        th = threading.Thread(target=cls.__server)
        th.setDaemon(True)
        th.start()
        cls.server_thread = th
        cls.server_ready = threading.Event()
        cls.server_end = threading.Event()

        # Prepare BackendConnector
        cfg = GlobalConfigStore()
        cfg.agent_username = "******"
        cfg.agentkey = RSAKey.generate(1024)
        cfg.backend_hostkey = RSAKey.generate(1024)
        cfg.host = "127.0.0.1"
        cfg.port = 12345
        cls.ingress = queue.Queue()
        cls.egress = queue.Queue()
        cls.connector = BackendConnector()
        endpoint = BackendConnector.EndPoint(ingress=cls.ingress,
                egress=cls.egress)
        cls.connector.register(endpoint)
        cls.connector.start()
Beispiel #2
0
def bastio_main():
    """Main application entry point."""
    signal.signal(signal.SIGINT, __sig_handler)
    signal.signal(signal.SIGTERM, __sig_handler)
    cfg = GlobalConfigStore()

    # Parse command line arguments
    cmd = CommandLine()
    command = cmd.parse()

    if command == 'generate-key':
        try:
            key = RSAKey.generate(cfg.bits)
            key.write_private_key_file(cfg.agentkey)
        except Exception as ex:
            _die(ex.message)
        _die("generated {}-bit key successfully".format(cfg.bits), True)
    elif command == 'upload-key':
        try:
            agentkey = RSAKey.from_private_key_file(cfg.agentkey)
        except Exception as ex:
            _die(ex.message)

        try:
            # Replace old key
            if cfg.new_agentkey:
                new_agentkey = RSAKey.from_private_key_file(cfg.new_agentkey)
                upload_public_key(cfg.apikey, new_agentkey.get_public_key(),
                        agentkey.get_public_key())
            else:
                upload_public_key(cfg.apikey, agentkey.get_public_key())
        except Exception as ex:
            _die(ex.message)
        _die("uploaded public key successfully", True)
    elif command == 'start':
        try:
            cfg.agent_username = cfg.apikey
            cfg.agentkey = RSAKey.from_private_key_file(cfg.agentkey)
            cfg.backend_hostkey = download_backend_hostkey()
        except Exception as ex:
            _die(ex.message)

    ### All that is below is part of the ``start`` command

    # Set logging based on debug status
    if cfg.debug:
        Logger().enable_stream()
    else:
        Logger().enable_syslog()

    cfg.threadpool = GlobalThreadPool(cfg.minthreads)
    cfg.processor = Processor()
    cfg.connector = BackendConnector()
    cfg.connector.register(cfg.processor.endpoint())
    cfg.connector.start()
    signal.pause()
 def test_key_generation(self):
     # Test invalid key size
     with self.assertRaises(BastioCryptoError):
         RSAKey.generate(1111)
     self.assertTrue(self.key.get_private_key())
     self.assertTrue(self.key.get_public_key())
 def setUpClass(cls):
     cls.key = RSAKey.generate(1024)
     cls.key_file = 'TEST_PRIVATE_KEY'
     file(cls.key_file, 'wb').write(cls.key.get_private_key())
 def setUpClass(cls):
     cls._public_key = RSAKey.generate(1024).get_public_key()
     cls._proc = Processor()
 def setUpClass(cls):
     cls.pubkey = RSAKey.generate(1024).get_public_key()