Skip to content

Protocol Linux Helper

finthetechguy edited this page Nov 23, 2026 · 1 revision

Linux Helper and polkit

The desktop app runs as the user. Radio work needs root or network capabilities (see Linux Backend). The app therefore starts a separate privileged process, ctrpass serve, through polkit. The helper owns the radio. It never opens the user's files and never writes the user's store.

Implemented in: ctrpass serve in the command-line crate, the app's helper module, and the polkit files installed with the app.

Process layout

flowchart LR
    subgraph user["User session"]
        app["Desktop app"]
        store["User's store"]
        keys["Key file"]
    end
    subgraph root["Privileged"]
        helper["ctrpass serve -i IF"]
        copy["Private store copy in a temp folder"]
        radio["LinuxRadio"]
    end
    app -->|"pkexec"| helper
    app -->|"JSON commands on stdin"| helper
    helper -->|"JSON events on stdout"| app
    keys -->|"read by the app, sent as text"| app
    store -->|"snapshot"| app
    helper --- copy
    helper --- radio
    app -->|"files arrivals"| store
Loading

Starting the helper

The app builds the command line ctrpass serve -i <interface>, with --force when the user chose to take a connected card.

Condition Command run
The app runs as root ctrpass serve -i IF directly
Otherwise pkexec /path/to/ctrpass serve -i IF
CTRPASS_HELPER is set That command, split like a shell would, followed by serve -i IF
CTRPASS_BIN is set That binary instead of ctrpass from PATH

polkit

The installer puts two files in place.

Action

/usr/share/polkit-1/actions/io.github.finthetechguy.Ctrpass.policy defines the action io.github.finthetechguy.Ctrpass.serve:

Setting Value
Program <prefix>/bin/ctrpass (the exec.path annotation)
Active sessions auth_admin_keep: administrator password, remembered for a short time
Inactive sessions Not allowed
Any other subject Not allowed

Optional rule

/etc/polkit-1/rules.d/50-io.github.finthetechguy.Ctrpass.rules lets members of one group start the helper without a password. It returns "yes" only when all of these hold:

  • the action is io.github.finthetechguy.Ctrpass.serve;
  • the subject is in an active session and in the group (default ctrpass);
  • the program is the installed ctrpass binary;
  • the command line is exactly <binary> serve -i <name> or <binary> serve -i <name> --force, where <name> is 1 to 15 characters of letters, digits, _, . or -.

Any other use of ctrpass through pkexec still asks for a password. Installing with --no-rule leaves the rule out. --user NAME adds that user to the group, which takes effect after logging in again.

Protocol between app and helper

One JSON object per line in each direction.

sequenceDiagram
    participant A as App
    participant H as Helper
    A->>H: start through pkexec
    H->>A: hello (version, interface)
    H->>A: state idle
    A->>H: keys (key file text)
    H->>A: keys (title IDs with signing keys, whether the Mii key is present)
    A->>H: load (store snapshot)
    H->>A: loaded (MAC, title count, message count)
    A->>H: exchange (role, channels, window, passes, radio, rotate_every)
    H->>A: radio (MAC, mixed, channels)
    H->>A: state exchanging
    H->>A: engaged, link_up, finished or abandoned
    H->>A: pass (report, arrived messages in hex, peer book)
    Note over A: Files the arrivals and peer book in the user's store
    A->>H: stop
    H->>A: state idle
    A->>H: quit
Loading

Commands

cmd Fields Effect
keys text Parse the key file text. The app reads the file as the user.
load store: a snapshot Restore the snapshot into a new private store in a temporary folder with mode 0700. Replaces any earlier copy.
scan channels (default 1, 6, 11), dwell seconds (default 0.5) Open the radio in Listen mode and scan rounds until stopped
exchange role: lead, wait or alternate (default lead); channels; window seconds (default 60); passes (default: until stopped); radio: auto, active or mixed; rotate_every seconds (default 28800, 0 for never) Run passes from the store copy
rotate Change the MAC and clear the filter now, also during an exchange
stop End the current scan or exchange
quit Exit

alternate switches between Lead and Wait on every pass. While a scan or exchange runs, only stop, quit and rotate are acted on. Other commands get an error event.

Events

event Fields When
hello version, interface At start
state state: idle, scanning, exchanging On each change
error message On a bad command or a failure
keys titles, record After keys
loaded mac, titles, messages After load
found console: MAC, token, channel, signal, services, titles During a scan
radio mac, mixed, channels Each time the radio is opened for an exchange
engaged, declined, link_up, finished peer During a pass
abandoned peer, reason During a pass
pass pass, role, peer, sent, refused, received, not_filed, messages, peers After a pass that engaged a console
rotated mac, peers After a MAC rotation

The app adds its own exit event with the exit code and the last lines of the helper's standard error when the process ends.

Exchange loop in the helper

flowchart TD
    start["exchange command"] --> open["Open LinuxRadio with the store copy's MAC"]
    open --> fixed{"Mixed mode?"}
    fixed -- yes --> ch1["Use channel 1 only"]
    fixed -- no --> chs["Use the channels given"]
    ch1 --> loop
    chs --> loop{"More passes?"}
    loop -- no --> idle["state idle"]
    loop -- yes --> due{"Rotation due?"}
    due -- yes --> rot["rotated event"] --> open
    due -- no --> pass["run_pass"]
    pass --> rep["pass event with arrivals and peer book"]
    rep --> cmd{"Command waiting?"}
    cmd -- rotate --> rot2["Rotate now, rotated event"] --> open
    cmd -- "stop or quit" --> idle
    cmd -- none --> loop
Loading

Who writes the user's store

The helper exchanges from its private copy. After each pass it sends the arrived messages as hex and the copy's peer book. The app, running as the user:

  1. files the messages into the user's store with the same inbound rules as an exchange (signature check, all-or-nothing room per title);
  2. replaces the user's peer book with the helper's.

After a rotation, the app also stores the new peer book. The private copy is deleted when the helper loads a new snapshot or exits.

Clone this wiki locally