Exemple #1
0
    def test_connective(self, local_port=None):
        if local_port is None:
            local_port = self.port
        if self.password and not no_special_chars(self.password):
            return False, _("Password should not contains special characters")

        client = paramiko.SSHClient()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        proxy = paramiko.SSHClient()
        proxy.set_missing_host_key_policy(paramiko.AutoAddPolicy())

        try:
            proxy.connect(self.ip, port=self.port,
                          username=self.username,
                          password=self.password,
                          pkey=self.private_key_obj)
        except(paramiko.AuthenticationException,
               paramiko.BadAuthenticationType,
               paramiko.SSHException,
               paramiko.ssh_exception.NoValidConnectionsError) as e:
            return False, str(e)

        try:
            sock = proxy.get_transport().open_channel(
                'direct-tcpip', ('127.0.0.1', local_port), ('127.0.0.1', 0)
            )
            client.connect("127.0.0.1", port=local_port,
                           username=self.username,
                           password=self.password,
                           key_filename=self.private_key_file,
                           sock=sock,
                           timeout=5)
        except (paramiko.SSHException, paramiko.ssh_exception.SSHException,
                paramiko.AuthenticationException, TimeoutError) as e:
            return False, str(e)
        finally:
            client.close()
        return True, None
Exemple #2
0
 def __call__(self, value):
     if not no_special_chars(value):
         raise serializers.ValidationError(
             _("Should not contains special characters"))