From 54d3668093bdc09ca2d0a98f28f96320552ef0c3 Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Wed, 17 Sep 2025 09:00:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=99=A8=E5=87=AD=E8=AF=81=E8=AE=A4=E8=AF=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=9A=E6=94=AF=E6=8C=81=E5=8A=A0=E5=AF=86=E5=87=AD?= =?UTF-8?q?=E8=AF=81=E5=92=8C=E6=96=B0=E5=AF=86=E9=92=A5=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 主要修复: - 导入 EncryptedDBOperations 支持加密凭证解密 - 优先使用 privateKey 字段,向后兼容 key 字段 - 统一凭证解析逻辑与终端保持一致 - 修复日志信息格式 这解决了使用凭证的SSH主机在文件管理器中无法认证的核心问题。 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/backend/ssh/file-manager.ts | 50 ++++++++++++++------------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/src/backend/ssh/file-manager.ts b/src/backend/ssh/file-manager.ts index 63f11b57..e932976c 100644 --- a/src/backend/ssh/file-manager.ts +++ b/src/backend/ssh/file-manager.ts @@ -5,6 +5,7 @@ import { db } from "../database/db/index.js"; import { sshCredentials } from "../database/db/schema.js"; import { eq, and } from "drizzle-orm"; import { fileLogger } from "../utils/logger.js"; +import { EncryptedDBOperations } from "../utils/encrypted-db-operations.js"; // 可执行文件检测工具函数 function isExecutableFile(permissions: string, fileName: string): boolean { @@ -104,56 +105,47 @@ app.post("/ssh/file_manager/ssh/connect", async (req, res) => { let resolvedCredentials = { password, sshKey, keyPassword, authType }; if (credentialId && hostId && userId) { try { - const credentials = await db - .select() - .from(sshCredentials) - .where( + const credentials = await EncryptedDBOperations.select( + db.select().from(sshCredentials).where( and( eq(sshCredentials.id, credentialId), eq(sshCredentials.userId, userId), ), - ); + ), + 'ssh_credentials' + ); if (credentials.length > 0) { const credential = credentials[0]; resolvedCredentials = { password: credential.password, - sshKey: credential.key, + sshKey: credential.privateKey || credential.key, // prefer new privateKey field keyPassword: credential.keyPassword, authType: credential.authType, }; } else { - fileLogger.warn("No credentials found in database for file manager", { - operation: "file_connect", - sessionId, + fileLogger.warn(`No credentials found for host ${hostId}`, { + operation: "ssh_credentials", hostId, credentialId, userId, }); } } catch (error) { - fileLogger.warn( - "Failed to resolve credentials from database for file manager", - { - operation: "file_connect", - sessionId, - hostId, - credentialId, - error: error instanceof Error ? error.message : "Unknown error", - }, - ); - } - } else if (credentialId && hostId) { - fileLogger.warn( - "Missing userId for credential resolution in file manager", - { - operation: "file_connect", - sessionId, + fileLogger.warn(`Failed to resolve credentials for host ${hostId}`, { + operation: "ssh_credentials", hostId, credentialId, - hasUserId: !!userId, - }, - ); + error: error instanceof Error ? error.message : "Unknown error", + }); + } + } else if (credentialId && hostId) { + fileLogger.warn("Missing userId for credential resolution in file manager", { + operation: "ssh_credentials", + hostId, + credentialId, + hasUserId: !!userId, + }); } const config: any = {