Example #1
0
    def _configure_backend(self) -> Union[Any, FileKeyring]:
        from chia.util.keychain import supports_keyring_passphrase

        if self.keyring:
            raise Exception("KeyringWrapper has already been instantiated")

        if platform == "win32" or platform == "cygwin":
            import keyring.backends.Windows

            keyring.set_keyring(keyring.backends.Windows.WinVaultKeyring())
        elif platform == "darwin":
            import keyring.backends.macOS

            keyring.set_keyring(keyring.backends.macOS.Keyring())
            # TODO: New keyring + passphrase support can be enabled for macOS by updating
            # supports_keyring_passphrase() and uncommenting the lines below. Leaving the
            # lines below in place for testing.
            #
            # if supports_keyring_passphrase():
            #     keyring = FileKeyring(keys_root_path=self.keys_root_path)  # type: ignore
            # else:
            #     keyring.set_keyring(keyring.backends.macOS.Keyring())
        elif platform == "linux":
            if supports_keyring_passphrase():
                keyring = FileKeyring(
                    keys_root_path=self.keys_root_path)  # type: ignore
            else:
                keyring = CryptFileKeyring()
                keyring.keyring_key = "your keyring password"  # type: ignore
        else:
            keyring = keyring_main

        return keyring
Example #2
0
 async def keyring_status(self) -> Dict[str, Any]:
     passphrase_support_enabled: bool = supports_keyring_passphrase()
     user_passphrase_is_set: bool = not using_default_passphrase()
     locked: bool = Keychain.is_keyring_locked()
     needs_migration: bool = Keychain.needs_migration()
     response: Dict[str, Any] = {
         "success": True,
         "is_keyring_locked": locked,
         "passphrase_support_enabled": passphrase_support_enabled,
         "user_passphrase_is_set": user_passphrase_is_set,
         "needs_migration": needs_migration,
     }
     return response
 def __init__(
     self,
     log: logging.Logger,
     uri: str = None,
     ssl_context: Optional[ssl.SSLContext] = None,
     local_keychain: Optional[Keychain] = None,
     user: str = None,
     testing: bool = False,
 ):
     self.log = log
     if local_keychain:
         self.keychain = local_keychain
     elif not supports_keyring_passphrase():
         self.keychain = Keychain()  # Proxy locally, don't use RPC
     else:
         self.keychain = None  # type: ignore
     self.keychain_user = user
     self.keychain_testing = testing
     super().__init__(uri or "", ssl_context)
Example #4
0
    def _configure_backend(self) -> Union[LegacyKeyring, FileKeyring]:
        from chia.util.keychain import supports_keyring_passphrase

        keyring: Union[LegacyKeyring, FileKeyring]

        if self.keyring:
            raise Exception("KeyringWrapper has already been instantiated")

        if supports_keyring_passphrase():
            keyring = FileKeyring(keys_root_path=self.keys_root_path)
        else:
            legacy_keyring: Optional[
                LegacyKeyring] = get_legacy_keyring_instance()
            if legacy_keyring is None:
                legacy_keyring = keyring_main
            else:
                keyring_main.set_keyring(legacy_keyring)
            keyring = legacy_keyring

        return keyring
Example #5
0
      https://github.com/Chia-Network/chia-blockchain/wiki/Farming-on-many-machines
    """
    from pathlib import Path
    from .init_funcs import init
    from chia.cmds.passphrase_funcs import initialize_passphrase

    set_passphrase = kwargs.get("set_passphrase")
    if set_passphrase:
        initialize_passphrase()

    init(
        Path(create_certs) if create_certs is not None else None,
        ctx.obj["root_path"],
        fix_ssl_permissions,
        testnet,
        v1_db,
    )


if not supports_keyring_passphrase():
    from chia.cmds.passphrase_funcs import remove_passphrase_options_from_cmd

    # TODO: Remove once keyring passphrase management is rolled out to all platforms
    remove_passphrase_options_from_cmd(init_cmd)

if __name__ == "__main__":
    from .init_funcs import chia_init
    from chia.util.default_root import DEFAULT_ROOT_PATH

    chia_init(DEFAULT_ROOT_PATH)
Example #6
0
    async def handle_message(
        self, websocket: WebSocketServerProtocol, message: WsRpcMessage
    ) -> Tuple[Optional[str], List[Any]]:
        """
        This function gets called when new message is received via websocket.
        """

        command = message["command"]
        destination = message["destination"]
        if destination != "daemon":
            destination = message["destination"]
            if destination in self.connections:
                sockets = self.connections[destination]
                return dict_to_json_str(message), sockets

            return None, []

        data = message["data"]
        commands_with_data = [
            "start_service",
            "start_plotting",
            "stop_plotting",
            "stop_service",
            "is_running",
            "register_service",
        ]
        if len(data) == 0 and command in commands_with_data:
            response = {"success": False, "error": f'{command} requires "data"'}
        # Keychain commands should be handled by KeychainServer
        elif command in keychain_commands and supports_keyring_passphrase():
            response = await self.keychain_server.handle_command(command, data)
        elif command == "ping":
            response = await ping()
        elif command == "start_service":
            response = await self.start_service(cast(Dict[str, Any], data))
        elif command == "start_plotting":
            response = await self.start_plotting(cast(Dict[str, Any], data))
        elif command == "stop_plotting":
            response = await self.stop_plotting(cast(Dict[str, Any], data))
        elif command == "stop_service":
            response = await self.stop_service(cast(Dict[str, Any], data))
        elif command == "is_running":
            response = await self.is_running(cast(Dict[str, Any], data))
        elif command == "is_keyring_locked":
            response = await self.is_keyring_locked()
        elif command == "keyring_status":
            response = await self.keyring_status()
        elif command == "unlock_keyring":
            response = await self.unlock_keyring(cast(Dict[str, Any], data))
        elif command == "migrate_keyring":
            response = await self.migrate_keyring(cast(Dict[str, Any], data))
        elif command == "set_keyring_passphrase":
            response = await self.set_keyring_passphrase(cast(Dict[str, Any], data))
        elif command == "remove_keyring_passphrase":
            response = await self.remove_keyring_passphrase(cast(Dict[str, Any], data))
        elif command == "notify_keyring_migration_completed":
            response = await self.notify_keyring_migration_completed(cast(Dict[str, Any], data))
        elif command == "exit":
            response = await self.stop()
        elif command == "register_service":
            response = await self.register_service(websocket, cast(Dict[str, Any], data))
        elif command == "get_status":
            response = self.get_status()
        else:
            self.log.error(f"UK>> {message}")
            response = {"success": False, "error": f"unknown_command {command}"}

        full_response = format_response(message, response)
        return full_response, [websocket]