Verify SSH hostkey before mounting

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
Joseph Nuthalapati committed 2019-07-03 12:42:41 +05:30
1 parent 7684814a5c
commit 3a6dcbe7a7
8 files changed
+146 -120

No files matched your search

+14
View File
@@ -21,6 +21,7 @@ FreedomBox app to manage backup archives.
import json
import os
import paramiko
from django.utils.text import get_valid_filename
from django.utils.translation import ugettext_lazy as _
@@ -142,3 +143,16 @@ def restore_from_upload(path, apps=None):
"""Restore files from an uploaded .tar.gz backup file"""
api.restore_apps(_restore_exported_archive_handler, app_names=apps,
create_subvolume=False, backup_file=path)
def is_ssh_hostkey_verified(hostname):
"""Check whether SSH Hostkey has already been verified.
hostname: Domain name or IP address of the host
"""
known_hosts_path = os.path.join(cfg.data_dir, '.ssh', 'known_hosts')
if not os.path.exists(known_hosts_path):
return False
known_hosts = paramiko.hostkeys.HostKeys(known_hosts_path)
host_keys = known_hosts.lookup(hostname)
return host_keys is not None