Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(remote-desktop): authenticate packaged Windows helpers

Lizi3de1ac3afc86
diff --git a/apps/desktop/native/remote-desktop/windows-host/src/main.rs b/apps/desktop/native/remote-desktop/windows-host/src/main.rs
index ccb6c8882a..59ac03f5f2 100644
--- a/apps/desktop/native/remote-desktop/windows-host/src/main.rs
+++ b/apps/desktop/native/remote-desktop/windows-host/src/main.rs
@@ -144,8 +144,13 @@ fn run() -> Staged<()> {
} else {
bundled()?
};
- let (_main, _) = security::authorize_client(pid, &installation.install, development)
+ let (main, _) = security::authorize_client(pid, &installation.install, development)
.stage(Step::ClientIdentity)?;
+ let trusted_main = if development {
+ None
+ } else {
+ Some(image(main.0).stage(Step::ClientIdentity)?)
+ };
service::elevate(
&installation,
&[
@@ -157,11 +162,12 @@ fn run() -> Staged<()> {
String::new()
},
][..if development { 3 } else { 2 }],
+ trusted_main.as_deref(),
)
}
Some("--elevate-uninstall") => {
let installation = bundled()?;
- service::elevate(&installation, &["--uninstall-from".to_owned()])
+ service::elevate(&installation, &["--uninstall-from".to_owned()], None)
}
Some("--status") => {
let status = match bundled() {
diff --git a/apps/desktop/native/remote-desktop/windows-host/src/service.rs b/apps/desktop/native/remote-desktop/windows-host/src/service.rs
index 97487b2aa1..eb9939b06e 100644
--- a/apps/desktop/native/remote-desktop/windows-host/src/service.rs
+++ b/apps/desktop/native/remote-desktop/windows-host/src/service.rs
@@ -257,6 +257,7 @@ fn powershell_script(
bootstrap: &std::path::Path,
source_hash: &str,
input_hash: &str,
+ trusted_main: Option<&std::path::Path>,
child_args: &[String],
remove_staging: bool,
) -> String {
@@ -285,6 +286,11 @@ fn powershell_script(
script.push_str(
"; $inputPath=Join-Path (Split-Path -Parent $source) 'cindy-windows-desktop-input.exe';",
);
+ if let Some(main) = trusted_main {
+ script.push_str(" $main=");
+ script.push_str(&powershell_literal(&main.to_string_lossy()));
+ script.push_str("; function Get-Signer([string]$Path) { $sig=Get-AuthenticodeSignature -LiteralPath $Path; if ($sig.Status -ne 'Valid' -or $null -eq $sig.SignerCertificate) { return $null }; return $sig.SignerCertificate.Thumbprint.ToUpperInvariant() }; $mainSigner=Get-Signer $main; if ($null -eq $mainSigner) { exit 1 }; if ((Get-Signer $source) -ne $mainSigner -or (Get-Signer $inputPath) -ne $mainSigner) { exit 1 };");
+ }
script.push_str("; $bootstrapDir=Split-Path -Parent $bootstrap; $stagingRoot=Split-Path -Parent $bootstrapDir; $programFiles=Split-Path -Parent $stagingRoot;");
script.push_str(" $trusted=@('S-1-5-18','S-1-5-32-544','S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464');");
script.push_str(" $writeMask=[System.Security.AccessControl.FileSystemRights]::Write -bor [System.Security.AccessControl.FileSystemRights]::WriteData -bor [System.Security.AccessControl.FileSystemRights]::AppendData -bor [System.Security.AccessControl.FileSystemRights]::WriteAttributes -bor [System.Security.AccessControl.FileSystemRights]::WriteExtendedAttributes -bor [System.Security.AccessControl.FileSystemRights]::Delete -bor [System.Security.AccessControl.FileSystemRights]::DeleteSubdirectoriesAndFiles -bor [System.Security.AccessControl.FileSystemRights]::ChangePermissions -bor [System.Security.AccessControl.FileSystemRights]::TakeOwnership;");
@@ -313,7 +319,11 @@ fn encode_powershell(script: &str) -> String {
/// user-writable helper is copied as data, then only the copy under Program
/// Files is started elevated, so an adjacent VCRUNTIME140.dll cannot be
/// loaded from Cindy's install directory.
-pub fn elevate(installation: &Installation, child_args: &[String]) -> Staged<()> {
+pub fn elevate(
+ installation: &Installation,
+ child_args: &[String],
+ trusted_main: Option<&std::path::Path>,
+) -> Staged<()> {
let source = std::env::current_exe().stage(Step::ElevateLaunch)?;
let _source_lock = read_lock(&source).stage(Step::ElevateLaunch)?;
let _input_lock =
@@ -342,6 +352,7 @@ pub fn elevate(installation: &Installation, child_args: &[String]) -> Staged<()>
&installation.bootstrap(),
&source_hash,
&input_hash,
+ trusted_main,
&child_args,
remove_staging,
);
@@ -998,6 +1009,7 @@ mod tests {
),
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
"fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210",
+ Some(Path::new(r"C:\Program Files\Cindy\Cindy.exe")),
&args,
false,
);
diff --git a/apps/desktop/native/remote-desktop/windows-host/src/staging.rs b/apps/desktop/native/remote-desktop/windows-host/src/staging.rs
index 7241ff542c..7c55165e39 100644
--- a/apps/desktop/native/remote-desktop/windows-host/src/staging.rs
+++ b/apps/desktop/native/remote-desktop/windows-host/src/staging.rs
@@ -15,13 +15,12 @@
//! * It removes the standing risk. After setup, no ordinary process can reach
//! the executable the service starts, so there is no unprompted path to
//! SYSTEM.
-//! * It does not make the one-time elevation itself trustworthy. The copy is
-//! made by this executable, which was launched from the installation
-//! directory and elevated by the user's confirmation. Anything that could
-//! already replace files there could have replaced this one too, and
-//! verifying our own signature from inside the same executable would prove
-//! nothing. That exposure is the same one the Cindy updater already accepts
-//! when it elevates to write into a protected directory.
+//! * Packaged setup additionally checks that the host and input helpers carry
+//! the same valid Authenticode signer as the running Cindy executable before
+//! the elevated copy is made. Source-mode setup deliberately uses a separate
+//! development trust boundary: an unsigned Electron runtime and its locally
+//! built helpers are accepted only when the explicit development flag is
+//! present.
use crate::naming::*;
use crate::security;
use crate::win::*;
diff --git a/apps/desktop/src/main/remote-desktop/__tests__/windowsLockScreenSetup.test.ts b/apps/desktop/src/main/remote-desktop/__tests__/windowsLockScreenSetup.test.ts
index 9216e4e49f..b8b7f0b6b8 100644
--- a/apps/desktop/src/main/remote-desktop/__tests__/windowsLockScreenSetup.test.ts
+++ b/apps/desktop/src/main/remote-desktop/__tests__/windowsLockScreenSetup.test.ts
@@ -98,7 +98,11 @@ describe('windows lock-screen setup diagnostics', () => {
it('does not compile source helpers during a status-only read', async () => {
electronApp.isPackaged = false;
- electronApp.getAppPath.mockReturnValue(path.join(process.cwd(), 'apps', 'desktop'));
+ electronApp.getAppPath.mockReturnValue(
+ path.basename(process.cwd()).toLowerCase() === 'desktop'
+ ? process.cwd()
+ : path.join(process.cwd(), 'apps', 'desktop'),
+ );
electronApp.getPath.mockReturnValue(
path.join(os.tmpdir(), `cindy-lock-screen-status-${process.pid}`),
);
diff --git a/docs/remote-desktop.md b/docs/remote-desktop.md
index 478ef28850..a71f7b6f33 100644
--- a/docs/remote-desktop.md
+++ b/docs/remote-desktop.md
@@ -1049,8 +1049,13 @@ user-writable, so the Cindy.exe check against it is a consistency check; what
actually gates the service is the approved process handle and the active console
session.
-The broker validates file/directory ownership, writable ACLs, reparse points,
-SCM identity, peer PIDs and active console session over the staged directory and
+Packaged setup checks that the host and input helpers have a valid Authenticode
+signature from the same signer as the running Cindy executable. Source-mode
+development setup uses an explicit unsigned development trust boundary; it is
+intended for a developer-controlled checkout and does not claim publisher
+provenance. In both modes the broker validates file/directory ownership, writable
+ACLs, reparse points, SCM identity, peer PIDs and active console session over the
+staged directory and
its parents up to Program Files, and retains those handles for its lifetime.
Workers are fixed-purpose children in kill-on-close jobs
with local-only, bounded, timed pipes. Uninstall/upgrade waits for the service to