Adjust for changed qubesd socket protocol

The socket protocol is adjusted to match qrexec socket service protocol.

QubesOS/qubes-issues#3293
This commit is contained in:
Marek Marczykowski-Górecki 2020-04-20 00:45:50 +02:00
parent 1d1289619c
commit bfe1a3d541
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
4 changed files with 13 additions and 17 deletions

View File

@ -659,11 +659,8 @@ class QubesLocal(QubesBase):
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)

View File

@ -79,10 +79,9 @@ class EventsDispatcher(object):
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():

View File

@ -771,19 +771,19 @@ class TC_20_QubesLocal(unittest.TestCase):
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')
@ -851,7 +851,7 @@ class TC_20_QubesLocal(unittest.TestCase):
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')
@ -865,7 +865,7 @@ class TC_20_QubesLocal(unittest.TestCase):
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):
@ -880,7 +880,7 @@ class TC_20_QubesLocal(unittest.TestCase):
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):

View File

@ -166,7 +166,7 @@ class TC_00_Events(qubesadmin.tests.QubesTestCase):
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()
@ -192,7 +192,7 @@ class TC_00_Events(qubesadmin.tests.QubesTestCase):
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()