Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error messages #645

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions qubes/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@
import uuid

import qubes.exc
from qubes.exc import ProtocolError, PermissionDenied
from qubes.exc import (
ProtocolError,
PermissionDenied,
QubesArgumentNotAllowedError,
DestinationNotDom0Error,
)


def method(name, *, no_payload=False, endpoints=None, **classifiers):
Expand Down Expand Up @@ -165,10 +170,10 @@ def __init__(
self.dest = decode_vm(dest, app.domains)

#: argument
self.arg = arg.decode("ascii")
self.arg = arg.decode("ascii", "strict")

#: name of the method
self.method = method_name.decode("ascii")
self.method = method_name.decode("ascii", "strict")

#: callback for sending events if applicable
self.send_event = send_event
Expand Down Expand Up @@ -239,6 +244,17 @@ def fire_event_for_filter(self, iterable, **kwargs):
"""Fire an event on the source qube to filter for permission"""
return apply_filters(iterable, self.fire_event_for_permission(**kwargs))

def enforce_no_arg(self) -> None:
"""If the argument is not empty, raise an exception."""
if self.arg:
raise QubesArgumentNotAllowedError(self.method, self.arg)

def enforce_dest_dom0(self) -> None:
"""If the destination is not dom0, raise an exception."""
name = self.dest.name
if name != "dom0":
raise DestinationNotDom0Error(name)

@staticmethod
def enforce(predicate):
"""An assert replacement, but works even with optimisations."""
Expand Down Expand Up @@ -349,6 +365,11 @@ async def respond(self, src, meth, dest, arg, *, untrusted_payload):
dest,
len(untrusted_payload),
)
if self.transport is not None:
self.send_exception(err)
self.transport.write_eof()
self.transport.close()
return

except ProtocolError:
self.app.log.warning(
Expand Down
Loading