From e12147f5b9ef2a0a68a8aed5b060d380cd3be477 Mon Sep 17 00:00:00 2001 From: Lynn Date: Thu, 19 Mar 2026 17:06:54 +0800 Subject: [PATCH] Fix: admin client (#13699) ### What problem does this PR solve? Define a crypt function in admin directory, remove import from api.utils. And move requests-toolbelt to dependency. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- admin/client/pyproject.toml | 2 +- admin/client/user.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/admin/client/pyproject.toml b/admin/client/pyproject.toml index 1b79c85c3..d2af4bb6c 100644 --- a/admin/client/pyproject.toml +++ b/admin/client/pyproject.toml @@ -11,13 +11,13 @@ dependencies = [ "beartype>=0.20.0,<1.0.0", "pycryptodomex>=3.10.0", "lark>=1.1.0", + "requests-toolbelt>=1.0.0", ] [dependency-groups] test = [ "pytest>=8.3.5", "requests>=2.32.3", - "requests-toolbelt>=1.0.0", ] [tool.setuptools] diff --git a/admin/client/user.py b/admin/client/user.py index 823e2a130..6e6a36eee 100644 --- a/admin/client/user.py +++ b/admin/client/user.py @@ -26,7 +26,19 @@ class AuthException(Exception): def encrypt_password(password_plain: str) -> str: try: - from api.utils.crypt import crypt + import base64 + from Cryptodome.PublicKey import RSA + from Cryptodome.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5 + def crypt(line): + """ + decrypt(crypt(input_string)) == base64(input_string), which frontend and ragflow_cli use. + """ + pub = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArq9XTUSeYr2+N1h3Afl/z8Dse/2yD0ZGrKwx+EEEcdsBLca9Ynmx3nIB5obmLlSfmskLpBo0UACBmB5rEjBp2Q2f3AG3Hjd4B+gNCG6BDaawuDlgANIhGnaTLrIqWrrcm4EMzJOnAOI1fgzJRsOOUEfaS318Eq9OVO3apEyCCt0lOQK6PuksduOjVxtltDav+guVAA068NrPYmRNabVKRNLJpL8w4D44sfth5RvZ3q9t+6RTArpEtc5sh5ChzvqPOzKGMXW83C95TxmXqpbK6olN4RevSfVjEAgCydH6HN6OhtOQEcnrU97r9H0iZOWwbw3pVrZiUkuRD1R56Wzs2wIDAQAB\n-----END PUBLIC KEY-----" + rsa_key = RSA.importKey(pub) + cipher = Cipher_pkcs1_v1_5.new(rsa_key) + password_base64 = base64.b64encode(line.encode('utf-8')).decode("utf-8") + encrypted_password = cipher.encrypt(password_base64.encode()) + return base64.b64encode(encrypted_password).decode('utf-8') except Exception as exc: raise AuthException( "Password encryption unavailable; install pycryptodomex (uv sync --python 3.12 --group test)."