修复文件管理器凭证认证问题:支持加密凭证和新密钥字段
主要修复: - 导入 EncryptedDBOperations 支持加密凭证解密 - 优先使用 privateKey 字段,向后兼容 key 字段 - 统一凭证解析逻辑与终端保持一致 - 修复日志信息格式 这解决了使用凭证的SSH主机在文件管理器中无法认证的核心问题。 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user