rmux

repository·main·Indexed 25 days ago

https://github.com/helvesec/rmux

A high-performance, cross-platform terminal multiplexer engine written in Rust with a tmux-style CLI and daemon runtime. It provides a stable Rust SDK (rmux-sdk) for programmatic access to sessions, windows, and panes, and a ratatui integration (ratatui-rmux) for rendering terminal panes. The project includes components for local IPC (rmux-ipc), OS abstraction (rmux-os), and a bincode-encoded wire protocol (rmux-proto), supporting Windows, macOS, and Linux.

Tokens
68.6K
Snippets
83
Records
430
Agent score
77%

What's inside rmux

  1. Overview of the rmux web-share E2EE Protocol v1

    main

    The rmux web-share end-to-end-encrypted (E2EE) protocol (version 1) provides confidentiality and integrity for terminal payloads sent from a browser client to a local rmux daemon (the host) over an untrusted relay (e.g., a Cloudflare tunnel).

    Key characteristics:

    • Hybrid Post-Quantum Security: Protects against future quantum threats by combining X25519 and ML-KEM-768. Confidentiality holds as long as the 256-bit share token remains secret and at least one of the key agreement algorithms remains unbroken.
    • Transport: Uses WebSockets. Handshake messages are sent as Text frames (UTF-8 JSON), while all subsequent data is sent as Binary frames containing encrypted records.
    • Trust Model: The relay (tunnel/proxy) is considered untrusted and can only observe ciphertext. The protocol is designed to protect against passive observers, active network attackers, MitM, and 'harvest now, decrypt later' quantum attacks.
  2. What is rmux-os?

    main

    rmux-os is a small, dependency-light OS abstraction layer used by RMUX IPC and terminal integrations. It provides a unified interface for OS-specific boundary operations required by the RMUX runtime, including host introspection, process and user identity, process control, and terminal queries.

    Supported platforms:

    • Linux
    • macOS
    • Windows (uses native Win32 APIs, not WSL)
  3. What is rmux-web-crypto?

    main

    rmux-web-crypto is a single-crate cryptographic core designed for the rmux web-share End-to-End Encryption (E2EE) protocol. It handles the low-level primitives required for secure communication without being tied to specific transport layers like WebSockets, TCP, or HTTP.

    Key cryptographic capabilities include:

    • Ephemeral X25519: Key generation and Diffie-Hellman.
    • ML-KEM-768: Post-quantum hybrid shared secret wrappers.
    • Session Derivation: Derives sessions using a Pre-Shared Key (PSK), X25519 DH shared secret, ML-KEM shared secret, and the exact handshake transcript bytes.
    • Authenticated Encryption: Uses ChaCha20-Poly1305 with monotonic sequence numbers.
    • Framing: Implements web-share text/binary "kind byte" framing on top of opaque records.

    Security properties:

    • Forward Secrecy: Provided by per-connection X25519 and ML-KEM secrets.
    • Authentication: Derived from a high-entropy PSK mixed into the key schedule via SHA-256(256-bit token).
  4. What is RMUX?

    main

    RMUX is an asynchronous, typed terminal multiplexer engine written in Rust. It is designed to implement over 90 tmux commands and provides a native runtime for Linux, macOS, and Windows (without requiring WSL).

    Developers can interact with RMUX in several ways:

    • Standalone CLI: Use it directly in the terminal.
    • Embedded Rust: Integrate the engine into Rust-based terminal applications.
    • Typed SDKs: Drive the engine using official SDKs for Rust, Python, and TypeScript.
  5. Use rmux-ipc for local IPC communication

    main

    The rmux-ipc crate provides local Inter-Process Communication (IPC) endpoint and transport primitives for the RMUX terminal multiplexer. It handles platform-specific socket resolution: using Unix domain sockets on Linux and macOS, and named pipes on Windows.

    Note: RMUX is strictly local; no network listeners are opened.

    While you can use rmux-ipc directly, most developers should interact with RMUX through the rmux-sdk instead of depending on rmux-ipc directly.

  6. Automate terminal sessions with the RMUX SDK

    main

    The RMUX SDK is a daemon-backed library designed for terminal automation. It is intended for programmatic use (where code is the user) rather than interactive CLI workflows.

    Key capabilities include:

    • Creating or reusing sessions.
    • Addressing panes by handle.
    • Sending input and waiting for rendered text.
    • Capturing snapshots and inspecting locators.
    • Streaming output and starting browser shares.
  7. Overview of the RMUX Web-Share E2EE Protocol Handshake

    main

    The RMUX web-share End-to-End Encryption (E2EE) protocol establishes a secure session between a browser client and an RMUX daemon via an untrusted relay. The handshake uses a combination of X25519 Diffie-Hellman and ML-KEM-768 to derive session keys.

    Handshake Flow:

    1. client_hello (Client $\rightarrow$ Relay $\rightarrow$ Daemon): The client sends a JSON message containing its ephemeral public keys and a token_id.
    2. server_challenge (Daemon $\rightarrow$ Relay $\rightarrow$ Client): The daemon responds with its own ephemeral public keys and ML-KEM ciphertext.
    3. Encrypted Authentication (Client $\rightarrow$ Daemon): The client sends a binary WebSocket frame containing encrypted authentication data to prove possession of the token_id.
    4. Ready (Daemon $\rightarrow$ Client): The daemon confirms the session is established.
    5. Encrypted Records: Terminal I/O flows in both directions using the derived session keys.

    The relay only sees the initial JSON handshake messages and opaque ciphertext; it cannot derive session keys without the token_id.

    browser client                relay (untrusted)              rmux daemon (host)
      ───────────────                ─────────────────              ──────────────────
            │                                │                                │
            │ WS Text: client_hello (JSON) ─►│ ─────────────────────────────► │  parse, lookup token_id,
            │                                │                                │  ML-KEM encapsulate, X25519 DH,
            │ ◄──────── WS Text: server_challenge (JSON) ◄────────────────────│  derive session keys
            │                                │                                │
            │ WS Binary: encrypted auth ───►│ ─────────────────────────────► │  open auth frame (proves token),
            │   frame {type:"auth",...}      │                                │  PIN+backoff+capacity checks
            │                                │                                │
            │ ◄──────── WS Binary: encrypted "ready" ◄────────────────────────│  session established
            │                                │                                │
            │ ◄═══════ encrypted records (terminal I/O, both directions) ═════► │
  8. What is RMUX and how does it work?

    main

    RMUX is a local terminal multiplexer that provides an optional end-to-end encrypted web sharing path.

    In a local runtime, the Daemon acts as the single authority for terminal state, managing shells, PTYs, panes, windows, scrollback, process state, and session metadata. All state remains on the local machine.

    Clients interact with the daemon via Local IPC (Unix sockets on Linux/macOS, named pipes on Windows) by sending typed requests and receiving typed responses or rendered output.

    For remote access, Web Share allows a selected pane or session to be exposed to a browser via an encrypted WebSocket protocol. This ensures that tunnel providers, reverse proxies, and relays cannot access terminal plaintext, as payloads are encrypted between the local daemon and the browser.

  9. Understand RMUX pane capabilities and state events

    main

    Certain SDK features depend on specific daemon capabilities:

    • Pane-local metadata and state streams: Requires sdk.pane.options and sdk.pane.state_events.
    • Foreground process data: Requires sdk.pane.foreground. This is a best-effort feature. On Unix, it reports the foreground process group. On Windows, it reports the ConPTY root process plus OSC7/process/profile cwd fallbacks.

    Pane State Lifecycle

    Closed events in the pane-state stream are terminal. Streams close upon:

    • Explicit kill/remove operations.
    • Normal pane removal.
    • Panes retained via remain-on-exit (these use PaneStateClosedReason::DiedKept).

    Note: For panes using remain-on-exit, the pane remains addressable for snapshots and captures even after the state stream has closed.

  10. Understand the rmux web-share E2EE security model

    main

    The rmux web-share protocol uses a hybrid end-to-end encryption (E2EE) layer to protect terminal content from untrusted relays (like share.rmux.io). It provides forward secrecy and post-quantum defense by combining multiple key agreement primitives.

    Key Security Properties

    • Hybrid Key Agreement: Combines ephemeral X25519 and ML-KEM-768 shared secrets. The key schedule mixes these with a high-entropy 256-bit share token using the formula: ikm = x25519_dh || ml_kem_shared_secret || SHA256(token).
    • Forward Secrecy: Even if a relay records traffic and later obtains the share token, they cannot decrypt past sessions because the per-connection X25519 and ML-KEM secrets are discarded.
    • Post-Quantum Defense: The channel remains secure against future quantum attacks on X25519 as long as ML-KEM-768 remains secure.
    • Authentication: The 256-bit share token is mixed into the key schedule. A relay cannot perform a Man-in-the-Middle (MITM) attack because they lack the token, which is never sent over the wire (only a truncated token_id is exposed).
    • PIN Security: The PIN is a secondary factor checked after the token-authenticated handshake. It is not fed into the Key Derivation Function (KDF), preventing offline brute-force attacks by a relay. Incorrect PIN attempts trigger exponential backoff via registry.rs.
  11. How the RMUX CLI dispatcher and helper work

    main

    RMUX uses a split CLI architecture to balance performance and capability:

    1. Tiny Dispatcher (Public CLI): A lightweight binary that parses a narrow allowlist of tmux-compatible commands and sends a single direct IPC request to the daemon. This is the primary rmux binary.
    2. Full CLI Helper (Private): A more robust binary located at libexec/rmux/rmux (Unix) or libexec/rmux/rmux.exe (Windows). It handles complex command forms, config loading, attached terminal setup, command queues, hooks, and long-lived streaming commands.

    Important for Packagers/Installers:

    • You must ship both the public tiny binary and the private helper together.
    • On Unix, install.sh typically installs the private helper and daemon before replacing the public tiny binary to maintain the bin/ and libexec/ layout.
    • On Windows (0.9 release), the split consists of rmux.exe (public), libexec/rmux/rmux.exe (private helper), and rmux-daemon.exe (daemon).

    Debugging: If you encounter compatibility issues with the tiny-path dispatcher, you can force the public binary to execute the full helper by setting the environment variable: RMUX_DISABLE_TINY_CLI=1

  12. How RMUX architecture works

    main

    RMUX operates on a client-server model where the core runtime (shells, sessions, windows, panes, and PTY processes) lives inside a local daemon.

    • Local Clients: Attach to the daemon via IPC (Inter-Process Communication).
    • Web Share: Exposes only the selected pane or session to a browser through an end-to-end encrypted WebSocket, keeping the rest of the environment secure and local.