feat(ingest): password-protected archives; 7z and rar refused clearly (#370) #388

Merged
sharang merged 1 commits from feat/archive-password into main 2026-09-25 09:59:17 +00:00
Owner

Closes #370.

Password-protected archives can now be scanned, 7z and rar are refused with a clear message, and one broken upload no longer drops a target's other artifacts.

Decision (2026-09-25)

An optional archive password, plus a clear refusal for 7z and rar.

Agent

  • Unpacking (ingest/archive.rs):
    • encrypted zip entries are decrypted with the stored password, ZipCrypto and AES alike, within the existing ExtractLimits;
    • ExtractError tells PasswordRequired and WrongPassword apart from everything else;
    • ZipCrypto lets about one wrong password in 256 past its header check, so a checksum failure on an encrypted entry also counts as a wrong password;
    • zip_encryption checks a password against the smallest encrypted entry;
    • unsupported_format recognises 7z and rar from their leading bytes.
  • Upload (POST …/artifacts/upload): 7z and rar are refused with 415. An encrypted zip is kept and marked with the fact archive_encrypted.
  • New endpoint PUT /api/v1/targets/{id}/artifacts/{artifact_id}/archive-password (body {"password": "…"}):
    • The password is checked against the stored file, then sealed like a git token (auth.method = "archive_password").
    • The API never returns it, and it is never sent in a URL.
    • Responses: 204 saved, 422 wrong, 409 not a password-protected zip, 503 when there is no key to seal it with.
  • Ingest (ingest/mod.rs):
    • opens the archive with the stored password;
    • ingest_all now records an IngestFailure per artifact and carries on with the rest.
    • Classification records each failure as a skipped stage: archive_password_required and archive_password_wrong are their own stage ids, so the dashboard can say what to do; anything else is ingest.
  • PLC archives: the CODESYS SBOM reads entry names through the raw entry, so a password-protected .projectarchive still lists its libraries (names are never encrypted in a zip). The silent skip is gone.

Dashboard

  • Wizard:
    • Every staged archive has an optional "Archiv-Passwort" field.
    • After an upload that the agent marks as encrypted, the password is checked and saved. A missing or wrong password shows as an upload error for that file, and the first scan does not start.
    • A 7z/rar upload shows "7z- und RAR-Archive werden nicht unterstützt …".
  • Target editor: a password-protected archive shows "Passwort fehlt" or "Passwort gesetzt", with a field that checks and saves a new password at once. The editor's own Save never carries credentials.
  • Scan runs: the two new skipped stages are shown in DE/EN, with the hint where to enter the password.

Checked

  • cargo fmt --all --check.
  • clippy with the CI flags for compliance-agent and the dashboard (server, web).
  • Tests: agent library 433, core 99, dashboard 48 / 32.
    • New unit tests: ZipCrypto (a fixture made with zip -P) and AES, each with the right, wrong and missing password; a plain zip needs none; 7z and rar are named; the stored password is used; a 7z upload is refused; one failing artifact doesn't cost the others; the dashboard's password state.
    • New integration test tests/archive_password.rs against a live Mongo: an encrypted upload is marked, a wrong password gets 422, the right one gets 204 and is never returned, a plain upload gets 409, and a 7z upload gets 415.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

Closes #370. Password-protected archives can now be scanned, 7z and rar are refused with a clear message, and one broken upload no longer drops a target's other artifacts. ## Decision (2026-09-25) An optional archive password, plus a clear refusal for 7z and rar. ## Agent - **Unpacking** (`ingest/archive.rs`): - encrypted zip entries are decrypted with the stored password, ZipCrypto and AES alike, within the existing `ExtractLimits`; - `ExtractError` tells `PasswordRequired` and `WrongPassword` apart from everything else; - ZipCrypto lets about one wrong password in 256 past its header check, so a checksum failure on an encrypted entry also counts as a wrong password; - `zip_encryption` checks a password against the smallest encrypted entry; - `unsupported_format` recognises 7z and rar from their leading bytes. - **Upload** (`POST …/artifacts/upload`): 7z and rar are refused with **415**. An encrypted zip is kept and marked with the fact `archive_encrypted`. - **New endpoint `PUT /api/v1/targets/{id}/artifacts/{artifact_id}/archive-password`** (body `{"password": "…"}`): - The password is checked against the stored file, then sealed like a git token (`auth.method = "archive_password"`). - The API never returns it, and it is never sent in a URL. - Responses: 204 saved, 422 wrong, 409 not a password-protected zip, 503 when there is no key to seal it with. - **Ingest** (`ingest/mod.rs`): - opens the archive with the stored password; - `ingest_all` now records an `IngestFailure` per artifact and carries on with the rest. - Classification records each failure as a skipped stage: `archive_password_required` and `archive_password_wrong` are their own stage ids, so the dashboard can say what to do; anything else is `ingest`. - **PLC archives:** the CODESYS SBOM reads entry names through the raw entry, so a password-protected `.projectarchive` still lists its libraries (names are never encrypted in a zip). The silent skip is gone. ## Dashboard - **Wizard:** - Every staged archive has an optional "Archiv-Passwort" field. - After an upload that the agent marks as encrypted, the password is checked and saved. A missing or wrong password shows as an upload error for that file, and the first scan does not start. - A 7z/rar upload shows "7z- und RAR-Archive werden nicht unterstützt …". - **Target editor:** a password-protected archive shows "Passwort fehlt" or "Passwort gesetzt", with a field that checks and saves a new password at once. The editor's own Save never carries credentials. - **Scan runs:** the two new skipped stages are shown in DE/EN, with the hint where to enter the password. ## Checked - `cargo fmt --all --check`. - clippy with the CI flags for compliance-agent and the dashboard (`server`, `web`). - Tests: agent library 433, core 99, dashboard 48 / 32. - **New unit tests:** ZipCrypto (a fixture made with `zip -P`) and AES, each with the right, wrong and missing password; a plain zip needs none; 7z and rar are named; the stored password is used; a 7z upload is refused; one failing artifact doesn't cost the others; the dashboard's password state. - **New integration test** `tests/archive_password.rs` against a live Mongo: an encrypted upload is marked, a wrong password gets 422, the right one gets 204 and is never returned, a plain upload gets 409, and a 7z upload gets 415. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang added 1 commit 2026-09-25 09:06:23 +00:00
feat(ingest): password-protected archives; 7z and rar refused clearly (#370)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 6m28s
e39d82e442
Encrypted zips (ZipCrypto and AES) are decrypted with a password set on
the artifact: the upload marks them, a new endpoint checks the password
against the file and stores it sealed, and the wizard and target editor
ask for it. A missing or wrong password is its own skipped stage. 7z
and rar uploads are refused with 415, one failing artifact no longer
drops the target's others, and a locked CODESYS archive still lists
its libraries.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang merged commit 80eb7f462c into main 2026-09-25 09:59:17 +00:00
Sign in to join this conversation.