feat: mobile API, enriched /health, mobileconfig module
Adds a persistent read-only HTTP listener (default port 8765, LAN-bound)
serving a dedicated subset of Numa's API for iOS/Android companion apps
and as a replacement for the one-shot server setup_phone used to spin up:
GET /health — enriched JSON with version, hostname, LAN IP,
SNI, DoT config, mobile API port, CA
fingerprint, features (shared handler with
the main API on port 5380)
GET /ca.pem — public CA certificate (shared handler)
GET /mobileconfig — full iOS profile (CA trust + DNS settings
pinned to current LAN IP)
GET /ca.mobileconfig — CA-only iOS profile (trust anchor without
DNS override — for the iOS companion app's
programmatic DNS flow via NEDNSSettingsManager)
All routes are idempotent GETs. The mobile API never serves the
state-mutating routes that live on the main API (overrides, blocking
toggle, service CRUD, cache flush), so it is safe to expose on the LAN
regardless of the main API's bind address. The CA private key is never
served by any route.
Opt-in via `[mobile] enabled = true`. Default is false so new installs
do not silently expose a LAN listener after upgrading; our committed
numa.toml template enables it explicitly for spike testing.
New modules:
- src/mobileconfig.rs — ProfileMode::{Full, CaOnly} enum with plist
builder lifted from setup_phone.rs. Full and CaOnly share the CA
payload UUID (same trust anchor) but have distinct top-level UUIDs
so they coexist as separate installable profiles on iOS.
- src/health.rs — HealthMeta cached metadata built once at startup
from config + CA fingerprint (SHA-256 of the PEM via ring), and the
HealthResponse JSON shape shared between the main and mobile APIs.
- src/mobile_api.rs — axum Router for the persistent listener. Reuses
api::health and api::serve_ca from the main API; owns the two
mobileconfig handlers.
Modified:
- src/api.rs — health() returns the enriched HealthResponse, now pub.
serve_ca is now pub so mobile_api can reuse it.
- src/config.rs — MobileConfig section (enabled, port, bind_addr).
- src/ctx.rs — health_meta: HealthMeta field on ServerCtx.
- src/main.rs — builds HealthMeta at startup, spawns mobile API
listener if enabled.
- src/lan.rs — build_announcement takes &HealthMeta and writes
enriched TXT records (version, api_port, proto, dot_port, ca_fp).
SRV port now reports the mobile API port; peer discovery still
reads TXT `services=` so this is backwards compatible. Always
announces even when no .numa services are registered, so the iOS
companion app can discover Numa via mDNS regardless of service
state.
- src/setup_phone.rs — reduced from 267 to 100 lines. The CLI is now
a thin QR wrapper over the persistent /mobileconfig endpoint; the
hand-rolled one-shot HTTP server (accept_loop, RUST_OK_HEADERS,
RUST_NOT_FOUND, download counter) is gone.
- src/dot.rs — test fixture updated with HealthMeta::test_fixture().
- numa.toml — commented [mobile] section, enabled = true for spike.
Tests: 136 unit tests passing (5 new in mobileconfig, 3 new in health).
cargo clippy clean. Integration sanity check: curl'd /health, /ca.pem,
/mobileconfig, /ca.mobileconfig against a running numa — all return
200 with correct content types and valid response bodies.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -31,6 +31,8 @@ pub struct Config {
|
||||
pub dnssec: DnssecConfig,
|
||||
#[serde(default)]
|
||||
pub dot: DotConfig,
|
||||
#[serde(default)]
|
||||
pub mobile: MobileConfig,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -412,6 +414,53 @@ fn default_dot_bind_addr() -> String {
|
||||
"0.0.0.0".to_string()
|
||||
}
|
||||
|
||||
/// Configuration for the mobile API — a persistent HTTP listener that
|
||||
/// serves a read-only subset of routes (`/health`, `/ca.pem`,
|
||||
/// `/mobileconfig`, `/ca.mobileconfig`) on a LAN-reachable port, for
|
||||
/// consumption by the iOS/Android companion apps.
|
||||
///
|
||||
/// Unlike the main API (port 5380, localhost-only by default, supports
|
||||
/// state-mutating routes), the mobile API is safe to expose on the LAN
|
||||
/// because every route is idempotent and read-only.
|
||||
#[derive(Deserialize, Clone)]
|
||||
pub struct MobileConfig {
|
||||
/// If true, spawn the mobile API listener at startup. **Default false.**
|
||||
/// Opt-in because the listener binds to the LAN by default and exposes
|
||||
/// a few read-only endpoints to any device on the same network (`/health`,
|
||||
/// `/ca.pem`, `/mobileconfig`, `/ca.mobileconfig`). None of those are
|
||||
/// cryptographically sensitive (the CA private key is never served),
|
||||
/// but users should enable this explicitly rather than have a new
|
||||
/// LAN-reachable port appear after an upgrade.
|
||||
#[serde(default)]
|
||||
pub enabled: bool,
|
||||
/// Port for the mobile API. Default 8765.
|
||||
#[serde(default = "default_mobile_port")]
|
||||
pub port: u16,
|
||||
/// Bind address for the mobile API. Default "0.0.0.0" (all interfaces)
|
||||
/// so phones on the LAN can reach it. Set to "127.0.0.1" to restrict
|
||||
/// to localhost — useful if you're running behind another front-end.
|
||||
#[serde(default = "default_mobile_bind_addr")]
|
||||
pub bind_addr: String,
|
||||
}
|
||||
|
||||
impl Default for MobileConfig {
|
||||
fn default() -> Self {
|
||||
MobileConfig {
|
||||
enabled: false,
|
||||
port: default_mobile_port(),
|
||||
bind_addr: default_mobile_bind_addr(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn default_mobile_port() -> u16 {
|
||||
8765
|
||||
}
|
||||
|
||||
fn default_mobile_bind_addr() -> String {
|
||||
"0.0.0.0".to_string()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user