diff --git a/apps/authentication/migrations/0009_connectiontoken_input_secret_type.py b/apps/authentication/migrations/0009_connectiontoken_input_secret_type.py new file mode 100644 index 000000000..045273f99 --- /dev/null +++ b/apps/authentication/migrations/0009_connectiontoken_input_secret_type.py @@ -0,0 +1,18 @@ +# Generated by Django 5.2.13 on 2026-06-03 02:54 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('authentication', '0008_alter_accesskey_secret_alter_temptoken_secret'), + ] + + operations = [ + migrations.AddField( + model_name='connectiontoken', + name='input_secret_type', + field=models.CharField(blank=True, default='password', max_length=16, verbose_name='Input secret type'), + ), + ] diff --git a/apps/authentication/serializers/connection_token.py b/apps/authentication/serializers/connection_token.py index c7b9fc313..c230841b7 100644 --- a/apps/authentication/serializers/connection_token.py +++ b/apps/authentication/serializers/connection_token.py @@ -26,7 +26,7 @@ class ConnectionTokenSerializer(OrgResourceModelSerializerMixin): model = ConnectionToken fields_mini = ['id', 'value'] fields_small = fields_mini + [ - 'user', 'asset', 'account', 'input_username', 'input_secret', + 'user', 'asset', 'account', 'input_username', 'input_secret', 'input_secret_type', 'connect_method', 'connect_options', 'protocol', 'actions', 'is_active', 'is_reusable', 'from_ticket', 'from_ticket_info', 'date_expired', 'date_created', 'date_updated', 'created_by', diff --git a/apps/common/utils/crypto/gm.py b/apps/common/utils/crypto/gm.py index 9f6f249a5..a868b2701 100644 --- a/apps/common/utils/crypto/gm.py +++ b/apps/common/utils/crypto/gm.py @@ -3,6 +3,7 @@ import base64 from django.conf import settings from gmssl.sm4 import CryptSM4, SM4_ENCRYPT, SM4_DECRYPT from gmssl import sm2, sm3, func +import logging from common.sdk.gm import Device from .base import BaseCrypto, BaseCryptoSuite @@ -108,9 +109,13 @@ class GmCryptoSuite(BaseCryptoSuite): return cipher_text def decrypt_with_key_pair(self, cipher_text, private_key): - message = base64.b64decode(cipher_text.encode()) - sm2_crypt = sm2.CryptSM2(public_key='', private_key=private_key) - return sm2_crypt.decrypt(message).decode() + try: + message = base64.b64decode(cipher_text.encode()) + sm2_crypt = sm2.CryptSM2(public_key='', private_key=private_key) + return sm2_crypt.decrypt(message).decode() + except Exception as e: + logging.error(f"Decrypt with key pair error: {e}") + return cipher_text def hash(self, msg): return Sm3Hasher.hash(msg)