Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

refactor(attribution): remove the installer carrier (#7794)

Louis Beaumont530cc8894c43
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/acquisition_handoff.rs b/apps/screenpipe-app-tauri/src-tauri/src/acquisition_handoff.rs
index 8d670af35..1df7f6925 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/acquisition_handoff.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/acquisition_handoff.rs
@@ -1,8 +1,9 @@
// screenpipe — AI that knows everything you've seen, said, or heard
// https://screenpipe.com
-//! Download possession -> authenticated account. Best effort, off the
-//! recording/startup path. The server owns authorization and attribution rules.
+//! Install-page deep link -> saved grant -> authenticated account. Best effort,
+//! off the recording/startup path. The server owns authorization and
+//! attribution rules; the installer itself carries nothing.
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine};
use serde::{Deserialize, Serialize};
use std::sync::atomic::{AtomicBool, Ordering};
@@ -64,21 +65,6 @@ impl Pending {
}
}
-#[cfg(target_os = "macos")]
-fn carrier() -> Option<String> {
- use std::{ffi::CString, os::unix::ffi::OsStrExt};
- let executable = std::env::current_exe().ok()?;
- let bundle = executable.ancestors().find(|p| p.extension().is_some_and(|e| e == "app"))?;
- let path = CString::new(bundle.as_os_str().as_bytes()).ok()?;
- let name = CString::new("com.apple.application-instance").ok()?;
- let mut bytes = [0u8; 36];
- // Exact-size read; absent, truncated or oversized attributes are ignored.
- let size = unsafe { libc::getxattr(path.as_ptr(), name.as_ptr(), bytes.as_mut_ptr().cast(), bytes.len(), 0, 0) };
- if size != 36 { return None; }
- let grant = String::from_utf8(bytes.to_vec()).ok()?.to_ascii_lowercase();
- uuid4(&grant).then_some(grant)
-}
-
fn storage_account(profile: &std::path::Path, origin: &str) -> String {
use sha2::{Digest, Sha256};
format!("profile-{:x}", Sha256::digest(format!("{}\n{}", profile.display(), origin).as_bytes()))
@@ -153,42 +139,8 @@ async fn persist(pending: &Pending) -> Result<(), ()> {
save(pending).await
}
-/// Download filenames carry only a random capability, never a user/source ID.
-fn grant_from_filename(name: &str, extension: &str) -> Option<String> {
- let grant = name.strip_prefix("screenpipe-")?.strip_suffix(extension)?;
- uuid4(grant).then(|| grant.to_owned())
-}
-
-#[cfg(target_os = "windows")]
-fn carrier() -> Option<String> {
- carrier_from(std::env::current_exe().ok()?.parent()?)
-}
-
-#[cfg(target_os = "windows")]
-fn carrier_from(directory: &std::path::Path) -> Option<String> {
- // The installer writes this once. Keep the read bounded so an untrusted or
- // corrupt install directory cannot turn startup into an unbounded read.
- let path = directory.join("acquisition-grant");
- let metadata = std::fs::metadata(&path).ok()?;
- if metadata.len() != 36 { return None; }
- use std::io::Read;
- let mut bytes = Vec::with_capacity(37);
- std::fs::File::open(path).ok()?.take(37).read_to_end(&mut bytes).ok()?;
- if bytes.len() != 36 { return None; }
- let grant = String::from_utf8(bytes).ok()?;
- uuid4(&grant).then_some(grant)
-}
-
-#[cfg(target_os = "linux")]
-fn carrier() -> Option<String> {
- // AppImages execute from a temporary mount; APPIMAGE is the original file.
- let path = std::path::PathBuf::from(std::env::var_os("APPIMAGE")?);
- grant_from_filename(path.file_name()?.to_str()?, ".AppImage")
-}
-
-/// `screenpipe://attribution?grant=<uuid4>`: the install page hands the same
-/// opaque grant the download carrier would have carried, after the ordinary
-/// installer is already running. No installer bytes, filenames or manifests.
+/// `screenpipe://attribution?grant=<uuid4>`: the install page hands an opaque
+/// grant to the already-installed app. No installer bytes, filenames or manifests.
pub(crate) fn grant_from_deep_link(url: &str) -> Option<String> {
if !crate::deep_link::is_for_current_build(url) { return None; }
let parsed = url.parse::<tauri::Url>().ok()?;
@@ -216,8 +168,8 @@ async fn accept(grant: String) -> Result<bool, ()> {
Ok(true)
}
-/// Deep links arrive from the OS on every platform; the worker then runs the
-/// same claim/bind path as the installer carrier.
+/// Deep links arrive from the OS on every platform; the worker then claims the
+/// grant and binds it to the verified account.
pub fn accept_deep_link(app: &AppHandle, url: &str) {
let Some(grant) = grant_from_deep_link(url) else { return; };
let app = app.clone();
@@ -322,10 +274,9 @@ fn spawn_worker(app: AppHandle) {
async fn run(app: AppHandle) -> Result<(), ()> {
if RETIREMENT.disabled(&tombstone()) { return Ok(()); }
- let mut p = match load_saved().await? {
- Some(p) => p,
- None => match carrier() { Some(grant) => Pending::new(grant), None => return Ok(()) },
- };
+ // Grants arrive only through the `screenpipe://attribution` deep link
+ // and are persisted by `accept` before this worker runs.
+ let Some(mut p) = load_saved().await? else { return Ok(()); };
if p.retired { return Ok(()); }
// Persist proof BEFORE first claim, including when its HTTP response is lost.
persist(&p).await?;
@@ -413,38 +364,6 @@ async fn send(client: &reqwest::Client, origin: &reqwest::Url, action: &str, p:
#[cfg(test)]
mod tests {
use super::*;
- #[test]
- fn portable_filenames_reject_placeholders_and_ambiguous_names() {
- let grant = "12345678-1234-4234-8234-123456789012";
- for extension in [".exe", ".AppImage"] {
- assert_eq!(grant_from_filename(&format!("screenpipe-{grant}{extension}"), extension), Some(grant.into()));
- for name in [format!("screenpipe-{PLACEHOLDER}{extension}"), format!("screenpipe-{grant}.txt{extension}"), format!("../screenpipe-{grant}{extension}"), format!("screenpipe-{grant}{extension}.exe")] {
- assert!(grant_from_filename(&name, extension).is_none());
- }
- }
- }
-
- #[cfg(target_os = "windows")]
- #[test]
- fn installed_windows_carrier_is_exact_and_bounded() {
- let dir = tempfile::tempdir().unwrap();
- let path = dir.path().join("acquisition-grant");
- let grant = "12345678-1234-4234-8234-123456789012";
- std::fs::write(&path, grant).unwrap();
- assert_eq!(carrier_from(dir.path()), Some(grant.into()));
- for invalid in [
- PLACEHOLDER,
- "12345678-1234-4234-7234-123456789012",
- "12345678-1234-4234-C234-123456789012",
- "12345678-1234-4234-8234-12345678901X",
- ] {
- std::fs::write(&path, invalid).unwrap();
- assert!(carrier_from(dir.path()).is_none());
- }
- std::fs::write(&path, format!("{grant}\n")).unwrap();
- assert!(carrier_from(dir.path()).is_none());
- }
-
#[tokio::test]
async fn credential_store_preserves_proof_and_retirement_across_restart() {
let dir = tempfile::tempdir().unwrap();
diff --git a/apps/screenpipe-app-tauri/src-tauri/windows/hooks.nsh b/apps/screenpipe-app-tauri/src-tauri/windows/hooks.nsh
index 7b8cec871..3ab61d8ee 100644
--- a/apps/screenpipe-app-tauri/src-tauri/windows/hooks.nsh
+++ b/apps/screenpipe-app-tauri/src-tauri/windows/hooks.nsh
@@ -9,88 +9,6 @@
!include "x64.nsh"
!include "LogicLib.nsh"
-; Save a filename-carried acquisition grant once. This is deliberately a pure
-; NSIS parser: attribution is optional and never launches a shell or blocks an
-; install. Expected filename: screenpipe-<lowercase canonical UUID v4>.exe.
-!macro _SP_SaveAcquisitionGrant
- Push $0
- Push $1
- Push $2
- Push $3
- ${IfNot} ${FileExists} "$INSTDIR\acquisition-grant"
- StrLen $0 $EXEFILE
- ${If} $0 == 51
- StrCpy $1 $EXEFILE 11 0
- StrCpy $2 $EXEFILE 4 47
- ${If} $1 == "screenpipe-"
- ${AndIf} $2 == ".exe"
- StrCpy $1 $EXEFILE 36 11
- ${If} $1 != "00000000-0000-4000-8000-000000000000"
- StrCpy $2 $1 1 14
- ${If} $2 == "4"
- StrCpy $2 $1 1 19
- ${If} $2 == "8"
- ${OrIf} $2 == "9"
- ${OrIf} $2 == "a"
- ${OrIf} $2 == "b"
- StrCpy $0 0
- StrCpy $3 1
- ${Do}
- StrCpy $2 $1 1 $0
- ${If} $0 == 8
- ${OrIf} $0 == 13
- ${OrIf} $0 == 18
- ${OrIf} $0 == 23
- ${If} $2 != "-"
- StrCpy $3 0
- ${ExitDo}
- ${EndIf}
- ${Else}
- ${If} $2 != "0"
- ${AndIf} $2 != "1"
- ${AndIf} $2 != "2"
- ${AndIf} $2 != "3"
- ${AndIf} $2 != "4"
- ${AndIf} $2 != "5"
- ${AndIf} $2 != "6"
- ${AndIf} $2 != "7"
- ${AndIf} $2 != "8"
- ${AndIf} $2 != "9"
- ${AndIf} $2 != "a"
- ${AndIf} $2 != "b"
- ${AndIf} $2 != "c"
- ${AndIf} $2 != "d"
- ${AndIf} $2 != "e"
- ${AndIf} $2 != "f"
- StrCpy $3 0
- ${ExitDo}
- ${EndIf}
- ${EndIf}
- IntOp $0 $0 + 1
- ${If} $0 >= 36
- ${ExitDo}
- ${EndIf}
- ${Loop}
- ${If} $3 == 1
- ClearErrors
- FileOpen $0 "$INSTDIR\acquisition-grant" w
- ${IfNot} ${Errors}
- FileWrite $0 $1
- FileClose $0
- ${EndIf}
- ${EndIf}
- ${EndIf}
- ${EndIf}
- ${EndIf}
- ${EndIf}
- ${EndIf}
- ${EndIf}
- Pop $3
- Pop $2
- Pop $1
- Pop $0
-!macroend
-
; Stop the service through SCM without executing an installed helper. This is
; required when an administrator removed a hostile ProgramData namespace: old
; helpers logged from prepare-upgrade and could recreate that namespace with
@@ -344,8 +262,6 @@
!macroend
!macro NSIS_HOOK_POSTINSTALL
- !insertmacro _SP_SaveAcquisitionGrant
-
; Binaries moved aside above. The orphan holding them has usually exited by
; now; whatever is left gets swept by the app on its next boot.
Delete "$INSTDIR\*.sp-old*"
diff --git a/docs/macos-acquisition-handoff.md b/docs/macos-acquisition-handoff.md
index d43ae7c57..d70145142 100644
--- a/docs/macos-acquisition-handoff.md
+++ b/docs/macos-acquisition-handoff.md
@@ -2,76 +2,36 @@
<!-- doc-covers: none -->
-The website companion saves the original, consented browser source and places
-an opaque download grant in a platform carrier. The app persists a verifier,
-claims the grant, and binds it using the verified Clerk session. This runs in a
-background task, independent of recording. All platforms use the same claim,
-retry, account-boundary, and retirement protocol.
+The website saves the original, consented browser source before download. The
+installer is the ordinary signed DMG, EXE or AppImage and carries nothing. After
+install, the website's install page opens `screenpipe://attribution?grant=<uuid4>`
+through the operating system. The app persists that grant with a verifier,
+claims it, and binds it using the verified Clerk session. This runs in a
+background task, independent of recording. All platforms share one protocol.
```text
-signed app + xattr -> ZIP -> website personalizes UUID and ZIP checksums
- -> macOS extracts app -> Keychain proof -> claim -> authenticated bind
-
-signed screenpipe-<UUID>.exe -> NSIS validates filename -> installed token
- -> Windows credential-store proof -> claim -> authenticated bind
-
-signed screenpipe-<UUID>.AppImage -> APPIMAGE filename -> credential-store proof
- -> claim -> authenticated bind
-```
-
-Retries reuse the same request and verifier. Saved proof survives app updates
-that remove the xattr. Account switch/logout invalidates in-flight work and saves
-a retirement marker before changing accounts, without waiting for credential
-storage. The native settings-store listener also retires immediately on analytics
-opt-out, including rapid off/on toggles and requests already in flight. A late
-credential write cannot erase a persisted marker, so restart remains retired.
-If the filesystem rejects the marker write, retirement is guaranteed only for
-the current process. Same-account JWT refresh wakes the
-worker without retiring the acquisition. Missing account provisioning is retried.
-No token, source data or HTTP error body is logged.
-
-Prepare artifacts locally from an already signed/notarized app:
-
-```sh
-python3 scripts/package-attribution-carrier.py \
- --app /path/to/screenpipe.app --platform macos-arm \
- --release VERSION --output /path/to/new-output-directory
+consented website visit -> install page "Open screenpipe"
+ -> screenpipe://attribution?grant=<uuid4> -> Keychain / credential-store proof
+ -> claim -> sign in from the app, in any browser -> authenticated bind
```
-The script checks app version, architecture, signature and metadata round-trip,
-then writes `screenpipe-attribution.zip` and `screenpipe-attribution.json`.
-For Linux or Windows, pass the original versioned release artifact instead:
-
-```sh
-python3 scripts/package-attribution-carrier.py \
- --artifact /path/to/versioned-installer \
- --platform linux \
- --release VERSION --output /path/to/new-output-directory
-```
-
-Linux writes `screenpipe-attribution.AppImage`; Windows and Windows ARM write
-`screenpipe-attribution.exe`. Each has a `screenpipe-attribution.json` manifest
-containing the original byte length and SHA-256. Windows preparation requires a
-Windows host and checks Authenticode, version metadata, and architecture evidence
-in the versioned release filename. The NSIS bootstrap PE machine is not treated
-as payload architecture. Filename personalization preserves the signed bytes.
-Use `--platform windows` for x86_64 and `--platform windows-arm` for ARM64.
-
-The script never uploads artifacts or changes publication pointers. Production
-activation and versioned-artifact publication have not been performed. Human
-publication remains required. An ordinary, unpersonalized download installs and
-runs normally without optional attribution. Renaming a personalized Windows or
-Linux download before its first install/launch can lose attribution.
-
-The signature-exempt xattr and ZIP extraction behavior are documented by
-[Apple Developer Technical Support](https://developer.apple.com/forums/thread/796303).
-There is no ZIP or user-supplied sidecar for Windows. NSIS saves the first valid
-grant beside the installed executable and updates never replace it. Linux reads
-only the original AppImage path supplied by `APPIMAGE`.
-
-Before enabling website carrier admission, verify actual production artifacts,
-app startup, restart, login/logout, trial/purchase, updater recovery, and provider
-readback. The macOS test uses an ad-hoc signed fixture; Windows NSIS tests exercise
-the real grant macro but mock installer signature/version metadata boundaries;
-Linux uses a synthetic AppImage header. These local tests do not prove the full
-production download or signing path.
+The app accepts only its own build scheme, the `attribution` route and exactly
+one valid v4 grant. The first saved grant wins: proof is never replaced, a
+retired profile accepts nothing, and the same URL delivered twice (open-URL
+event, single-instance forward, launch arguments, `/focus` handoff) is harmless.
+
+Retries reuse the same request and verifier. Saved proof survives app updates.
+Account switch/logout invalidates in-flight work and saves a retirement marker
+before changing accounts, without waiting for credential storage. The native
+settings-store listener also retires immediately on analytics opt-out, including
+rapid off/on toggles and requests already in flight. A late credential write
+cannot erase a persisted marker, so restart remains retired. If the filesystem
+rejects the marker write, retirement is guaranteed only for the current process.
+Same-account JWT refresh wakes the worker without retiring the acquisition.
+Missing account provisioning is retried. No token, source data or HTTP error
+body is logged.
+
+Not covered: a visitor who closes the install page before clicking, or who
+installs from a shared link, mirror or package manager, has no grant and stays
+an unknown source. Nothing in the installer, packager, manifests or release
+workflow is involved in attribution.
diff --git a/scripts/package-attribution-carrier.py b/scripts/package-attribution-carrier.py
deleted file mode 100644
index 624c87b82..000000000
--- a/scripts/package-attribution-carrier.py
+++ /dev/null
@@ -1,186 +0,0 @@
-#!/usr/bin/env python3
-# screenpipe — AI that knows everything you've seen, said, or heard
-# https://screenpipe.com
-"""Prepare a versioned download carrier from a release artifact. Never uploads/publishes."""
-import argparse
-import hashlib
-import json
-from pathlib import Path
-import plistlib
-import os
-import re
-import shutil
-import struct
-import subprocess
-import sys
-import tempfile
-import zipfile
-
-PLACEHOLDER = '00000000-0000-4000-8000-000000000000'
-
-
-def package(app, output, platform, release):
- app, output = Path(app).resolve(), Path(output).resolve()
- if app.suffix != '.app' or not re.fullmatch(r'\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?', release):
- raise ValueError('signed .app and valid release required')
- info = plistlib.loads((app / 'Contents/Info.plist').read_bytes())
- if info.get('CFBundleShortVersionString') != release:
- raise ValueError('release must match the app version')
- executable = app / 'Contents/MacOS' / info['CFBundleExecutable']
- expected_arch = {'macos-arm': 'arm64', 'macos-intel': 'x86_64'}[platform]
- architectures = subprocess.check_output(['lipo', '-archs', str(executable)]).decode().split()
- if not any(arch == expected_arch or (expected_arch == 'arm64' and arch == 'arm64e') for arch in architectures):
- raise ValueError('platform does not match the signed executable')
- subprocess.run(['codesign', '--verify', '--deep', '--strict', str(app)], check=True)
- output.mkdir(parents=True, exist_ok=True)
- archive = output / 'screenpipe-attribution.zip'
- manifest = output / 'screenpipe-attribution.json'
- if archive.exists() or manifest.exists():
- raise ValueError('refusing to overwrite prepared artifacts')
- with tempfile.TemporaryDirectory(prefix='screenpipe-carrier-') as tmp:
- tmp = Path(tmp)
- container = tmp / 'root'
- container.mkdir()
- copied = container / app.name
- subprocess.run(['ditto', str(app), str(copied)], check=True)
- subprocess.run(['xattr', '-w', 'com.apple.application-instance', PLACEHOLDER, str(copied)], check=True)
- subprocess.run(['codesign', '--verify', '--deep', '--strict', str(copied)], check=True)
- original = tmp / 'original.zip'
- subprocess.run(['ditto', '-c', '-k', '--sequesterRsrc', str(container), str(original)], check=True)
- member_name = '__MACOSX/._' + app.name
- prepared = tmp / 'prepared.zip'
- with zipfile.ZipFile(original) as src, zipfile.ZipFile(prepared, 'w', allowZip64=False) as dst:
- for entry in src.infolist():
- if entry.filename == member_name:
- payload = src.read(entry)
- if payload.count(PLACEHOLDER.encode()) != 1:
- raise ValueError('ambiguous or absent xattr placeholder')
- entry.compress_type = zipfile.ZIP_STORED
- entry.extra = b''
- entry.comment = b''
- dst.writestr(entry, payload)
- else:
- with src.open(entry) as source, dst.open(entry, 'w') as target:
- shutil.copyfileobj(source, target, 1024 * 1024)
- with zipfile.ZipFile(prepared) as z:
- entry = z.getinfo(member_name)
- payload = z.read(entry)
- central = z.start_dir
- with prepared.open('rb') as f:
- while True:
- f.seek(central)
- header = f.read(46)
- if header[:4] != b'PK\x01\x02':
- raise ValueError('missing carrier central entry')
- namesize, extrasize, commentsize = struct.unpack_from('<HHH', header, 28)
- name = f.read(namesize).decode('utf-8')
- if name == member_name:
- break
- central += 46 + namesize + extrasize + commentsize
- size = prepared.stat().st_size
- if size > 2147483647:
- raise ValueError('carrier exceeds the website streaming limit')
- digest = hashlib.sha256()
- with prepared.open('rb') as f:
- for block in iter(lambda: f.read(1024 * 1024), b''):
- digest.update(block)
- result = dict(schema=1, platform=platform, release=release, size=size,
- sha256=digest.hexdigest(), placeholder=PLACEHOLDER,
- member=dict(name=member_name, data_offset=entry.header_offset+30+len(member_name.encode()),
- data_length=len(payload), grant_offset=payload.index(PLACEHOLDER.encode()),
- crc32=entry.CRC, local_crc_offset=entry.header_offset+14,
- central_crc_offset=central+16))
- # Check the actual archive extraction, including metadata and signature.
- extracted = tmp / 'extracted'
- subprocess.run(['ditto', '-x', '-k', str(prepared), str(extracted)], check=True)
- extracted_app = extracted / app.name
- received = subprocess.check_output(['xattr', '-p', 'com.apple.application-instance', str(extracted_app)]).decode().strip()
- if received != PLACEHOLDER:
- raise ValueError('archive lost the application instance attribute')
- subprocess.run(['codesign', '--verify', '--deep', '--strict', str(extracted_app)], check=True)
- shutil.copyfile(prepared, archive)
- manifest.write_text(json.dumps(result, indent=2)+'\n')
- return archive, manifest
-
-
-def package_filename(artifact, output, platform, release):
- """Copy an immutable executable; only its delivered filename is personalized."""
- artifact, output = Path(artifact).resolve(), Path(output).resolve()
- if not re.fullmatch(r'\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?', release):
- raise ValueError('valid release required')
- if not re.search(r'(?:^|[_-])' + re.escape(release) + r'(?:[_-]|\.)', artifact.name):
- raise ValueError('release must match the versioned artifact filename')
- if platform not in ('linux', 'windows', 'windows-arm'):
- raise ValueError('unsupported filename platform')
- if platform == 'linux':
- with artifact.open('rb') as source:
- header = source.read(20)
- if (artifact.suffix != '.AppImage' or header[:6] != b'\x7fELF\x02\x01' or
- header[8:11] != b'AI\x02' or len(header) != 20 or struct.unpack_from('<H', header, 18)[0] != 62):
- raise ValueError('Linux x86_64 type-2 AppImage required')
- else:
- if artifact.suffix.lower() != '.exe':
- raise ValueError('Windows installer .exe required')
- arch = (r'(?:^|[_-])(?:x64|x86_64|amd64)(?:[_-]|\.)' if platform == 'windows'
- else r'(?:^|[_-])(?:arm64|aarch64)(?:[_-]|\.)')
- if not re.search(arch, artifact.name, re.IGNORECASE):
- raise ValueError('versioned release filename lacks target architecture evidence')
- metadata = windows_metadata(artifact)
- if metadata.get('Status') != 'Valid':
- raise ValueError('installer must have a valid Authenticode signature')
- versions = {str(metadata.get(key, '')).strip() for key in ('ProductVersion', 'FileVersion')}
- if release not in versions:
- raise ValueError('release must match Windows version metadata')
- size = artifact.stat().st_size
- if not 100 <= size <= 2147483647:
- raise ValueError('carrier size outside streaming limit')
- output.mkdir(parents=True, exist_ok=True)
- target = output / ('screenpipe-attribution.exe' if platform.startswith('windows')
- else 'screenpipe-attribution.AppImage')
- manifest = output / 'screenpipe-attribution.json'
- if target.exists() or manifest.exists():
- raise ValueError('refusing to overwrite prepared artifacts')
- digest = hashlib.sha256()
- # Hash the exact bytes being copied, with exclusive creation.
- with artifact.open('rb') as source, target.open('xb') as destination:
- for block in iter(lambda: source.read(1024 * 1024), b''):
- digest.update(block)
- destination.write(block)
- if target.stat().st_size != size:
- target.unlink()
- raise ValueError('artifact changed during copy')
- target.chmod(artifact.stat().st_mode & 0o777)
- with manifest.open('x') as destination:
- json.dump(dict(schema=1, carrier='filename', platform=platform, release=release,
- size=size, sha256=digest.hexdigest()), destination, indent=2)
- destination.write('\n')
- return target, manifest
-
-
-def windows_metadata(artifact):
- """Read signature and version using Windows' supported PowerShell APIs."""
- if sys.platform != 'win32':
- raise ValueError('Windows packaging requires a Windows host')
- script = ("$ErrorActionPreference='Stop';$p=$env:SCREENPIPE_ATTRIBUTION_ARTIFACT;"
- "$s=Get-AuthenticodeSignature -LiteralPath $p;"
- "$v=[Diagnostics.FileVersionInfo]::GetVersionInfo($p);"
- "@{Status=[string]$s.Status;ProductVersion=$v.ProductVersion;"
- "FileVersion=$v.FileVersion}|ConvertTo-Json -Compress")
- output = subprocess.check_output([
- 'powershell.exe', '-NoProfile', '-NonInteractive', '-Command', script
- ], text=True, timeout=30, env={**os.environ, 'SCREENPIPE_ATTRIBUTION_ARTIFACT': str(artifact)})
- return json.loads(output)
-
-
-if __name__ == '__main__':
- parser = argparse.ArgumentParser(description=__doc__)
- inputs = parser.add_mutually_exclusive_group(required=True)
- inputs.add_argument('--app')
- inputs.add_argument('--artifact')
- parser.add_argument('--output', required=True)
- parser.add_argument('--platform', choices=['macos-arm', 'macos-intel', 'linux', 'windows', 'windows-arm'], required=True)
- parser.add_argument('--release', required=True)
- args = parser.parse_args()
- prepare = package if args.app else package_filename
- for artifact in prepare(args.app or args.artifact, args.output, args.platform, args.release):
- print(artifact)
diff --git a/scripts/test_attribution_carrier.py b/scripts/test_attribution_carrier.py
deleted file mode 100644
index 7f9035790..000000000
--- a/scripts/test_attribution_carrier.py
+++ /dev/null
@@ -1,155 +0,0 @@
-# screenpipe — AI that knows everything you've seen, said, or heard
-# https://screenpipe.com
-"""Local attribution-carrier packaging regressions; never publish artifacts."""
-import importlib.util
-import hashlib
-import json
-import sys
-from pathlib import Path
-import plistlib
-import shutil
-import subprocess
-import tempfile
-import unittest
-from unittest import mock
-
-spec = importlib.util.spec_from_file_location('carrier', Path(__file__).with_name('package-attribution-carrier.py'))
-carrier = importlib.util.module_from_spec(spec)
-spec.loader.exec_module(carrier)
-
-
-class CarrierTest(unittest.TestCase):
- @unittest.skipUnless(sys.platform == "darwin", "requires macOS signing tools")
- def test_signed_archive_metadata_and_overwrite_boundaries(self):
- with tempfile.TemporaryDirectory(prefix='screenpipe-carrier-test-') as tmp:
- root = Path(tmp)
- app = root / 'Fixture.app'
- executable = app / 'Contents/MacOS/Fixture'
- executable.parent.mkdir(parents=True)
- shutil.copyfile('/bin/echo', executable)
- executable.chmod(0o755)
- (app / 'Contents/Info.plist').write_bytes(plistlib.dumps(dict(
- CFBundleIdentifier='com.screenpipe.carrier-fixture', CFBundleExecutable='Fixture',
- CFBundleName='Fixture', CFBundlePackageType='APPL', CFBundleShortVersionString='0.3.100')))
- subprocess.run(['codesign', '--force', '--sign', '-', str(app)], check=True)
- architectures = subprocess.check_output(['lipo', '-archs', str(executable)]).decode()
- platform = 'macos-arm' if 'arm64' in architectures else 'macos-intel'
- output = root / 'output'
- archive, manifest = carrier.package(app, output, platform, '0.3.100')
- self.assertTrue(archive.is_file())
- self.assertTrue(manifest.is_file())
- # Packaging already verifies extraction, xattr preservation and the
- # actual extracted signature. Also prove it never mutates the input.
- attrs = subprocess.check_output(['xattr', str(app)]).decode()
- self.assertNotIn('com.apple.application-instance', attrs)
- with self.assertRaisesRegex(ValueError, 'overwrite'):
- carrier.package(app, output, platform, '0.3.100')
- with self.assertRaisesRegex(ValueError, 'version'):
- carrier.package(app, root / 'wrong-version', platform, '0.3.101')
-
- def test_appimage_bytes_unchanged_and_metadata_bounded(self):
- with tempfile.TemporaryDirectory() as tmp:
- root = Path(tmp)
- artifact = root / 'screenpipe_1.2.3_amd64.AppImage'
- content = bytearray(1024)
- content[:6] = b'\x7fELF\x02\x01'
- content[8:11] = b'AI\x02'
- content[18] = 62
- artifact.write_bytes(content)
- artifact.chmod(0o755)
- prepared, manifest = carrier.package_filename(artifact, root / 'out', 'linux', '1.2.3')
- self.assertEqual(prepared.read_bytes(), content)
- self.assertEqual(artifact.read_bytes(), content)
- data = json.loads(manifest.read_text())
- self.assertEqual(data['sha256'], hashlib.sha256(content).hexdigest())
- self.assertEqual(data['carrier'], 'filename')
- with self.assertRaisesRegex(ValueError, 'overwrite'):
- carrier.package_filename(artifact, root / 'out', 'linux', '1.2.3')
- with self.assertRaisesRegex(ValueError, 'version'):
- carrier.package_filename(artifact, root / 'bad-version', 'linux', '1.2.4')
- content[18] = 183
- artifact.write_bytes(content)
- with self.assertRaisesRegex(ValueError, 'x86_64'):
- carrier.package_filename(artifact, root / 'bad-arch', 'linux', '1.2.3')
-
- def test_windows_bytes_metadata_architecture_and_overwrite_boundaries(self):
- with tempfile.TemporaryDirectory() as tmp:
- root = Path(tmp)
- content = b'MZ' + bytes(1022)
- for platform, arch in [('windows', 'x64'), ('windows-arm', 'arm64')]:
- artifact = root / f'screenpipe_1.2.3_{arch}-setup.exe'
- artifact.write_bytes(content)
- output = root / platform
- metadata = dict(Status='Valid', ProductVersion='1.2.3', FileVersion='1.2.3')
- with mock.patch.object(carrier, 'windows_metadata', return_value=metadata):
- prepared, manifest = carrier.package_filename(artifact, output, platform, '1.2.3')
- self.assertEqual(prepared.name, 'screenpipe-attribution.exe')
- self.assertEqual(prepared.read_bytes(), content)
- data = json.loads(manifest.read_text())
- self.assertEqual(data['sha256'], hashlib.sha256(content).hexdigest())
- self.assertEqual(data['carrier'], 'filename')
- with self.assertRaisesRegex(ValueError, 'overwrite'):
- carrier.package_filename(artifact, output, platform, '1.2.3')
- wrong_arch = root / f'screenpipe_1.2.3_{"arm64" if arch == "x64" else "x64"}-setup.exe'
- wrong_arch.write_bytes(content)
- with self.assertRaisesRegex(ValueError, 'architecture'):
- carrier.package_filename(wrong_arch, root / f'bad-{platform}', platform, '1.2.3')
- with mock.patch.object(carrier, 'windows_metadata', return_value={**metadata, 'Status': 'NotSigned'}):
- with self.assertRaisesRegex(ValueError, 'Authenticode'):
- carrier.package_filename(artifact, root / f'unsigned-{platform}', platform, '1.2.3')
- with mock.patch.object(carrier, 'windows_metadata', return_value={**metadata, 'ProductVersion': '1.2.4', 'FileVersion': '1.2.4'}):
- with self.assertRaisesRegex(ValueError, 'version metadata'):
- carrier.package_filename(artifact, root / f'version-{platform}', platform, '1.2.3')
-
- @unittest.skipUnless(sys.platform == 'win32', 'requires Windows NSIS')
- def test_actual_nsis_filename_grant_fixture(self):
- makensis = shutil.which('makensis') or shutil.which('makensis.exe')
- self.assertIsNotNone(makensis, 'makensis is required for the Windows fixture')
- hooks = (Path(__file__).parents[1] / 'apps/screenpipe-app-tauri/src-tauri/windows/hooks.nsh').resolve()
- with tempfile.TemporaryDirectory(prefix='screenpipe-nsis-attribution-') as tmp:
- root = Path(tmp)
- fixture = root / 'fixture.nsi'
- fixture.write_text(
- '; screenpipe — AI that knows everything you\'ve seen, said, or heard\n'
- '; https://screenpipe.com\n'
- 'Unicode true\nSilentInstall silent\nRequestExecutionLevel user\n'
- f'!include "{hooks}"\n'
- 'Name "Screenpipe attribution fixture"\nOutFile "fixture.exe"\nInstallDir "$TEMP\\screenpipe-attribution-fixture"\n'
- 'Section\nCreateDirectory "$INSTDIR"\nFileOpen $0 "$INSTDIR\\installed" w\nFileWrite $0 "ok"\nFileClose $0\n'
- '!insertmacro _SP_SaveAcquisitionGrant\nSectionEnd\n',
- encoding='utf-8')
- subprocess.run([makensis, '/V2', str(fixture)], cwd=root, check=True)
-
- # Exercise the real PowerShell adapter, including a path whose
- # spaces and metacharacters must remain data, never command text.
- metadata_fixture = root / 'fixture $ [attribution].exe'
- shutil.copyfile(root / 'fixture.exe', metadata_fixture)
- self.assertEqual(carrier.windows_metadata(metadata_fixture)['Status'], 'NotSigned')
-
- first = '12345678-1234-4234-8234-123456789012'
- second = 'abcdefab-cdef-4abc-9def-abcdefabcdef'
-
- def install(filename, directory):
- installer = root / filename
- shutil.copyfile(root / 'fixture.exe', installer)
- subprocess.run([str(installer), '/S', f'/D={directory}'], check=True)
- self.assertEqual((directory / 'installed').read_text(), 'ok')
-
- valid_dir = root / 'valid'
- install(f'screenpipe-{first}.exe', valid_dir)
- self.assertEqual((valid_dir / 'acquisition-grant').read_text(), first)
- install(f'screenpipe-{second}.exe', valid_dir)
- self.assertEqual((valid_dir / 'acquisition-grant').read_text(), first)
- for index, name in enumerate([
- f'screenpipe-{carrier.PLACEHOLDER}.exe',
- 'screenpipe-12345678-1234-4234-7234-123456789012.exe',
- 'screenpipe-12345678-1234-4234-C234-123456789012.exe',
- 'screenpipe.exe',
- ]):
- directory = root / f'invalid-{index}'
- install(name, directory)
- self.assertFalse((directory / 'acquisition-grant').exists())
-
-
-if __name__ == '__main__':
- unittest.main()