Commit Graph

155 Commits

Author SHA1 Message Date
d85c882635 feat!: harden SSH server handler security
- Restrict auth methods to PUBLICKEY only (no none, password, hostbased,
  or keyboard-interactive advertised during negotiation)
- Log all denied channel types (session, x11, forwarded-tcpip) and
  dangerous request types (exec, shell, subsystem, pty, env, x11, agent)
- Explicitly reject all dangerous channel request handlers (exec, shell,
  subsystem, pty, env, x11, agent forwarding) with channel_failure
  responses instead of russh's default silent Ok(()) which leaves clients
  hanging and is a footgun if session channels are ever allowed
- Explicitly reject tcpip_forward, streamlocal_forward with logged warnings
- Log signal requests at debug level (harmless, no response needed)
- Override handlers in both core ServerHandler and NapiServerHandler
- Add tracing dependency to wraith-napi for security event logging
- Set preferred algorithms explicitly (russh::Preferred::DEFAULT which
  uses only modern KEX/cipher/MAC algorithms)
2026-06-03 09:04:01 +00:00
a7595f1718 fix: update repo URLs from github.com/alkdev to git.alk.dev/alkdev 2026-06-03 06:45:22 +00:00
37ff929a42 docs: add iroh and TLS NAPI examples to README 2026-06-03 06:30:39 +00:00
150b1f3ae5 feat(napi): add TLS and iroh transport support to serve() and connect() 2026-06-03 05:58:05 +00:00
053ace6fcc docs: add README, LICENSE files, and crate/module-level doc comments
Add top-level README.md with alpha status warning, quick start guide,
architecture overview, feature flags, transport modes, auth docs, and
Node.js API examples.

Add dual LICENSE-MIT and LICENSE-APACHE files.

Add comprehensive crate-level and module-level rustdoc to all three
crates (wraith-core, wraith, wraith-napi) and all public modules
(transport, client, server, auth, socks5, error). Add doc comments to
key public types (Transport, TransportAcceptor, ConnectOptions,
ClientSession, Server, ServeOptions, KeySource, ServerAuthConfig, etc).

Update Cargo.toml files with workspace-level package metadata
(version, edition, license, repository) and crate descriptions.
2026-06-02 22:03:10 +00:00
f63589a5ca chore: complete review/complete-system — final review passed, all criteria met 2026-06-02 20:27:03 +00:00
9b06f26a3c chore: complete review/server-and-client with fixes applied 2026-06-02 20:22:22 +00:00
e49aef05d3 fix: wire channel proxy into handler, add client reconnection with backoff, fix ADR-006 violations
- handler.channel_open_direct_tcpip now proxies non-wraith channels via
  connect_outbound+proxy_channel instead of dropping them
- ClientSession.run() spawns reconnect monitor that detects handle closure,
  reconnects with exponential backoff (1s/2s/4s/8s/16s/30s cap),
  and re-registers remote port forwards
- Remove server-side logging of tunnel destinations (ADR-006 compliance)
- Remove debug-level logging of proxy targets in channel_proxy
2026-06-02 20:22:13 +00:00
f057e868ce chore: complete Gen 8 + Gen 9 meta tasks (cli-layer, napi-layer, serve-function, serve-command) 2026-06-02 20:08:34 +00:00
0fdb6cd782 feat(napi): implement serve() function with WraithServer, WraithServerStream, and ConnectionInfo
Expose NAPI serve() per ADR-016. WraithServer provides close() and
onConnection(callback) for receiving SSH channel streams from
incoming connections. Each connection produces a WraithServerStream
(Duplex-like read/write/close) with ConnectionInfo (remoteAddr,
transportKind). Supports TCP transport with optional authorizedKeys
and certAuthority auth. TLS and iroh transports return helpful errors
indicating future support.
2026-06-02 20:05:13 +00:00
62d57dd477 Implement wraith serve CLI subcommand with clap
Add serve subcommand with all flags matching server.md CLI interface:
--key, --authorized-keys, --cert-authority, --transport, --listen,
--tls-cert, --tls-key, --acme-domain, --stealth, --proxy,
--iroh-relay, --max-connections-per-ip, --max-auth-attempts.

--key is required, --transport defaults to tcp, --listen defaults to
0.0.0.0:22. --stealth validates TLS transport. --acme-domain requires
acme feature flag. --transport iroh prints endpoint ID on startup.
Key inputs accept file paths. Errors reported to stderr with non-zero
exit code. Also adds acme feature flag and rustls-pemfile/rustls-pki-types
dependencies for TLS cert loading.
2026-06-02 12:28:37 +00:00
c7b8c5c5e0 chore: complete meta/server-layer — all server module tasks done 2026-06-02 12:12:53 +00:00
6297c07383 chore: fix clippy dead_code warning on handler.transport, update serve-loop task to completed 2026-06-02 12:11:54 +00:00
32a8c9a725 Merge branch 'feat/server/serve-loop' 2026-06-02 12:04:09 +00:00
373b053820 feat(server): implement serve loop, ServeOptions, graceful shutdown, and integration test
- Add ServeOptions struct with all CLI fields (key, authorized_keys, cert_authority,
  transport_mode, listen_addr, tls_cert, tls_key, acme_domain, stealth, proxy,
  iroh_relay, max_connections_per_ip, max_auth_attempts)
- ServeOptions::key/authorized_keys accept KeySource (file or in-memory)
- Server::new(opts) creates server with bound russh config, auth config, rate limiter
- Server::run(acceptor, endpoint_info) enters accept loop: rate limit check -> create
  handler -> russh::server::run_stream()
- Stealth mode integration: protocol detection before run_stream() on TLS connections
- Graceful shutdown: Server::shutdown() sends SSH disconnect, waits drain timeout,
  aborts remaining sessions
- SIGTERM/SIGINT handler on unix platforms
- iroh mode: prints endpoint ID on startup
- Integration test: start server, shutdown signal, verify clean exit
- Re-export Server, ServeOptions, ServeTransportMode, ServeError from lib.rs
2026-06-02 11:57:30 +00:00
94feb5fdac feat(cli): implement wraith connect subcommand with clap derive
All CLI flags from client.md: --server, --peer, --transport (default tcp),
--identity, --socks5 (default 127.0.0.1:1080), --forward (repeatable),
--remote-forward (repeatable), --proxy, --iroh-relay, --tls-server-name,
--insecure. Env var defaults: WRAITH_SERVER, WRAITH_IDENTITY. Validates
--server required for tcp/tls, --peer required for iroh, --identity required.
Warns on --proxy with --transport tcp (ADR-019). Translates args to
ConnectOptions and calls ClientSession::new(opts).run().await. Errors to
stderr with non-zero exit.
2026-06-02 11:39:57 +00:00
f13a1c985f Merge remote-tracking branch 'origin/feat/server/channel-proxy'
# Conflicts:
#	crates/wraith-core/src/error.rs
#	crates/wraith-core/src/server/mod.rs
2026-06-02 11:32:28 +00:00
49fe2b699f Implement server channel proxy: direct, SOCKS5, and HTTP CONNECT outbound connections
- Add channel_proxy.rs with connect_outbound() supporting Direct, Socks5, and HttpConnect proxy modes
- Implement proxy_channel() with bidirectional copy between SSH channel and outbound TCP
- Channel errors close individual channels without affecting SSH session (ADR-006)
- Remove destination logging from handler to comply with ADR-006
- Add ForwardError to error.rs (was missing, needed by forward.rs)
- Fix TcpListener type annotation in forward.rs
- Add 11 unit tests: direct, SOCKS5 handshake, HTTP CONNECT, proxy rejection, unreachable targets
2026-06-02 11:24:32 +00:00
365b11d19e Merge remote-tracking branch 'origin/feat/server/stealth-mode'
# Conflicts:
#	crates/wraith-core/src/error.rs
#	crates/wraith-core/src/server/mod.rs
2026-06-02 11:14:06 +00:00
7dcf7502b7 feat(server): implement stealth mode protocol multiplexing (ADR-017)
Add stealth mode detection that peeks at the first bytes after TLS handshake
to determine SSH vs HTTP protocol. SSH connections proceed to russh handler;
non-SSH connections receive a fake nginx 404 response, making the server
indistinguishable from an ordinary HTTPS site to scanners and DPI systems.

- ProtocolDetection enum (Ssh, Http) for protocol classification
- detect_protocol() uses BufReader::fill_buf() to peek without consuming bytes
- send_fake_nginx_404() writes HTTP/1.1 404 + Server: nginx headers
- validate_stealth_config() enforces TLS transport requirement for stealth
- 17 unit tests covering SSH banner, HTTP, random data, and edge cases
2026-06-02 11:13:15 +00:00
585913d3c8 Merge remote-tracking branch 'origin/feat/napi/connect-function'
# Conflicts:
#	crates/wraith-core/src/error.rs
2026-06-02 11:11:14 +00:00
243243a82f Implement NAPI connect() function — single SSH channel as duplex stream
- Add WraithConnectOptions struct with napi fields: server, peer, transport,
  identity (string path or Buffer), tlsServerName, insecure, irohRelay, proxy
