From c194606550f95b22dabe729e3ac96e4ffe7d0d40 Mon Sep 17 00:00:00 2001 From: Alex Pyrgiotis Date: Tue, 20 Jun 2023 19:47:54 +0300 Subject: [PATCH] Add Qubes RPC calls Add two RPC calls that can run on disposable VMs: * dz.Convert: This call simply imports the dangerzone package and runs the Qubes wrapper for the "document to pixels" code. This call is similar to the way we run the conversion part in a container. * dz.ConvertDev: This call is for development purposes, and does the following: - First it receives the `dangerzone.conversion` module as Python zipfile. This way, we can quickly iterate on changes on the server-side part of Qubes, without altering the templates. - Second, it calls the Qubes wrapper for the "document to pixels" code, as dz.Convert does. --- qubes/dz.Convert | 2 ++ qubes/dz.ConvertDev | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100755 qubes/dz.Convert create mode 100755 qubes/dz.ConvertDev diff --git a/qubes/dz.Convert b/qubes/dz.Convert new file mode 100755 index 0000000..d6b2e3e --- /dev/null +++ b/qubes/dz.Convert @@ -0,0 +1,2 @@ +#!/bin/sh +python -m dangerzone.conversion.doc_to_pixels_qubes_wrapper diff --git a/qubes/dz.ConvertDev b/qubes/dz.ConvertDev new file mode 100755 index 0000000..a663081 --- /dev/null +++ b/qubes/dz.ConvertDev @@ -0,0 +1,42 @@ +#!/usr/bin/env python + +import asyncio +import glob +import io +import os +import sys +import tempfile +import zipfile + + +def say(msg): + print(msg, file=sys.stderr, flush=True) + + +def main(): + say("Debugging mode enabled") + + # Get the size of the zipfile + size = int.from_bytes(sys.stdin.buffer.read(4)) + say(f"Reading {size} bytes of Python zipfile") + + # Read the zipfile from stdin + zf = sys.stdin.buffer.read(size) + if len(zf) < size: + say(f"Client closed the connection early") + return 1 + + with tempfile.NamedTemporaryFile(suffix=".zip") as t: + say(f"Storing the Python zipfile to {t.name}") + t.write(zf) + t.flush() + + say(f"Importing the conversion module") + sys.path.insert(0, t.name) + + from dangerzone.conversion.doc_to_pixels_qubes_wrapper import main + return asyncio.run(main()) + + +if __name__ == "__main__": + sys.exit(main())