Skip to content

Commit

Permalink
Adjust for changed qubesd socket protocol
Browse files Browse the repository at this point in the history
The socket protocol is adjusted to match qrexec socket service protocol.

QubesOS/qubes-issues#3293
  • Loading branch information
marmarek committed May 18, 2020
1 parent c84d893 commit a7510e5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
7 changes: 2 additions & 5 deletions qubesadmin/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,11 +665,8 @@ def qubesd_call(self, dest, method, arg=None, payload=None,
raise qubesadmin.exc.QubesDaemonCommunicationError(
'Failed to connect to qubesd service: %s', str(e))

# src, method, dest, arg
for call_arg in ('dom0', method, dest, arg):
if call_arg is not None:
client_socket.sendall(call_arg.encode('ascii'))
client_socket.sendall(b'\0')
call_header = '{}+{} dom0 name {}\0'.format(method, arg or '', dest)
client_socket.sendall(call_header.encode('ascii'))
if payload is not None:
client_socket.sendall(payload)

Expand Down
7 changes: 3 additions & 4 deletions qubesadmin/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ def _get_events_reader(self, vm=None) -> (asyncio.StreamReader, callable):
if self.app.qubesd_connection_type == 'socket':
reader, writer = yield from asyncio.open_unix_connection(
qubesadmin.config.QUBESD_SOCKET)
writer.write(b'dom0\0') # source
writer.write(self._api_method.encode() + b'\0') # method
writer.write(dest.encode('ascii') + b'\0') # dest
writer.write(b'\0') # arg
writer.write(self._api_method.encode() + b'+ ') # method+arg
writer.write(b'dom0 ') # source
writer.write(b'name ' + dest.encode('ascii') + b'\0') # dest
writer.write_eof()

def cleanup_func():
Expand Down
12 changes: 6 additions & 6 deletions qubesadmin/tests/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,19 +771,19 @@ def test_000_qubesd_call(self):
self.listen_and_send(b'0\0')
self.app.qubesd_call('test-vm', 'some.method', 'arg1', b'payload')
self.assertEqual(self.get_request(),
b'dom0\0some.method\0test-vm\0arg1\0payload')
b'some.method+arg1 dom0 name test-vm\0payload')

def test_001_qubesd_call_none_arg(self):
self.listen_and_send(b'0\0')
self.app.qubesd_call('test-vm', 'some.method', None, b'payload')
self.assertEqual(self.get_request(),
b'dom0\0some.method\0test-vm\0\0payload')
b'some.method+ dom0 name test-vm\0payload')

def test_002_qubesd_call_none_payload(self):
self.listen_and_send(b'0\0')
self.app.qubesd_call('test-vm', 'some.method', None, None)
self.assertEqual(self.get_request(),
b'dom0\0some.method\0test-vm\0\0')
b'some.method+ dom0 name test-vm\0')

def test_003_qubesd_call_payload_stream(self):
payload_input = os.path.join(self.tmpdir, 'payload-input')
Expand Down Expand Up @@ -851,7 +851,7 @@ def test_010_run_service(self):
stderr=subprocess.PIPE)

self.assertEqual(self.get_request(),
b'dom0\0admin.vm.Start\0some-vm\0\0')
b'admin.vm.Start+ dom0 name some-vm\0')

def test_011_run_service_filter_esc(self):
self.listen_and_send(b'0\0')
Expand All @@ -865,7 +865,7 @@ def test_011_run_service_filter_esc(self):
stderr=subprocess.PIPE)

self.assertEqual(self.get_request(),
b'dom0\0admin.vm.Start\0some-vm\0\0')
b'admin.vm.Start+ dom0 name some-vm\0')

@mock.patch('os.isatty', lambda fd: fd == 2)
def test_012_run_service_user(self):
Expand All @@ -880,7 +880,7 @@ def test_012_run_service_user(self):
stderr=subprocess.PIPE)

self.assertEqual(self.get_request(),
b'dom0\0admin.vm.Start\0some-vm\0\0')
b'admin.vm.Start+ dom0 name some-vm\0')

def test_013_run_service_default_target(self):
with self.assertRaises(ValueError):
Expand Down
4 changes: 2 additions & 2 deletions qubesadmin/tests/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def test_020_get_events_reader_local(self):
self.read_all, sock2))
loop.run_until_complete(asyncio.wait([task, reader]))
self.assertEqual(reader.result(),
b'dom0\0admin.Events\0dom0\0\0')
b'admin.Events+ dom0 name dom0\0')
self.assertIsInstance(task.result()[0], asyncio.StreamReader)
cleanup_func = task.result()[1]
cleanup_func()
Expand All @@ -192,7 +192,7 @@ def test_021_get_events_reader_local_vm(self):
self.read_all, sock2))
loop.run_until_complete(asyncio.wait([task, reader]))
self.assertEqual(reader.result(),
b'dom0\0admin.Events\0test-vm\0\0')
b'admin.Events+ dom0 name test-vm\0')
self.assertIsInstance(task.result()[0], asyncio.StreamReader)
cleanup_func = task.result()[1]
cleanup_func()
Expand Down

0 comments on commit a7510e5

Please sign in to comment.