From 052a4afef601ce3b814927e4a9b7d578e5dce55c Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 2 Dec 2022 20:06:56 +0800 Subject: [PATCH] =?UTF-8?q?pref:=20=E6=9A=82=E6=97=B6=E4=BF=AE=E6=94=B9=20?= =?UTF-8?q?key=20fingerprint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/models/base.py | 2 ++ apps/common/utils/encode.py | 17 +++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/apps/assets/models/base.py b/apps/assets/models/base.py index 30eafa6b7..3ecfd4deb 100644 --- a/apps/assets/models/base.py +++ b/apps/assets/models/base.py @@ -91,6 +91,8 @@ class BaseAccount(JMSOrgBaseModel): @property def ssh_key_fingerprint(self): + # Todo: 等待修复 + return '等待修复' if self.public_key: public_key = self.public_key elif self.private_key: diff --git a/apps/common/utils/encode.py b/apps/common/utils/encode.py index b06d96a3d..81856b931 100644 --- a/apps/common/utils/encode.py +++ b/apps/common/utils/encode.py @@ -165,8 +165,10 @@ def parse_ssh_public_key_str(text: bytes = "", password=None) -> str: private_key = _parse_ssh_private_key(text, password=password) if private_key is None: return "" - public_key_bytes = private_key.public_key().public_bytes(serialization.Encoding.OpenSSH, - serialization.PublicFormat.OpenSSH) + public_key_bytes = private_key.public_key().public_bytes( + serialization.Encoding.OpenSSH, + serialization.PublicFormat.OpenSSH, + ) return public_key_bytes.decode('utf-8') @@ -185,12 +187,11 @@ def _parse_ssh_private_key(text, password=None): text = text.encode("utf-8") except UnicodeDecodeError: return None - if password is not None: - if isinstance(password, str): - try: - password = password.encode("utf-8") - except UnicodeDecodeError: - return None + if isinstance(password, str): + try: + password = password.encode("utf-8") + except UnicodeDecodeError: + return None try: private_key = serialization.load_ssh_private_key(text, password=password)