Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README: add detailed paperkey instructions #433

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

matheusmoreira
Copy link

Document the paperkey backup and restoration process. Includes instructions on backing up to printed QR codes.

Document the paperkey backup and restoration process.
Describe the original human readable text method
as well as the convenient QR code method.
@drduh
Copy link
Owner

drduh commented May 5, 2024

Looks good. Let's move this to Optional hardening, since I do not believe most people will want or need to do these steps. What do you think?

@jeevsobs
Copy link

jeevsobs commented May 6, 2024

The instructions as-is don't seem to be compatible with the guide. There are several problems I encountered:

First of all, the guide's gpg.conf specifies that exports be armored by default but paperkey accepts binary inputs.

To solve this is simple, just export the gpg dearmored when piping into paperkey.
(e.g. gpg --batch --pinentry-mode=loopback --passphrase "$CERTIFY_PASS" --export-secret-keys $KEYID | gpg --dearmor | paperkey | lpr)

You can then simply print out the human-readable paperkey. That's fine if that's all you want but it's inconvenient for recovery since the recovery input sequence is extremely long.

This is where another problem that arises if you want to use QR codes for practicality. qrencode will throw an error saying the input is too large. This is due to the paperkey being over the maximum 3KB limit of QR data. Even if you could somehow fit it in, the QR code is difficult to scan, especially if your scanning hardware isn't great (e.g. bad webcam).

A solution to this would be to split the paperkey into multiple files and encode those separately. Recovery would involve decoding the QR codes and concatenating the files together for import.
A way to approach this process is described here: https://maxammann.org/posts/2021/01/keeping-secret-safe/

Just thought that I would bring these issues up before anything is merged. I can provide advice for rewriting this section if needed.

@matheusmoreira
Copy link
Author

matheusmoreira commented May 8, 2024

First of all, the guide's gpg.conf specifies that exports be armored by default but paperkey accepts binary inputs.

That's true. Paperkey does require binary input and gpg outputs binary OpenPGP packets by default. I didn't notice that this default had been reconfigured. Will fix.

You can then simply print out the human-readable paperkey.

You can and you absolutely should. If the QR code is dense enough, you can run into serious trouble trying to read it back in. 4096 bit RSA keys are particularly problematic, they produce very dense QR codes even with the lowest possible error correction setting.

I would have lost an encryption key if I hadn't printed out the paperkey pages. Restoring a 4096 bit RSA key that way was nightmarish but it worked.

That's fine if that's all you want but it's inconvenient for recovery since the recovery input sequence is extremely long.

Yeah. I bought two YubiKey 5s with Curve25519 support after that taxing experience. The keys are much smaller, you can actually read the QR code back in.

qrencode will throw an error saying the input is too large.

Even 4096 bit RSA keys will fit into QR codes. You just need to use binary mode and paperkey's raw output mode to pipe just the key itself into qrencode. Don't pipe the base16 output into qrencode.

the QR code is difficult to scan, especially if your scanning hardware isn't great (e.g. bad webcam).

This is true. I should probably add that warning to the guide too.

A solution to this would be to split the paperkey into multiple files and encode those separately.

QR codes actually have native support for this, they call it structured append. Many other types of barcodes support this as well. QR codes support appending up to 16 symbols. I've yet to come across reader apps that supports it though.

@jeevsobs
Copy link

Might want to point out that you used ed25519 keys then. Were you able to get the guide's keys working? I wasn't able to pipe the guide's rsa4096 key with the 3 subkeys into qrencode. I did indeed use paperkey raw output and a rsa4096 without subkeys worked.

I do agree that you should definitely print out the text paperkey. Always good to have more backups. Also, Interesting tidbit about structured append.

@matheusmoreira
Copy link
Author

@jeevsobs

I wasn't able to pipe the guide's rsa4096 key with the 3 subkeys into qrencode.

I do see the problem! There's indeed a mistake in my pull request.

gpg has a rather unfortunate interface. When you --export-secret-keys it won't export just the key you asked for, it'll export the entire keyring. This happens even if you specify the key by ID or fingerprint.

In order to make it export only the desired key, it needs an exclamation mark ! appended to the ID or fingerprint.

gpg --export-secret-key "${KEYID}"'!' | paperkey | lpr
gpg --export-secret-key "${KEYID}"'!' | \ 
     paperkey --output-type raw | \ 
     qrencode --8bit --output
     "${KEYID}".secret-key.qr.png

An entire key ring is probably too big for a QR code, especially 4096 bit RSA keys, but without the ! I'm not sure even the ECC keys will fit.

Thanks for testing it and catching this issue!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants