|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +## Project |
| 4 | + |
| 5 | +ssh-agent-proxy — a localhost HTTP signing proxy backed by any ssh-agent. |
| 6 | +Written in Rust (edition 2024). Single binary, no runtime dependencies. |
| 7 | + |
| 8 | +## Build & test |
| 9 | + |
| 10 | +```sh |
| 11 | +cargo build --release # Linux |
| 12 | +cargo test # requires ssh-keygen for SSHSIG byte-equality tests |
| 13 | +cargo clippy -- -D warnings # lint |
| 14 | +cargo fmt -- --check # format check |
| 15 | +make build-windows # cross-compile (needs mingw) |
| 16 | +``` |
| 17 | + |
| 18 | +## Architecture |
| 19 | + |
| 20 | +- `src/main.rs` — entry point, tokio runtime, signal handling, service dispatch |
| 21 | +- `src/server.rs` — axum HTTP handlers (/sign, /publickey, /healthz) |
| 22 | +- `src/config.rs` — env var config loading |
| 23 | +- `src/sshsig.rs` — SSHSIG wire format (must produce output byte-identical to ssh-keygen) |
| 24 | +- `src/agent.rs` — minimal SSH agent protocol client (LIST + SIGN only) |
| 25 | +- `src/agent_source.rs` — dials agent per request, key selection, RSA sha2-512 upgrade |
| 26 | +- `src/wire.rs` — shared SSH string read/write primitives |
| 27 | +- `src/dialer_{unix,windows}.rs` — platform-specific agent connection |
| 28 | +- `src/hardening_{linux,macos,windows}.rs` — process hardening (prctl, mlockall, etc.) |
| 29 | +- `src/service_windows.rs` — Windows SCM integration (install/uninstall/dispatcher) |
| 30 | + |
| 31 | +## Key design decisions |
| 32 | + |
| 33 | +- Fresh agent connection per HTTP request — no caching, no key material held between requests |
| 34 | +- `AgentBackedSigner` uses `Mutex` (not `RefCell`) for interior mutability because axum handlers require `Send` |
| 35 | +- Signature format anti-downgrade check on ALL key types, not just RSA |
| 36 | +- `DefaultBodyLimit` enforced at the axum layer, not just in-handler |
| 37 | +- Platform code uses `#[cfg(target_os)]` / `#[cfg(unix)]` / `#[cfg(windows)]` |
| 38 | +- Windows service module is in main.rs module tree (not lib.rs) because it calls `crate::run()` |
| 39 | + |
| 40 | +## Testing |
| 41 | + |
| 42 | +The SSHSIG byte-equality tests are the most important — they prove the wire format |
| 43 | +is correct by comparing against `ssh-keygen -Y sign` output. If those pass, the |
| 44 | +signing pipeline is correct. |
| 45 | + |
| 46 | +## Cross-compilation |
| 47 | + |
| 48 | +Windows cross-compile from Linux requires `x86_64-pc-windows-gnu` target and |
| 49 | +`gcc-mingw-w64-x86-64`. Native Windows builds use MSVC and avoid Smart App Control |
| 50 | +issues that MinGW binaries can trigger. |
0 commit comments