How I used Qubes Split GPG for key isolation, and the pitfalls I hit while setting it up.

Split GPG works like a smart card: the private key lives in a separate, network-isolated qube, and less trusted qubes such as Thunderbird only forward encryption, decryption and signing requests to it. If a client qube is compromised, the attacker still can’t get the private key. See the Qubes Split GPG documentation for details.

Environment Setup

This runs on Qubes OS 4.2.

First install it in dom0:

sudo qubes-dom0-update qubes-gpg-split-dom0

Install it in the Template for the GPG AppVM:

sudo apt install qubes-gpg-split

Use apt on Debian templates; on Fedora templates, use sudo dnf install qubes-gpg-split instead.

After importing your GPG key into the qube, you can check it with:

gpg -K

Set the auto-accept window. The unit is seconds, so 86400 is one day:

echo "export QUBES_GPG_AUTOACCEPT=86400" >> ~/.profile

This means no confirmation dialog for a day. Lower it for more security, or leave it unset.

Configure the client qube to use the work GPG qube:

export QUBES_GPG_DOMAIN=work-gpg
qubes-gpg-client -K

If the key shows up, it works:

Make the client pick the GPG qube automatically:

echo "work-gpg" > /rw/config/gpg-split-domain

In dom0, edit the qubes-rpc policy file /etc/qubes-rpc/policy/qubes.Gpg:

work-email  work-gpg  allow

This allows the work-email qube to access the work-gpg qube.

If the GPG key has a passphrase, you enter it in the client qube, which undercuts the point of the isolation. The Qubes docs recommend not setting a passphrase and letting qube isolation do the protecting.

If it already has one, remove it like this:

gpg2 --edit-key <key_id>
passwd

Set the passphrase to empty, then save and exit.

Git

Git can point its GPG program at the split-gpg wrapper. Edit ~/.gitconfig:

[user]
	email = <your-email>
	name = Your Name
	signingkey = <your-key-id>
[gpg]
	program = qubes-gpg-client-wrapper
[commit]
	gpgSign = 1

signingkey must show up in qubes-gpg-client --list-keys.

Create a local repo and make a commit to see it work:

git init demo
cd demo
echo demo > readme.md
git add .
git commit -s -m "add readme.md"

You’ll get a prompt when committing:

Check the commit:

git log --show-signature

Split SSH

Split SSH forwards SSH agent requests from the client qube to the GPG qube over qubes.SshAgent, so the private keys stay there. The examples below use work-email and work-gpg; substitute your own qube names.

First create the policy in dom0:

vi /etc/qubes-rpc/policy/qubes.SshAgent

Contents:

work-email work-gpg ask,default_target=work-gpg

If you don’t want to be asked every time:

work-email work-gpg allow,target=work-gpg

Add SSH support to GPG in the work-gpg AppVM. Edit ~/.gnupg/gpg-agent.conf:

enable-ssh-support

Get the keygrip of the SSH key:

gpg --with-keygrip -k

GPG SSH keygrip

Write the keygrip into ~/.gnupg/sshcontrol:

9501B4272C70680B802F5F2F2D903AC2DE3C0525

Install the dependencies in the work-gpg Template and create /etc/qubes-rpc/qubes.SshAgent:

sudo apt install socat libnotify-bin
#!/bin/sh
# Qubes App Split SSH Script

# Activate GPG Agent and set the correct SSH socket
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
gpgconf --launch gpg-agent

# safeguard - Qubes notification bubble for each ssh request
notify-send "[$(qubesdb-read /name)] SSH agent access from: $QREXEC_REMOTE_DOMAIN"

# SSH connection
socat - "UNIX-CONNECT:$SSH_AUTH_SOCK"

Make it executable:

sudo chmod +x /etc/qubes-rpc/qubes.SshAgent

In the work-email AppVM, edit /rw/config/rc.local:

# SPLIT SSH CONFIGURATION >>>
# replace "work-gpg" with your AppVM name which stores the ssh private key(s)
SSH_VAULT_VM="work-gpg"

if [ "$SSH_VAULT_VM" != "" ]; then
  export SSH_SOCK="/home/user/.SSH_AGENT_$SSH_VAULT_VM"
  rm -f "$SSH_SOCK"
  sudo -u user /bin/sh -c "umask 177 && exec socat 'UNIX-LISTEN:$SSH_SOCK,fork' 'EXEC:qrexec-client-vm $SSH_VAULT_VM qubes.SshAgent'" &
fi
# <<< SPLIT SSH CONFIGURATION

Then add this to ~/.bashrc:

# SPLIT SSH CONFIGURATION >>>
SSH_VAULT_VM="work-gpg"

if [ "$SSH_VAULT_VM" != "" ]; then
  export SSH_AUTH_SOCK="/home/user/.SSH_AGENT_$SSH_VAULT_VM"
fi
# <<< SPLIT SSH CONFIGURATION

Restart work-email, then list the keys in the agent:

ssh-add -L

The first time, a dialog asks whether to allow access to work-gpg:

Split SSH authorization prompt

Once you allow it, the keys are listed.

Email Encryption

Thunderbird has included OpenPGP since version 78, so installing Enigmail is no longer necessary.

Open the Thunderbird config editor:

Thunderbird config editor

Search for mail.openpgp.allow_external_gnupg and set it to true. Then search for mail.openpgp.alternative_gpg_path and enter /usr/bin/qubes-gpg-client-wrapper. Restart Thunderbird.

Then configure end-to-end encryption in the account settings:

Thunderbird end-to-end encryption

Choose the smartcard option:

Choose smartcard

Enter the GPG key ID, which you can look up with:

qubes-gpg-client-wrapper -K --keyid-format long

Enter the key ID

Once added, it looks like this:

Added

Thunderbird can’t fetch the public key through the wrapper, so import it manually once:

Import the public key manually

Set the trust level to Yes, I’ve verified in person this key has the correct fingerprint. since you’re confirming your own fingerprint:

Trust the public key

To test, write yourself an email:

Compose a test email

The encryption option is already on. If the private key is on a YubiKey, you’ll be asked for the PIN when sending:

Enter the PIN when sending

You also need the PIN to read mail, after which you’ll see the decrypted content:

Decrypted email

pass with Split GPG

pass doesn’t go through split-gpg by default, but an extension can wire it up. Download qubes.bash from pass-qubes:

mkdir -p ~/.password-store/.extensions
mv ~/Downloads/qubes.bash ~/.password-store/.extensions/
chmod +x ~/.password-store/.extensions/*.bash
export PASSWORD_STORE_ENABLE_EXTENSIONS=true

Then use:

pass qubes generate -c -n test/t0 128
pass qubes show test/t0 --clip
pass qubes rm test/t0

To enable the extension on every login, add the variable to ~/.profile:

echo "export PASSWORD_STORE_ENABLE_EXTENSIONS=true" >> ~/.profile

What You Can Do Next

  • Use automation to configure Split GPG / Split SSH policies in bulk

References