mirror of https://github.com/borgbackup/borg.git
Merge pull request #839 from enkore/issue/791
If BORG_PASSPHRASE is present but wrong, don't prompt for password, f…
This commit is contained in:
commit
515b7454a3
16
borg/key.py
16
borg/key.py
|
@ -18,6 +18,10 @@ import msgpack
|
||||||
PREFIX = b'\0' * 8
|
PREFIX = b'\0' * 8
|
||||||
|
|
||||||
|
|
||||||
|
class PassphraseWrong(Error):
|
||||||
|
"""passphrase supplied in BORG_PASSPHRASE is incorrect"""
|
||||||
|
|
||||||
|
|
||||||
class PasswordRetriesExceeded(Error):
|
class PasswordRetriesExceeded(Error):
|
||||||
"""exceeded the maximum password retries"""
|
"""exceeded the maximum password retries"""
|
||||||
|
|
||||||
|
@ -284,13 +288,19 @@ class KeyfileKeyBase(AESKeyBase):
|
||||||
key = cls(repository)
|
key = cls(repository)
|
||||||
target = key.find_key()
|
target = key.find_key()
|
||||||
prompt = 'Enter passphrase for key %s: ' % target
|
prompt = 'Enter passphrase for key %s: ' % target
|
||||||
passphrase = Passphrase.env_passphrase(default='')
|
passphrase = Passphrase.env_passphrase()
|
||||||
for retry in range(1, 4):
|
if passphrase is None:
|
||||||
|
passphrase = Passphrase()
|
||||||
|
if not key.load(target, passphrase):
|
||||||
|
for retry in range(0, 3):
|
||||||
|
passphrase = Passphrase.getpass(prompt)
|
||||||
if key.load(target, passphrase):
|
if key.load(target, passphrase):
|
||||||
break
|
break
|
||||||
passphrase = Passphrase.getpass(prompt)
|
|
||||||
else:
|
else:
|
||||||
raise PasswordRetriesExceeded
|
raise PasswordRetriesExceeded
|
||||||
|
else:
|
||||||
|
if not key.load(target, passphrase):
|
||||||
|
raise PassphraseWrong
|
||||||
num_blocks = num_aes_blocks(len(manifest_data) - 41)
|
num_blocks = num_aes_blocks(len(manifest_data) - 41)
|
||||||
key.init_ciphers(PREFIX + long_to_bytes(key.extract_nonce(manifest_data) + num_blocks))
|
key.init_ciphers(PREFIX + long_to_bytes(key.extract_nonce(manifest_data) + num_blocks))
|
||||||
return key
|
return key
|
||||||
|
|
Loading…
Reference in New Issue