Sfoglia il codice sorgente

increase Key.version to 2

Old borg (< 2.0) can not read/process the new keys that have crypt_key instead of enc_key and enc_hmac_key.
Thomas Waldmann 2 anni fa
parent
commit
d5df53732d
3 ha cambiato i file con 5 aggiunte e 5 eliminazioni
  1. 1 1
      docs/internals/data-structures.rst
  2. 3 3
      src/borg/crypto/key.py
  3. 1 1
      src/borg/item.pyx

+ 1 - 1
docs/internals/data-structures.rst

@@ -933,7 +933,7 @@ in the configuration file.
 The internal data structure is as follows:
 
 version
-  currently always an integer, 1
+  currently always an integer, 2
 
 repository_id
   the ``id`` field in the ``config`` ``INI`` file of the repository.

+ 3 - 3
src/borg/crypto/key.py

@@ -461,8 +461,8 @@ class FlexiKey:
         if data:
             data = msgpack.unpackb(data)
             key = Key(internal_dict=data)
-            if key.version != 1:
-                raise IntegrityError("Invalid key file header")
+            if key.version not in (1, 2):  # legacy: item.Key can still process v1 keys
+                raise UnsupportedKeyFormatError()
             self.repository_id = key.repository_id
             self.crypt_key = key.crypt_key
             self.id_key = key.id_key
@@ -575,7 +575,7 @@ class FlexiKey:
 
     def _save(self, passphrase, algorithm):
         key = Key(
-            version=1,
+            version=2,
             repository_id=self.repository_id,
             crypt_key=self.crypt_key,
             id_key=self.id_key,

+ 1 - 1
src/borg/item.pyx

@@ -459,7 +459,7 @@ class Key(PropDict):
             if k in ('repository_id', 'crypt_key', 'id_key'):
                 v = fix_bytes_value(d, k)
             self._dict[k] = v
-        if 'crypt_key' not in self._dict:  # legacy, we're loading an old key
+        if 'crypt_key' not in self._dict:  # legacy, we're loading an old v1 key
             k = fix_bytes_value(d, 'enc_key') + fix_bytes_value(d, 'enc_hmac_key')
             assert isinstance(k, bytes), "k == %r" % k
             assert len(k) in (32 + 32, 32 + 128)  # 256+256 or 256+1024 bits