def test_getSshKeyFingerprint(self): self.assertIsNone(tools.getSshKeyFingerprint(os.path.abspath(__file__))) with TemporaryDirectory() as d: key = os.path.join(d, 'key') cmd = ['ssh-keygen', '-q', '-N', '', '-f', key] proc = subprocess.Popen(cmd) proc.communicate() fingerprint = tools.getSshKeyFingerprint(key) self.assertIsInstance(fingerprint, str) self.assertRegex(fingerprint, r'^[a-fA-F0-9:]+$')
def test_getSshKeyFingerprint(self): self.assertIsNone(tools.getSshKeyFingerprint(os.path.abspath(__file__))) with TemporaryDirectory() as d: key = os.path.join(d, 'key') cmd = ['ssh-keygen', '-q', '-N', '', '-f', key] proc = subprocess.Popen(cmd) proc.communicate() fingerprint = tools.getSshKeyFingerprint(key) self.assertIsInstance(fingerprint, str) if fingerprint.startswith('SHA256'): self.assertEqual(len(fingerprint), 50) self.assertRegex(fingerprint, r'^SHA256:[a-zA-Z0-9/+]+$') else: self.assertEqual(len(fingerprint), 47) self.assertRegex(fingerprint, r'^[a-fA-F0-9:]+$')
def __init__(self, *args, **kwargs): #init MountControl super(SSH, self).__init__(*args, **kwargs) self.setattr_kwargs('user', self.config.get_ssh_user(self.profile_id), **kwargs) self.setattr_kwargs('host', self.config.get_ssh_host(self.profile_id), **kwargs) self.setattr_kwargs('port', self.config.get_ssh_port(self.profile_id), **kwargs) self.setattr_kwargs('path', self.config.get_snapshots_path_ssh(self.profile_id), **kwargs) self.setattr_kwargs('cipher', self.config.get_ssh_cipher(self.profile_id), **kwargs) self.setattr_kwargs('private_key_file', self.config.get_ssh_private_key_file(self.profile_id), **kwargs) self.setattr_kwargs('nice', self.config.is_run_nice_on_remote_enabled(self.profile_id), store = False, **kwargs) self.setattr_kwargs('ionice', self.config.is_run_ionice_on_remote_enabled(self.profile_id), store = False, **kwargs) self.setattr_kwargs('nocache', self.config.is_run_nocache_on_remote_enabled(self.profile_id), store = False, **kwargs) self.setattr_kwargs('password', None, store = False, **kwargs) if not self.path: self.path = './' self.set_default_args() # config strings used in ssh-calls self.user_host_path = '%s@%s:%s' % (self.user, self.host, self.path) self.user_host = '%s@%s' % (self.user, self.host) # ssh_options contains port but can be extended to include cipher, customkeyfile, etc self.ssh_options = ['-p', str(self.port)] self.ssh_options += ['-o', 'ServerAliveInterval=240'] # specifying key file here allows to override for potentially # conflicting .ssh/config key entry self.ssh_options += ['-o', 'IdentityFile=%s' % self.private_key_file] self.mountproc = 'sshfs' self.symlink_subfolder = None self.log_command = '%s: %s' % (self.mode, self.user_host_path) self.private_key_fingerprint = tools.getSshKeyFingerprint(self.private_key_file) if not self.private_key_fingerprint: logger.warning('Couldn\'t get fingerprint for private key %(path)s. ' 'Most likely because the public key %(path)s.pub wasn\'t found. ' 'Using fallback to private keys path instead. ' 'But this can make troubles with passphrase-less keys.' %{'path': self.private_key_file}, self) self.private_key_fingerprint = self.private_key_file self.unlock_ssh_agent()
def __init__(self, cfg = None, profile_id = None, hash_id = None, tmp_mount = False, parent = None, symlink = True, **kwargs): self.config = cfg if self.config is None: self.config = config.Config() self.profile_id = profile_id if self.profile_id is None: self.profile_id = self.config.get_current_profile() self.tmp_mount = tmp_mount self.hash_id = hash_id self.parent = parent self.symlink = symlink #init MountControl super(SSH, self).__init__() self.all_kwargs = {} #First we need to map the settings. self.setattr_kwargs('mode', self.config.get_snapshots_mode(self.profile_id), **kwargs) self.setattr_kwargs('hash_collision', self.config.get_hash_collision(), **kwargs) #start editing from here--------------------------------------------------------- self.setattr_kwargs('user', self.config.get_ssh_user(self.profile_id), **kwargs) self.setattr_kwargs('host', self.config.get_ssh_host(self.profile_id), **kwargs) self.setattr_kwargs('port', self.config.get_ssh_port(self.profile_id), **kwargs) self.setattr_kwargs('path', self.config.get_snapshots_path_ssh(self.profile_id), **kwargs) self.setattr_kwargs('cipher', self.config.get_ssh_cipher(self.profile_id), **kwargs) self.setattr_kwargs('private_key_file', self.config.get_ssh_private_key_file(self.profile_id), **kwargs) self.setattr_kwargs('nice', self.config.is_run_nice_on_remote_enabled(self.profile_id), store = False, **kwargs) self.setattr_kwargs('ionice', self.config.is_run_ionice_on_remote_enabled(self.profile_id), store = False, **kwargs) self.setattr_kwargs('nocache', self.config.is_run_nocache_on_remote_enabled(self.profile_id), store = False, **kwargs) self.setattr_kwargs('password', None, store = False, **kwargs) if not self.path: self.path = './' self.set_default_args() self.symlink_subfolder = None # config strings used in ssh-calls self.user_host_path = '%s@%s:%s' % (self.user, self.host, self.path) self.user_host = '%s@%s' % (self.user, self.host) # ssh_options contains port but can be extended to include cipher, customkeyfile, etc self.ssh_options = ['-p', str(self.port)] self.ssh_options += ['-o', 'ServerAliveInterval=240'] # specifying key file here allows to override for potentially # conflicting .ssh/config key entry self.ssh_options += ['-o', 'IdentityFile=%s' % self.private_key_file] self.log_command = '%s: %s' % (self.mode, self.user_host_path) self.private_key_fingerprint = tools.getSshKeyFingerprint(self.private_key_file) if not self.private_key_fingerprint: logger.warning('Couldn\'t get fingerprint for private key %(path)s. ' 'Most likely because the public key %(path)s.pub wasn\'t found. ' 'Using fallback to private keys path instead. ' 'But this can make troubles with passphrase-less keys.' %{'path': self.private_key_file}, self) self.private_key_fingerprint = self.private_key_file self.unlock_ssh_agent()