mirror of
https://github.com/borgbackup/borg.git
synced 2025-03-06 11:40:31 +00:00
When probing key files, do binary reads
This commit is contained in:
parent
eaf0f62022
commit
24cd303ca9
1 changed files with 6 additions and 4 deletions
10
borg/key.py
10
borg/key.py
|
@ -394,13 +394,15 @@ class KeyfileKey(KeyfileKeyBase):
|
|||
FILE_ID = 'BORG_KEY'
|
||||
|
||||
def find_key(self):
|
||||
id = hexlify(self.repository.id).decode('ascii')
|
||||
file_id = self.FILE_ID.encode()
|
||||
first_line = file_id + b' ' + hexlify(self.repository.id)
|
||||
keys_dir = get_keys_dir()
|
||||
for name in os.listdir(keys_dir):
|
||||
filename = os.path.join(keys_dir, name)
|
||||
with open(filename, 'r') as fd:
|
||||
line = fd.readline().strip()
|
||||
if line.startswith(self.FILE_ID) and line[len(self.FILE_ID) + 1:] == id:
|
||||
# we do the magic / id check in binary mode to avoid stumbling over
|
||||
# decoding errors if somebody has binary files in the keys dir for some reason.
|
||||
with open(filename, 'rb') as fd:
|
||||
if fd.read(len(first_line)) == first_line:
|
||||
return filename
|
||||
raise KeyfileNotFoundError(self.repository._location.canonical_path(), get_keys_dir())
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue