From 57bc1ff47d145b07f52e913065f43519d5b9a1e3 Mon Sep 17 00:00:00 2001 From: Martin Hostettler Date: Sun, 25 Sep 2016 14:35:06 +0200 Subject: [PATCH 1/3] paperkey.html: Add interactive html template for printing key backups. --- docs/paperkey.html | 2438 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2438 insertions(+) create mode 100644 docs/paperkey.html diff --git a/docs/paperkey.html b/docs/paperkey.html new file mode 100644 index 000000000..82c7f98ac --- /dev/null +++ b/docs/paperkey.html @@ -0,0 +1,2438 @@ + + + + + + +BorgBackup Printable Key Template + + + + + + +
+
+

To create a printable key, either paste the contents of your keyfile or a key export in the text field + below, or select a key export file.

+

To create a key export use

borg key export /path/to/repository exportfile.txt

+

If you are using keyfile mode, keyfiles are usually stored in $HOME/.config/borg/keys/

+

You can edit the parts with light blue border in the print preview below by click into them.

+

Key security: This print template will never send anything to remote servers. But keep in mind, that printing + might involve computers that can store the printed image, for example with cloud printing services, or + networked printers.

+

+
+ + +
+
+ QR error correction: +
+ QR code size
+ Text size
+ Text columns +
+ +
+
+ + +
+
+ +
+
BorgBackup Printable Key Backup
+
To restore either scan the QR code below, decode it and import it using +
borg key-import /path/to/repo scannedfile
+ +Or run +
borg key import --paper /path/to/repo
and type in the text below.

+
+
+
+
Notes:
+
+
+ + + + + \ No newline at end of file From 52e84a6e2db4cef1b05864053cde4437318e88ba Mon Sep 17 00:00:00 2001 From: Martin Hostettler Date: Sun, 25 Sep 2016 17:08:40 +0200 Subject: [PATCH 2/3] quickstart.rst: Add link to paperkey template. --- docs/conf.py | 2 ++ docs/quickstart.rst | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 94e088d5f..43413a504 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -140,6 +140,8 @@ html_favicon = '_static/favicon.ico' # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['borg_theme'] +html_extra_path = ['paperkey.html'] + # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. html_last_updated_fmt = '%Y-%m-%d' diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 58ce6c96f..1d01370e8 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -231,11 +231,14 @@ For automated backups the passphrase can be specified using the You can make backups using :ref:`borg_key_export` subcommand. If you want to print a backup of your key to paper use the ``--paper`` - option of this command and print the result. + option of this command and print the result, or this print `template`_ + if you need a version with QR-Code. A backup inside of the backup that is encrypted with that key/passphrase won't help you with that, of course. +.. _template: paperkey.html + .. _remote_repos: Remote repositories From 257e55f37e479f2e0d6d68a3d219c79eb69069e6 Mon Sep 17 00:00:00 2001 From: Martin Hostettler Date: Wed, 8 Feb 2017 00:22:37 +0100 Subject: [PATCH 3/3] Add qr html export mode to `key export` command --- borg/archiver.py | 8 +++++++- borg/keymanager.py | 20 ++++++++++++++++---- {docs => borg}/paperkey.html | 0 docs/conf.py | 2 +- setup.py | 3 +++ 5 files changed, 27 insertions(+), 6 deletions(-) rename {docs => borg}/paperkey.html (100%) diff --git a/borg/archiver.py b/borg/archiver.py index c2626beba..8d4b41839 100644 --- a/borg/archiver.py +++ b/borg/archiver.py @@ -198,7 +198,10 @@ class Archiver: if not args.path: self.print_error("output file to export key to expected") return EXIT_ERROR - manager.export(args.path) + if args.qr: + manager.export_qr(args.path) + else: + manager.export(args.path) return EXIT_SUCCESS @with_repository(lock=False, exclusive=False, manifest=False, cache=False) @@ -1259,6 +1262,9 @@ class Archiver: subparser.add_argument('--paper', dest='paper', action='store_true', default=False, help='Create an export suitable for printing and later type-in') + subparser.add_argument('--qr-html', dest='qr', action='store_true', + default=False, + help='Create an html file suitable for printing and later type-in or qr scan') key_import_epilog = textwrap.dedent(""" This command allows to restore a key previously backed up with the diff --git a/borg/keymanager.py b/borg/keymanager.py index 0b365e822..49799afc6 100644 --- a/borg/keymanager.py +++ b/borg/keymanager.py @@ -2,6 +2,7 @@ from binascii import unhexlify, a2b_base64, b2a_base64 import binascii import textwrap from hashlib import sha256 +import pkgutil from .key import KeyfileKey, RepoKey, PassphraseKey, KeyfileNotFoundError, PlaintextKey from .helpers import Manifest, NoManifestError, Error, yes, bin_to_hex @@ -77,16 +78,27 @@ class KeyManager: elif self.keyblob_storage == KEYBLOB_REPO: self.repository.save_key(self.keyblob.encode('utf-8')) + def get_keyfile_data(self): + data = '%s %s\n' % (KeyfileKey.FILE_ID, bin_to_hex(self.repository.id)) + data += self.keyblob + if not self.keyblob.endswith('\n'): + data += '\n' + return data + def store_keyfile(self, target): with open(target, 'w') as fd: - fd.write('%s %s\n' % (KeyfileKey.FILE_ID, bin_to_hex(self.repository.id))) - fd.write(self.keyblob) - if not self.keyblob.endswith('\n'): - fd.write('\n') + fd.write(self.get_keyfile_data()) def export(self, path): self.store_keyfile(path) + def export_qr(self, path): + with open(path, 'wb') as fd: + key_data = self.get_keyfile_data() + html = pkgutil.get_data('borg', 'paperkey.html') + html = html.replace(b'', key_data.encode() + b'') + fd.write(html) + def export_paperkey(self, path): def grouped(s): ret = '' diff --git a/docs/paperkey.html b/borg/paperkey.html similarity index 100% rename from docs/paperkey.html rename to borg/paperkey.html diff --git a/docs/conf.py b/docs/conf.py index 43413a504..166916954 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -140,7 +140,7 @@ html_favicon = '_static/favicon.ico' # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['borg_theme'] -html_extra_path = ['paperkey.html'] +html_extra_path = ['../borg/paperkey.html'] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. diff --git a/setup.py b/setup.py index 4f2ca8681..4e816907e 100644 --- a/setup.py +++ b/setup.py @@ -302,6 +302,9 @@ setup( 'borg = borg.archiver:main', ] }, + package_data={ + 'borg': ['paperkey.html'] + }, cmdclass=cmdclass, ext_modules=ext_modules, setup_requires=['setuptools_scm>=1.7'],