- Add WraithStream napi class wrapping SSH channel read/write halves via
  ChannelStream::into_stream() + tokio::io::split()
- Implement connect() async function: transport creation (tcp, tls), SSH client
  connection, authenticate, open direct_tcpip channel, return WraithStream
- Identity field accepts file path (string) or in-memory key data (Buffer)
- All Rust errors marshalled to JavaScript exceptions with descriptive messages
- Add ForwardError enum to wraith-core (required by forward.rs)
- Enable tls, iroh features on wraith-core dependency
- 7 unit tests for key source resolution and address parsing
2026-06-02 11:10:42 +00:00
2ab5eeda53 Merge remote-tracking branch 'origin/feat/client/connect-options' 2026-06-02 11:07:54 +00:00
128affd264 Implement ConnectOptions struct and ClientSession orchestration with graceful shutdown
Adds client/connect.rs with ConnectOptions (programmatic API per ADR-011),
ClientSession::new() for SSH session establishment, ClientSession::run()
for SOCKS5 + port forwards + shutdown, and graceful shutdown via
SIGTERM/SIGINT with SSH disconnect and 2s drain timeout.
2026-06-02 11:07:33 +00:00
5a2b535605 Merge remote-tracking branch 'origin/feat/server/rate-limiting-and-logging'
# Conflicts:
#	crates/wraith-core/src/error.rs
#	crates/wraith-core/src/server/handler.rs
#	crates/wraith-core/src/server/mod.rs
2026-06-02 11:06:18 +00:00
24b70f5651 Implement server rate limiting and fail2ban-friendly structured logging
Add ConnectionRateLimiter (HashMap<IpAddr, usize>) and AuthAttemptLimiter
with check/on_connect/on_disconnect and check/on_failure methods.
Integrate into ServerHandler with structured tracing::info! logging for
auth attempts, connection opened/closed events. No logging of tunnel
destinations per ADR-006. Also add ForwardError type and fix type
annotation in forward.rs to unblock compilation.
2026-06-02 11:02:55 +00:00
f963898a05 Implement control channel routing for wraith-* reserved destinations (ADR-018)
- Add control_channel.rs with WRAITH_CONTROL_DESTINATION, WRAITH_PREFIX constants
- Add ControlChannelHandler trait and ControlChannelRouter for routing logic
- Add DuplexStream supertrait for Box<dyn> compatibility
- Server handler rejects wraith-* destinations when no handler configured
- Add ForwardError type to fix pre-existing compilation error
- Unit tests: reserved detection, non-reserved pass-through, prefix matching
2026-06-02 11:01:54 +00:00
992d478630 Merge remote-tracking branch 'origin/feat/transport/acme-cert-provisioning' 2026-06-02 10:49:57 +00:00
e3f33a24c3 Implement ACME/Let's Encrypt certificate provisioning (ADR-008)
Add AcmeCertProvider with domain-based and IP-based modes using rustls-acme.
AcmeTlsAcceptor::bind_acme() and TlsAcceptor::bind_acme() provide ACME-integrated
TLS acceptance with automatic cert renewal via background tokio task.
Feature-gated behind 'acme' (implies 'tls'). Unit tests for config construction;
integration test for LE staging marked #[ignore].
2026-06-02 10:49:32 +00:00
5fec0b53d9 Merge remote-tracking branch 'origin/feat/client/socks5-server' 2026-06-02 10:49:20 +00:00
2efd4cf7c5 Implement SOCKS5 server: local proxy forwarding through SSH channels
Convert socks5.rs to directory module with protocol parsing and server
implementation. Socks5Server binds to configurable address (default
127.0.0.1:1080), handles SOCKS5 handshake (no-auth), parses IPv4/IPv6/domain
addresses, and proxies bidirectionally via SSH direct_tcpip channels.
Domain names sent unresolved (SOCKS5h) to prevent DNS leaks (ADR-006).
No logging of request targets per privacy requirements.
2026-06-02 10:49:07 +00:00
4e4afd5020 Merge remote-tracking branch 'origin/feat/client/port-forwarding'
# Conflicts:
#	crates/wraith-core/src/client/mod.rs
#	crates/wraith-core/src/lib.rs
2026-06-02 10:46:54 +00:00
7336c0f13c feat(client): implement port forwarding — local (-L) and remote (-R) forwards
- PortForwardSpec parses -L/-R spec strings: bind_addr:bind_port:target_host:target_port
- LocalForwarder binds TcpListener, accepts connections, opens SSH direct-tcpip channel, proxies bidirectionally
- RemoteForwarder sends tcpip_forward request, handles forwarded-tcpip channel opens, connects local target, proxies bidirectionally
- Both forwarders run concurrently with SOCKS5 server via Arc<Mutex<Handle>>
- Connection errors close individual channels without affecting other forwards or SSH session
- ForwardError type added with display and source chaining tests
- Unit tests: spec parsing, local forward bind/accept, remote forward proxy bidirectional
2026-06-02 10:45:43 +00:00
975778bfb1 Merge remote-tracking branch 'origin/feat/client/channel-manager' 2026-06-02 10:44:32 +00:00
d6a49a07d7 implement ChannelManager with SSH session management, channel ops, and reconnection 2026-06-02 10:44:21 +00:00
24b92227e7 Implement ServerHandler with auth delegation and channel dispatch
Convert server.rs to directory module (server/mod.rs + server/handler.rs).
ServerHandler implements russh::server::Handler with:
- auth_publickey() delegating to ServerAuthConfig with structured logging
- channel_open_direct_tcpip() routing wraith-* prefix to internal handler,
  stub for regular TCP proxy
