Commit de0fda1a by Sheng

Call lookup_hostname only under reject policy

parent 33703f0c
...@@ -152,16 +152,6 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler): ...@@ -152,16 +152,6 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
raise InvalidValueError('Invalid hostname: {}'.format(value)) raise InvalidValueError('Invalid hostname: {}'.format(value))
return value return value
def lookup_hostname(self, hostname, port):
if isinstance(self.policy, paramiko.RejectPolicy):
key = hostname if port == 22 else '[{}]:{}'.format(hostname, port)
if self.ssh_client._system_host_keys.lookup(key) is None:
if self.ssh_client._host_keys.lookup(key) is None:
raise ValueError(
'Connection to {}:{} is not allowed.'.format(
hostname, port)
)
def get_port(self): def get_port(self):
value = self.get_value('port') value = self.get_value('port')
try: try:
...@@ -174,16 +164,28 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler): ...@@ -174,16 +164,28 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
raise InvalidValueError('Invalid port: {}'.format(value)) raise InvalidValueError('Invalid port: {}'.format(value))
def lookup_hostname(self, hostname, port):
key = hostname if port == 22 else '[{}]:{}'.format(hostname, port)
if self.ssh_client._system_host_keys.lookup(key) is None:
if self.ssh_client._host_keys.lookup(key) is None:
raise ValueError(
'Connection to {}:{} is not allowed.'.format(
hostname, port)
)
def get_args(self): def get_args(self):
hostname = self.get_hostname() hostname = self.get_hostname()
port = self.get_port() port = self.get_port()
if isinstance(self.policy, paramiko.RejectPolicy):
self.lookup_hostname(hostname, port) self.lookup_hostname(hostname, port)
username = self.get_value('username') username = self.get_value('username')
password = self.get_argument('password', u'') password = self.get_argument('password', u'')
privatekey = self.get_privatekey() privatekey = self.get_privatekey()
if privatekey: if privatekey:
pkey = self.get_pkey_obj(privatekey, password, pkey = self.get_pkey_obj(
self.privatekey_filename) privatekey, password, self.privatekey_filename
)
else: else:
pkey = None pkey = None
args = (hostname, port, username, password, pkey) args = (hostname, port, username, password, pkey)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment