mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
backups: Don't send passphrase on the command line
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
1 parent
fa3e2ea86b
commit
dd5d93637f
4 files changed
+66
-85
No files matched your search
@@ -108,9 +108,13 @@ def _backup_handler(packet, encryption_passphrase=None):
|
||||
paths = packet.directories + packet.files
|
||||
paths.append(manifest_path)
|
||||
arguments = ['create-archive', '--path', packet.path, '--paths'] + paths
|
||||
input_data = ''
|
||||
if encryption_passphrase:
|
||||
arguments += ['--encryption-passphrase', encryption_passphrase]
|
||||
actions.superuser_run('backups', arguments)
|
||||
input_data = json.dumps({
|
||||
'encryption_passphrase': encryption_passphrase
|
||||
})
|
||||
|
||||
actions.superuser_run('backups', arguments, input=input_data.encode())
|
||||
|
||||
|
||||
def get_exported_archive_apps(path):
|
||||
@@ -131,13 +135,15 @@ def _restore_exported_archive_handler(packet, encryption_passphrase=None):
|
||||
|
||||
def restore_archive_handler(packet, encryption_passphrase=None):
|
||||
"""Perform restore operation on packet."""
|
||||
locations = {'directories': packet.directories, 'files': packet.files}
|
||||
locations = {
|
||||
'directories': packet.directories,
|
||||
'files': packet.files,
|
||||
'encryption_passphrase': encryption_passphrase
|
||||
}
|
||||
locations_data = json.dumps(locations)
|
||||
arguments = [
|
||||
'restore-archive', '--path', packet.path, '--destination', '/'
|
||||
]
|
||||
if encryption_passphrase:
|
||||
arguments += ['--encryption-passphrase', encryption_passphrase]
|
||||
actions.superuser_run('backups', arguments, input=locations_data.encode())
|
||||
|
||||
|
||||
|
||||
@@ -93,13 +93,13 @@ class BorgRepository():
|
||||
self.credentials = credentials
|
||||
|
||||
@staticmethod
|
||||
def _get_encryption_arguments(credentials):
|
||||
"""Return '--encryption-passphrase' argument to backups call."""
|
||||
def _get_encryption_data(credentials):
|
||||
"""Return additional dictionary data to send to backups call."""
|
||||
passphrase = credentials.get('encryption_passphrase', None)
|
||||
if passphrase:
|
||||
return ['--encryption-passphrase', passphrase]
|
||||
return {'encryption_passphrase': passphrase}
|
||||
|
||||
return []
|
||||
return {}
|
||||
|
||||
@property
|
||||
def repo_path(self):
|
||||
@@ -177,8 +177,10 @@ class BorgRepository():
|
||||
return chunk
|
||||
|
||||
args = ['export-tar', '--path', self._get_archive_path(archive_name)]
|
||||
args += self._get_encryption_arguments(self.credentials)
|
||||
input_data = json.dumps(self._get_encryption_data(self.credentials))
|
||||
proc = self._run('backups', args, run_in_background=True)
|
||||
proc.stdin.write(input_data.encode())
|
||||
proc.stdin.close()
|
||||
return BufferedReader(proc.stdout)
|
||||
|
||||
def get_archive(self, name):
|
||||
@@ -375,8 +377,9 @@ class SshBorgRepository(BorgRepository):
|
||||
if key not in self.KNOWN_CREDENTIALS:
|
||||
raise ValueError('Unknown credentials entry: %s' % key)
|
||||
|
||||
arguments += self._get_encryption_arguments(self.credentials)
|
||||
return self._run('backups', arguments, superuser=superuser)
|
||||
input_data = json.dumps(self._get_encryption_data(self.credentials))
|
||||
return self._run('backups', arguments, superuser=superuser,
|
||||
input=input_data.encode())
|
||||
|
||||
|
||||
def get_ssh_repositories():
|
||||
|
||||
@@ -146,10 +146,7 @@ def _append_borg_arguments(arguments, credentials):
|
||||
kwargs = {}
|
||||
passphrase = credentials.get('encryption_passphrase', None)
|
||||
if passphrase:
|
||||
arguments += ['--encryption-passphrase', passphrase]
|
||||
|
||||
if 'ssh_password' in credentials and credentials['ssh_password']:
|
||||
kwargs['input'] = credentials['ssh_password'].encode()
|
||||
kwargs['input'] = json.dumps({'encryption_passphrase': passphrase})
|
||||
|
||||
if 'ssh_keyfile' in credentials and credentials['ssh_keyfile']:
|
||||
arguments += ['--ssh-keyfile', credentials['ssh_keyfile']]
|
||||
|
||||
Reference in new issue
Block a user