- ProxyConfig/ProxyMode types for outbound proxy configuration
- Unit tests for auth delegation, reserved destination routing, and
  unknown channel type rejection
2026-06-02 10:40:05 +00:00
bf8233af61 fix: add rand dev-dep, install rustls CryptoProvider in TLS tests, fix iroh OsRng import 2026-06-02 10:32:29 +00:00
b3589a038e Merge remote-tracking branch 'origin/feat/transport/iroh-transport' into transport/trait-and-types
# Conflicts:
#	Cargo.lock
#	crates/wraith-core/Cargo.toml
2026-06-02 10:30:12 +00:00
c3f5f3f504 Implement IrohTransport and IrohAcceptor (feature-gated iroh)
Add iroh QUIC P2P transport using tokio::io::join for stream duplexing
per ADR-003. Default relay is n0's https://relay.iroh.network/ (ADR-009).
Proxy URL passed to Endpoint::builder (ADR-010). Integration test marked
#[ignore] for CI since it requires iroh relay connectivity.
2026-06-02 10:29:40 +00:00
b559e335d3 Implement server-side auth with ServerAuthConfig (Ed25519 keys + cert-authority) 2026-06-02 10:21:28 +00:00
1054e3907e Merge remote-tracking branch 'origin/feat/transport/tls-transport' into transport/trait-and-types
# Conflicts:
#	crates/wraith-core/src/transport/tls.rs
2026-06-02 10:09:12 +00:00
f6d4705632 Implement TlsTransport and TlsAcceptor with tokio-rustls (feature-gated tls) 2026-06-02 10:08:29 +00:00
4052c4f19e fix: add ssh-key dev-dependency for server_auth tests 2026-06-02 10:08:11 +00:00
eb032c87f1 Implement client-side SSH auth handler with ClientAuthConfig and ClientHandler 2026-06-02 10:03:56 +00:00
b4f4f2ed8c Implement SSH key material loading with KeySource, load_private_key, load_public_keys, and CertAuthorityEntry 2026-06-02 09:52:39 +00:00
b157ab3799 Implement TcpTransport and TcpAcceptor for plain TCP connections 2026-06-02 09:23:35 +00:00
dddc6d7a4c Define Transport trait, TransportAcceptor trait, TransportInfo, and TransportKind types 2026-06-02 09:17:50 +00:00
56d032afdb Define error types for transport, auth, channel, and config layers 2026-06-02 09:16:23 +00:00
2bc15f1035 Initialize Cargo workspace with wraith-core, wraith, and wraith-napi crates
- Workspace root Cargo.toml with three crate members
- wraith-core: library with feature flags (tls, iroh, acme), core deps (russh, tokio, tracing, anyhow, thiserror, tokio-util), module skeleton (transport, client, server, auth, socks5, error)
- wraith: binary crate depending on wraith-core with clap derive
- wraith-napi: cdylib crate depending on wraith-core, napi, napi-derive
- .gitignore for target/ and node_modules/
2026-06-02 09:14:40 +00:00
14dbd81195 Decompose architecture into 35 atomic tasks across 10 generations for implementation 2026-06-02 09:02:55 +00:00