From a80ca8e7eb5302af25852a19acfc27977c6dc1f4 Mon Sep 17 00:00:00 2001 From: jackie_cqz <88996311+jackie-cqz@users.noreply.github.com> Date: Wed, 2 Dec 2026 01:21:51 +0800 Subject: [PATCH 1/2] feat(desktop): add per-connection CA trust --- desktop/README.md | 2 + desktop/README.zh.md | 2 + desktop/ui/src/app/Overview.tsx | 94 +++++++++++++++++--- desktop/ui/tests/app.test.tsx | 146 ++++++++++++++++++++++++++++++++ 4 files changed, 233 insertions(+), 11 deletions(-) diff --git a/desktop/README.md b/desktop/README.md index aa78d00ea4..674a53eabd 100644 --- a/desktop/README.md +++ b/desktop/README.md @@ -63,6 +63,8 @@ The unsigned installer is for internal verification. If WebView2 is absent, its Choose **Connect an existing service** on Home or in **Services & Agents**. Enter the service address and choose its authentication mode. Use HTTPS for remote services and a literal loopback address for local HTTP. Choose a [verified compatibility profile](src-tauri/src/connections/compatibility.json) that matches the Server deployment. Bearer credentials can stay in the system vault or be limited to the current session. +For a new HTTPS connection to a service that uses a private CA, open **Advanced settings** and paste the PEM CA certificate from your administrator. Desktop trusts the certificate alongside system certificates for this connection and still verifies the hostname. Leave the field empty to use the system trust store alone. + Confirm the connection, then use the space menu in the top bar to select an authorized space. The Desktop application verifies the target and credentials before enabling qualified operations. ## Save, search, and read a memory diff --git a/desktop/README.zh.md b/desktop/README.zh.md index a756b0bb81..0684e5d9a8 100644 --- a/desktop/README.zh.md +++ b/desktop/README.zh.md @@ -51,6 +51,8 @@ pnpm --dir desktop desktop:dev 从首页选择「已有服务」,或在「服务与 Agent」打开连接对话框。填写服务地址并选择认证方式。远程服务使用 HTTPS,本机 HTTP 使用字面回环地址。选择与部署匹配的[已验证兼容配置](src-tauri/src/connections/compatibility.json)。Bearer 凭据可保存在系统凭据库,也可仅用于本次会话。 +如果要新建 HTTPS 连接,且服务使用私有 CA,请打开「高级设置」并粘贴管理员提供的 PEM 格式 CA 证书。Desktop 仅在此连接中额外信任该证书,并继续校验主机名。留空时仅使用系统信任库。 + 确认连接后,在顶部空间菜单选择可访问的空间。桌面端核对目标和凭据,通过对应资格校验的操作才可使用。 ## 显式就绪探测与连接身份 diff --git a/desktop/ui/src/app/Overview.tsx b/desktop/ui/src/app/Overview.tsx index 21be46213b..d98fe4dbbe 100644 --- a/desktop/ui/src/app/Overview.tsx +++ b/desktop/ui/src/app/Overview.tsx @@ -36,7 +36,11 @@ import { contractSha256 } from "../generated/operations"; import { desktopApi } from "../shared/ipc"; import { messages, type Language } from "./messages"; import { activeCheckReport, refreshConnectionState } from "./context"; -import { connectionError, connectionMessages } from "./connection-messages"; +import { + connectionError, + connectionErrorCode, + connectionMessages, +} from "./connection-messages"; import { PageFeedback } from "@/components/ui/feedback"; import { Dialog, @@ -57,6 +61,7 @@ import { Button } from "@/components/ui/button"; import { PageActionButton } from "@/components/ui/page-action-button"; import { ActionNotification } from "@/components/ui/action-notification"; import { Input } from "@/components/ui/input"; +import { Textarea } from "@/components/ui/textarea"; import { Select, SelectContent, @@ -68,6 +73,7 @@ import { Bot, CircleCheck, Check, + ChevronDown, Copy, Eye, EyeOff, @@ -801,10 +807,18 @@ export function QuickConnectDialog({ const [storage, setStorage] = useState("persistent"); const [savedProfile, setSavedProfile] = useState(null); const [credentialVisible, setCredentialVisible] = useState(false); + const [advancedOpen, setAdvancedOpen] = useState(false); + const [caPem, setCaPem] = useState(""); const [submitted, setSubmitted] = useState(false); const zh = language === "zh"; const t = connectionMessages[language]; const dialogTitle = title ?? (zh ? "连接服务" : "Connect service"); + const supportsCustomCa = + !preview && endpoint.trim().toLowerCase().startsWith("https://"); + const certificateError = + supportsCustomCa && + advancedOpen && + connectionErrorCode(error) === "invalid_certificate"; const duplicate = state?.profiles.some( (profile) => profile.id !== savedProfile?.id && profile.name.trim() === name.trim(), @@ -863,7 +877,7 @@ export function QuickConnectDialog({ name: name.trim(), endpoint: endpoint.trim(), authentication, - caPem: null, + caPem: supportsCustomCa && caPem.trim() ? caPem : null, compatibility, keepCredential: false, credential: requiresCredential ? { secret: credential, storage } : null, @@ -874,21 +888,26 @@ export function QuickConnectDialog({ if (!profile) throw { code: "not_found" }; setSavedProfile(profile); const checked = await desktopApi.check(profile.id, true); - if ( - checked.active?.connectionId !== profile.id || - !checked.active.report.compatibilityVerified - ) + const active = checked.active; + if (active?.connectionId !== profile.id) throw { code: "compatibility_unverified" }; - const defaultScope = await desktopApi.defaultScope( - checked.active.generation, - ); + if (!active.report.compatibilityVerified) { + const failure = active.report.liveness.error; + throw failure?.code === "tls" + ? failure + : { code: "compatibility_unverified" }; + } + const defaultScope = await desktopApi.defaultScope(active.generation); const selected = await desktopApi.selectScope( - checked.active.generation, + active.generation, defaultScope.scope_id, ); onState(selected); onConnected(); } catch (cause) { + if (connectionErrorCode(cause) === "invalid_certificate") { + setAdvancedOpen(true); + } setError(cause); if (!preview) await refreshConnectionState(onState); } finally { @@ -911,7 +930,7 @@ export function QuickConnectDialog({ - {error != null && ( + {error != null && !certificateError && ( )} + {supportsCustomCa && ( +
+ +