Score:0

Is there a published implementation of QubesOS "Convert to Trusted PDF" on Ubuntu?

tn flag

The title pretty much says it. Convert to Trusted PDF is a valuable tool, and it would be great to implement it in the Ubuntu ecosystem.

waltinator avatar
it flag
What do you mean by "Trusted PDF", and what's the input?
Lexible avatar
tn flag
@waltinator Please see the link in my edit.
ar flag
I looked at the link. You may want to send a feature request to Canonical, using their launchpad site. Alternately, you can try to set up a read only VM that does what you want.
Lexible avatar
tn flag
@user68186 Can you say a smidge more?
ar flag
Did I answer your question? If so please accept the answer. Thanks!
Score:2
ar flag

The Problem

You have an untrusted PDF file. It may contain a malware and the malware may infect your computer and do terrible things to it.

You want to convert this PDF to a "trusted" PDF that does not have any malware without endangering your Ubuntu computer.

The Method

The idea is to install Multipass in your Ubuntu computer, and use the default primary Virtual Machine (VM) to "flatten" the untrusted PDF file. The process of flattening the PDF involves converting the PDF file to a postscript (PS) file and then convert the PS file back to PDF. The resulting PDF is "trusted" as the any malware in the original PDF is not expected to survive the double conversion process.

Finally, once the conversion is complete, the VM is destroyed. So that any changes that may be made to the VM by the malware in the original PDF is destroyed with it.

A Proof of Concept

This solution is command line based, where we will type (or paste) commands in the terminal.

First let us install Multipass in your computer with the following command:

sudo snap install multipass

You have to do it only once.

The rest of the work is done by a bash script. I call it flatten.sh. Save the script below in your home folder as flatten.sh and make it executable.

#!/bin/bash

if [ -z $1 ]; then
    echo "No argument set. Valid argument is a PDF filename.pdf in the $HOME folder"
    read -ep "Enter filename: " FULLNAME
else
    FULLNAME=$1
fi
if [ ! -f $FULLNAME ]; then
    echo "The file $FULLNAME not found." 
    echo "Valid argument is a PDF filename.pdf in the $HOME folder"
    echo "exiting..."
    exit 1
fi

INPNAME=$(basename $FULLNAME)
DIR=$(dirname $FULLNAME)
OUTNAME="Trusted-$INPNAME"
multipass start
multipass exec primary -- sudo apt update
multipass exec primary -- sudo apt install ghostscript -y
multipass exec primary -- cp "Home/$INPNAME" .
multipass exec primary -- pdf2ps "$INPNAME" temp  
multipass exec primary -- ps2pdf temp "$OUTNAME"
multipass exec primary -- mv "$OUTNAME" Home/
multipass stop primary  
multipass delete primary
multipass purge

Let us say, you have a file called test.pdf that you don't trust. Use the following command to run the script:

./flatten.sh test.pdf

The test.pdf should be in your $HOME folder. If you have your PDF file in a different folder, the script (as it is written) won't find it.

Here is the list of things that will happen once you start this script:

  1. A VM will be created
  2. A minimal version of Ubuntu will be installed in the VM
  3. The script will install ghostscript, needed for the conversion
  4. The untrusted PDF file will be copied to the VM's virtual storage.
  5. The untruested PDF will be converted to a temp PS file and
  6. The temp PS file will be converted to "trusted" PDF with the with the "Truted-" prefix.
  7. The trusted PDF will be moved back to your home folder.
  8. The VM will be stopped, deleted, and purged.

This whole process will take some time, particularly initiation of the VM and the installation of ghostscript.

Note: if the untrusted PDF file is very big the Multipass VM may run out of the virtual memory allocated by default. See Multipass documentation on how to allocated more memory to the VM.

Downside

As far as I can tell there is no way to take a snapshot of the primary VM in Multipass after installing Ghostscript and spin that stored VM for the next time you need to sanitize a PDF. If this was possible it would make the process take a little less time.

Another Way

Another way to achieve similar results may be to use LDX/LXC containers. LXD supports snapshots and a custom container with just Ghostscript may be a little lighter than a full VM. However, I don't have any experience with LXD/LXC.

Hope this helps

Lexible avatar
tn flag
+1 This is a fabulous answer! I think I have a slight preference for Convert to Trusted PDF's model (PDF rendered by an engine in VM which ignores scripts, fetching URLs etc create raster images, compile new pdf of raster images, OCR that, then return the 'trusted' PDF to user, but the difference in vulnerabilities seems close in either case. Thank you for this!
ar flag
@Lexible Thanks! The blog you linked, specifically says **Covert to Trusted PDF** does not OCR the text. See "There are two annoying downsides that trusted PDFs have:" in the blog. In any case, passing the flattened PDF through OCR may result in lost images, figures, diagrams, as well as formatting, fonts etc. The downside of my approach is there is no way to save a snapshot of the VM after installing ghostscript in Multipass. LXD/LXC can solve that but the initial setup of LXD/LXC is more cumbersome. Either way it is command line, no fancy colored borders in GUI.
raj avatar
cn flag
raj
"The process of flattening the PDF involves converting the PDF file to a postscript (PS) file and then convert the PS file back to PDF." Isn't this basically equivalent to printing the PDF file to another PDF file using "print to file" option? Of course one needs to do the printing in a separate VM...
ar flag
@raj It is doing the same thing in a bit more secure way. Setting up a VM with GUI to run Evince or Ocular would take up more resources (and time if you want to delete the VM after the job is done, and recreate it next time). Feel free to write a GUI based answer.
Lexible avatar
tn flag
@user68186 Whoops! Yes: you are correct about the OCR... I would have to add that in if I wanted it.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.