mirror of https://github.com/borgbackup/borg.git
Merge pull request #6564 from ThomasWaldmann/deleted-key-master
load_key: no key is same as empty key, fixes #6441
This commit is contained in:
commit
8d3db4637d
|
@ -617,11 +617,11 @@ class FlexiKey:
|
||||||
raise KeyfileNotFoundError(self.repository._location.canonical_path(), get_keys_dir())
|
raise KeyfileNotFoundError(self.repository._location.canonical_path(), get_keys_dir())
|
||||||
elif self.STORAGE == KeyBlobStorage.REPO:
|
elif self.STORAGE == KeyBlobStorage.REPO:
|
||||||
loc = self.repository._location.canonical_path()
|
loc = self.repository._location.canonical_path()
|
||||||
try:
|
key = self.repository.load_key()
|
||||||
self.repository.load_key()
|
if not key:
|
||||||
return loc
|
# if we got an empty key, it means there is no key.
|
||||||
except configparser.NoOptionError:
|
|
||||||
raise RepoKeyNotFoundError(loc) from None
|
raise RepoKeyNotFoundError(loc) from None
|
||||||
|
return loc
|
||||||
else:
|
else:
|
||||||
raise TypeError('Unsupported borg key storage type')
|
raise TypeError('Unsupported borg key storage type')
|
||||||
|
|
||||||
|
@ -681,6 +681,10 @@ class FlexiKey:
|
||||||
# what we get in target is just a repo location, but we already have the repo obj:
|
# what we get in target is just a repo location, but we already have the repo obj:
|
||||||
target = self.repository
|
target = self.repository
|
||||||
key_data = target.load_key()
|
key_data = target.load_key()
|
||||||
|
if not key_data:
|
||||||
|
# if we got an empty key, it means there is no key.
|
||||||
|
loc = target._location.canonical_path()
|
||||||
|
raise RepoKeyNotFoundError(loc) from None
|
||||||
key_data = key_data.decode('utf-8') # remote repo: msgpack issue #99, getting bytes
|
key_data = key_data.decode('utf-8') # remote repo: msgpack issue #99, getting bytes
|
||||||
else:
|
else:
|
||||||
raise TypeError('Unsupported borg key storage type')
|
raise TypeError('Unsupported borg key storage type')
|
||||||
|
|
|
@ -7,7 +7,7 @@ from hashlib import sha256
|
||||||
from ..helpers import Manifest, NoManifestError, Error, yes, bin_to_hex, dash_open
|
from ..helpers import Manifest, NoManifestError, Error, yes, bin_to_hex, dash_open
|
||||||
from ..repository import Repository
|
from ..repository import Repository
|
||||||
|
|
||||||
from .key import KeyfileKey, KeyfileNotFoundError, KeyBlobStorage, identify_key
|
from .key import KeyfileKey, KeyfileNotFoundError, RepoKeyNotFoundError, KeyBlobStorage, identify_key
|
||||||
|
|
||||||
|
|
||||||
class UnencryptedRepo(Error):
|
class UnencryptedRepo(Error):
|
||||||
|
@ -56,7 +56,12 @@ class KeyManager:
|
||||||
self.keyblob = ''.join(fd.readlines()[1:])
|
self.keyblob = ''.join(fd.readlines()[1:])
|
||||||
|
|
||||||
elif self.keyblob_storage == KeyBlobStorage.REPO:
|
elif self.keyblob_storage == KeyBlobStorage.REPO:
|
||||||
self.keyblob = self.repository.load_key().decode()
|
key_data = self.repository.load_key().decode()
|
||||||
|
if not key_data:
|
||||||
|
# if we got an empty key, it means there is no key.
|
||||||
|
loc = self.repository._location.canonical_path()
|
||||||
|
raise RepoKeyNotFoundError(loc) from None
|
||||||
|
self.keyblob = key_data
|
||||||
|
|
||||||
def store_keyblob(self, args):
|
def store_keyblob(self, args):
|
||||||
if self.keyblob_storage == KeyBlobStorage.KEYFILE:
|
if self.keyblob_storage == KeyBlobStorage.KEYFILE:
|
||||||
|
|
|
@ -343,7 +343,7 @@ class Repository:
|
||||||
self.save_config(self.path, self.config)
|
self.save_config(self.path, self.config)
|
||||||
|
|
||||||
def load_key(self):
|
def load_key(self):
|
||||||
keydata = self.config.get('repository', 'key')
|
keydata = self.config.get('repository', 'key', fallback='').strip()
|
||||||
# note: if we return an empty string, it means there is no repo key
|
# note: if we return an empty string, it means there is no repo key
|
||||||
return keydata.encode('utf-8') # remote repo: msgpack issue #99, returning bytes
|
return keydata.encode('utf-8') # remote repo: msgpack issue #99, returning bytes
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue