Browse Source

change encryption to be on by default (repokey mode)

it's 2015, let's be safe-by-default and unsafe-as-option.

also: show default mode in builtin help
Thomas Waldmann 9 năm trước cách đây
mục cha
commit
6d615ec30a

+ 2 - 3
borg/archiver.py

@@ -64,7 +64,6 @@ class Archiver:
             repository = RemoteRepository(location, create=create, lock_wait=self.lock_wait, lock=lock, args=args)
             repository = RemoteRepository(location, create=create, lock_wait=self.lock_wait, lock=lock, args=args)
         else:
         else:
             repository = Repository(location.path, create=create, exclusive=exclusive, lock_wait=self.lock_wait, lock=lock)
             repository = Repository(location.path, create=create, exclusive=exclusive, lock_wait=self.lock_wait, lock=lock)
-        repository._location = location
         return repository
         return repository
 
 
     def print_error(self, msg, *args):
     def print_error(self, msg, *args):
@@ -797,8 +796,8 @@ class Archiver:
                                type=location_validator(archive=False),
                                type=location_validator(archive=False),
                                help='repository to create')
                                help='repository to create')
         subparser.add_argument('-e', '--encryption', dest='encryption',
         subparser.add_argument('-e', '--encryption', dest='encryption',
-                               choices=('none', 'keyfile', 'repokey', 'passphrase'), default='none',
-                               help='select encryption key mode')
+                               choices=('none', 'keyfile', 'repokey', 'passphrase'), default='repokey',
+                               help='select encryption key mode (default: "%(default)s")')
 
 
         check_epilog = textwrap.dedent("""
         check_epilog = textwrap.dedent("""
         The check command verifies the consistency of a repository and the corresponding archives.
         The check command verifies the consistency of a repository and the corresponding archives.

+ 1 - 1
borg/remote.py

@@ -129,7 +129,7 @@ class RemoteRepository:
             self.name = name
             self.name = name
 
 
     def __init__(self, location, create=False, lock_wait=None, lock=True, args=None):
     def __init__(self, location, create=False, lock_wait=None, lock=True, args=None):
-        self.location = location
+        self.location = self._location = location
         self.preload_ids = []
         self.preload_ids = []
         self.msgid = 0
         self.msgid = 0
         self.to_send = b''
         self.to_send = b''

+ 2 - 1
borg/repository.py

@@ -11,7 +11,7 @@ import struct
 from zlib import crc32
 from zlib import crc32
 
 
 import msgpack
 import msgpack
-from .helpers import Error, ErrorWithTraceback, IntegrityError, ProgressIndicatorPercent
+from .helpers import Error, ErrorWithTraceback, IntegrityError, Location, ProgressIndicatorPercent
 from .hashindex import NSIndex
 from .hashindex import NSIndex
 from .locking import UpgradableLock, LockError, LockErrorT
 from .locking import UpgradableLock, LockError, LockErrorT
 from .lrucache import LRUCache
 from .lrucache import LRUCache
@@ -54,6 +54,7 @@ class Repository:
 
 
     def __init__(self, path, create=False, exclusive=False, lock_wait=None, lock=True):
     def __init__(self, path, create=False, exclusive=False, lock_wait=None, lock=True):
         self.path = os.path.abspath(path)
         self.path = os.path.abspath(path)
+        self._location = Location('file://%s' % self.path)
         self.io = None
         self.io = None
         self.lock = None
         self.lock = None
         self.index = None
         self.index = None

+ 2 - 1
borg/testsuite/archiver.py

@@ -92,7 +92,7 @@ def test_return_codes(cmd, tmpdir):
     input = tmpdir.mkdir('input')
     input = tmpdir.mkdir('input')
     output = tmpdir.mkdir('output')
     output = tmpdir.mkdir('output')
     input.join('test_file').write('content')
     input.join('test_file').write('content')
-    rc, out = cmd('init', '%s' % str(repo))
+    rc, out = cmd('init', '--encryption=none', '%s' % str(repo))
     assert rc == EXIT_SUCCESS
     assert rc == EXIT_SUCCESS
     rc, out = cmd('create', '%s::archive' % repo, str(input))
     rc, out = cmd('create', '%s::archive' % repo, str(input))
     assert rc == EXIT_SUCCESS
     assert rc == EXIT_SUCCESS
@@ -192,6 +192,7 @@ class ArchiverTestCaseBase(BaseTestCase):
     def setUp(self):
     def setUp(self):
         os.environ['BORG_CHECK_I_KNOW_WHAT_I_AM_DOING'] = '1'
         os.environ['BORG_CHECK_I_KNOW_WHAT_I_AM_DOING'] = '1'
         os.environ['BORG_DELETE_I_KNOW_WHAT_I_AM_DOING'] = '1'
         os.environ['BORG_DELETE_I_KNOW_WHAT_I_AM_DOING'] = '1'
+        os.environ['BORG_PASSPHRASE'] = 'waytooeasyonlyfortests'
         self.archiver = not self.FORK_DEFAULT and Archiver() or None
         self.archiver = not self.FORK_DEFAULT and Archiver() or None
         self.tmpdir = tempfile.mkdtemp()
         self.tmpdir = tempfile.mkdtemp()
         self.repository_path = os.path.join(self.tmpdir, 'repository')
         self.repository_path = os.path.join(self.tmpdir, 'repository')

+ 3 - 2
docs/quickstart.rst

@@ -146,9 +146,10 @@ Keep an eye on CPU load and throughput.
 Repository encryption
 Repository encryption
 ---------------------
 ---------------------
 
 
-Repository encryption is enabled at repository creation time::
+Repository encryption can be enabled or disabled at repository creation time
+(the default is enabled, with `repokey` method)::
 
 
-    $ borg init --encryption=repokey|keyfile PATH
+    $ borg init --encryption=none|repokey|keyfile PATH
 
 
 When repository encryption is enabled all data is encrypted using 256-bit AES_
 When repository encryption is enabled all data is encrypted using 256-bit AES_
 encryption and the integrity and authenticity is verified using `HMAC-SHA256`_.
 encryption and the integrity and authenticity is verified using `HMAC-SHA256`_.