Commit 801a1e84 authored by ibuler's avatar ibuler

[Bugfix] 修复组越界异常和ssh key问题

parent 45a9193a
...@@ -173,12 +173,17 @@ class InteractiveServer: ...@@ -173,12 +173,17 @@ class InteractiveServer:
line = header + '{0.comment:%s}' % (comment_length//2) # comment中可能有中文 line = header + '{0.comment:%s}' % (comment_length//2) # comment中可能有中文
header += "{0.comment:%s}" % comment_length header += "{0.comment:%s}" % comment_length
self.client.send(title(header.format(fake_group, "ID"))) self.client.send(title(header.format(fake_group, "ID")))
for index, group in enumerate(self.asset_groups): for index, group in enumerate(self.asset_groups, 1):
self.client.send(wr(line.format(group, index))) self.client.send(wr(line.format(group, index)))
self.client.send(wr(_("Total: {}").format(len(self.asset_groups)), before=1)) self.client.send(wr(_("Total: {}").format(len(self.asset_groups)), before=1))
def display_group_assets(self, _id): def display_group_assets(self, _id):
self.search_result = self.asset_groups[_id].assets_granted if _id > len(self.asset_groups) or _id <= 0:
self.client.send(wr(warning("Not match group, select again")))
self.display_asset_groups()
return
self.search_result = self.asset_groups[_id-1].assets_granted
self.display_search_result() self.display_search_result()
def display_search_result(self): def display_search_result(self):
......
...@@ -12,7 +12,8 @@ import paramiko ...@@ -12,7 +12,8 @@ import paramiko
from .session import Session from .session import Session
from .models import Server from .models import Server
from .utils import wrap_with_line_feed as wr, wrap_with_warning as warning from .utils import wrap_with_line_feed as wr, wrap_with_warning as warning, \
get_private_key_fingerprint
logger = logging.getLogger(__file__) logger = logging.getLogger(__file__)
...@@ -92,16 +93,22 @@ class ProxyServer: ...@@ -92,16 +93,22 @@ class ProxyServer:
timeout=TIMEOUT, compress=True, auth_timeout=10, timeout=TIMEOUT, compress=True, auth_timeout=10,
look_for_keys=False look_for_keys=False
) )
except paramiko.AuthenticationException: except (paramiko.AuthenticationException, paramiko.BadAuthenticationType):
admins = self.app.config['ADMINS'] or 'administrator' admins = self.app.config['ADMINS'] or 'administrator'
self.client.send(warning(wr( self.client.send(warning(wr(
"Authenticate with server failed, contact {}".format(admins), "Authenticate with server failed, contact {}".format(admins),
before=1, after=0 before=1, after=0
))) )))
key_fingerprint = system_user.private_key.get_hex() if system_user.private_key else None password_short = "None"
key_fingerprint = "None"
if system_user.password:
password_short = system_user.password[:5] + (len(system_user.password)-5) * '*'
if system_user.private_key:
key_fingerprint = get_private_key_fingerprint(system_user.private_key)
logger.error("Connect {}@{}:{} auth failed, password: {}, key: {}".format( logger.error("Connect {}@{}:{} auth failed, password: {}, key: {}".format(
system_user.username, asset.ip, asset.port, system_user.username, asset.ip, asset.port,
system_user.password, key_fingerprint, password_short, key_fingerprint,
)) ))
return None return None
except socket.error as e: except socket.error as e:
......
...@@ -14,6 +14,7 @@ import time ...@@ -14,6 +14,7 @@ import time
import datetime import datetime
import gettext import gettext
from io import StringIO from io import StringIO
from binascii import hexlify
import paramiko import paramiko
import pyte import pyte
...@@ -26,16 +27,15 @@ from .exception import NoAppException ...@@ -26,16 +27,15 @@ from .exception import NoAppException
BASE_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) BASE_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
def ssh_key_string_to_obj(text): def ssh_key_string_to_obj(text, password=None):
key_f = StringIO(text)
key = None key = None
try: try:
key = paramiko.RSAKey.from_private_key(key_f) key = paramiko.RSAKey.from_private_key(StringIO(text), password=password)
except paramiko.SSHException: except paramiko.SSHException:
pass pass
try: try:
key = paramiko.DSSKey.from_private_key(key_f) key = paramiko.DSSKey.from_private_key(StringIO(text), password=password)
except paramiko.SSHException: except paramiko.SSHException:
pass pass
return key return key
...@@ -357,6 +357,11 @@ def _gettext(): ...@@ -357,6 +357,11 @@ def _gettext():
return gettext.gettext return gettext.gettext
def get_private_key_fingerprint(key):
line = hexlify(key.get_fingerprint())
return b':'.join([line[i:i+2] for i in range(0, len(line), 2)])
def make_message(): def make_message():
os.makedirs(os.path.join(BASE_DIR, "locale", "zh_CN")) os.makedirs(os.path.join(BASE_DIR, "locale", "zh_CN"))
pass pass
......
___
|_ |
| |_ _ _ __ ___ _ __ ___ ___ _ ____ _____ _ __
| | | | | '_ ` _ \| '_ \/ __|/ _ \ '__\ \ / / _ \ '__|
/\__/ / |_| | | | | | | |_) \__ \ __/ | \ V / __/ |
\____/ \__,_|_| |_| |_| .__/|___/\___|_| \_/ \___|_|
| |
|_|
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