Merge pull request #2135 from textshell/feature/paperkey-doc-qr

paperkey+qr html+js template
This commit is contained in:
enkore 2017-02-12 15:33:04 +01:00 committed by GitHub
commit 4f9dd98a31
6 changed files with 2470 additions and 6 deletions

View File

@ -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

View File

@ -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'</textarea>', key_data.encode() + b'</textarea>')
fd.write(html)
def export_paperkey(self, path):
def grouped(s):
ret = ''

2438
borg/paperkey.html Normal file

File diff suppressed because it is too large Load Diff

View File

@ -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 = ['../borg/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'

View File

@ -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

View File

@ -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'],