From b0cd7b824e7691f3d36d9f44a134fe96234e0ce5 Mon Sep 17 00:00:00 2001 From: BlackRockCity Date: Fri, 9 Oct 2026 22:54:44 -0600 Subject: [PATCH 1/7] docs: add macOS iOS MITM onboarding guide Documents a macOS-assisted workflow for authenticating the official Roborock iOS app with local_roborock_server. Covers mitmproxy certificate setup via AirDrop, WireGuard onboarding, verification-code login, authentication handoff, reverse-proxy requirements, validation, cleanup, and troubleshooting. --- docs/ios_mitm_onboarding.md | 120 ++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 docs/ios_mitm_onboarding.md diff --git a/docs/ios_mitm_onboarding.md b/docs/ios_mitm_onboarding.md new file mode 100644 index 00000000..309fe0d7 --- /dev/null +++ b/docs/ios_mitm_onboarding.md @@ -0,0 +1,120 @@ +# Roborock Local Server: macOS iPhone MITM Login Helper + +An interactive Bash wrapper for the **official Roborock iOS app** login procedure used with [Python-roborock/local_roborock_server](https://github.com/Python-roborock/local_roborock_server). + +**Status:** Community-contributed workflow, not an upstream-supported installer. The wrapper described here has not been independently end-to-end tested in its latest form. Review it and test against your installed `mitm_redirect.py` before distributing it. + +## What this does + +Once a vacuum has already been provisioned to Roborock Local Server, the official iOS app may need a one-time intercepted login so that its protocol authentication session can be synchronized to the local server. This helper walks the operator through that temporary process on a **Mac**: + +- Checks whether the iPhone already trusts the Mac's mitmproxy CA. +- If needed, finds or generates the CA certificate on the Mac, opens it in Finder, and instructs the operator to AirDrop it to the iPhone. +- Coordinates obtaining the Roborock email verification code **before** enabling the WireGuard tunnel. +- Preflights the local server's protocol-sync endpoint and secret. +- Starts the repository's `mitm_redirect.py` with the explicit HTTPS endpoint, including `:443` when a reverse proxy terminates TLS on port 443. +- Guides WireGuard QR enrollment and verification-code submission. +- Waits for manual confirmation that robot status and map work, then verifies the app again with WireGuard **off**. +- Stops the temporary MITM process and reminds the operator to disable trust in the temporary CA. + +**This is not vacuum Wi-Fi onboarding.** First complete the upstream [Installation](https://github.com/Python-roborock/local_roborock_server/blob/main/docs/installation.md) and [Onboarding](https://github.com/Python-roborock/local_roborock_server/blob/main/docs/onboarding.md) instructions. This helper supplements the [Official Roborock App](https://github.com/Python-roborock/local_roborock_server/blob/main/docs/roborock_app.md) section. + +## Requirements + +- macOS computer with Bash, `curl`, `open`, and [`uv`](https://docs.astral.sh/uv/). +- A checkout of `local_roborock_server` or a directory containing its `mitm_redirect.py`, `pyproject.toml`, and `uv.lock`. +- The companion `roborock_onboard.sh` script, placed beside `mitm_redirect.py`. +- An operational Roborock Local Server instance, with vacuum already paired and account data imported. +- A valid HTTPS hostname for the local server, reachable from the Mac. +- Current **Protocol Auth / `admin.session_secret`** from the *running* server's admin dashboard. +- An iPhone with the official Roborock app and WireGuard installed, and the ability to receive the Roborock login email. +- AirDrop between the Mac and iPhone, if the CA is not already installed. + +The script assumes the server's protocol-sync callback is accessible at `https://:443/internal/protocol/user-data`. This matches one tested reverse-proxy layout; other port arrangements need script adjustments. + +## Files + +```text +local_roborock_server/ +├── roborock_onboard.sh # Community helper; add this file +├── mitm_redirect.py # Upstream script +├── pyproject.toml # Upstream dependencies +├── uv.lock # Upstream lockfile +└── ... +``` + +The Bash wrapper is not a replacement for `mitm_redirect.py`. If your local Python file has a development filename such as `mitm_redirect_fixed_v2.py`, confirm it is compatible and rename/copy it to `mitm_redirect.py` before running the wrapper. + +## Quick start + +From the directory containing the scripts: + +```bash +chmod +x roborock_onboard.sh +./roborock_onboard.sh +``` + +The script prompts for your HTTPS hostname and current protocol-sync secret on first use. It stores them in `.roborock_onboard.conf` with permissions `0600`. **That file contains a sensitive credential:** do not commit, upload, share, or back it up to an untrusted location. Add `.roborock_onboard.conf`, `.roborock_mitm.pid`, and `roborock_mitm.log` to `.gitignore` before publishing the helper. + +Other commands: + +```bash +./roborock_onboard.sh status # Check for the expected MITM process +./roborock_onboard.sh stop # Stop a tracked/recognized MITM process +./roborock_onboard.sh config # Replace saved hostname and secret +``` + +## Guided iPhone workflow + +1. **Certificate:** Keep WireGuard off. If the iPhone lacks the mitmproxy CA, the helper checks `~/.mitmproxy/mitmproxy-ca-cert.cer`, attempts to generate the CA locally if absent, and opens Finder with the file selected. AirDrop it to the iPhone, install it under **Settings → General → VPN & Device Management**, then enable **Full Trust** under **Settings → General → About → Certificate Trust Settings**. The certificate must be generated by the *same mitmproxy installation* that will intercept traffic. Never download a stranger's root CA or distribute the private key. +2. **Email code:** With WireGuard still **off**, request a fresh Roborock verification code. Leave the app on the code-entry screen without submitting it. +3. **Preflight:** The helper posts a deliberately incomplete payload to `/internal/protocol/user-data`. HTTP `400` with `code: 40041` and `reason: missing_user_data` is the expected success signal for this particular preflight. An unexpected response requires investigation. +4. **MITM:** The helper starts the MITM launcher on the Mac. Its web interface exposes a WireGuard QR code at `http://127.0.0.1:8081/#/capture` (open this **on the Mac**). +5. **WireGuard and login:** Scan the QR code with WireGuard on the iPhone to create a new tunnel, enable it, then return to the Roborock app and submit the code obtained earlier. +6. **Check intercepted session:** Confirm the robot appears and both status and map load. This can take around 1.5 minutes; there is **no fixed timeout** in the helper. Proceed only when successful. Inspect `roborock_mitm.log` for synchronization errors. +7. **Check normal operation:** Force-quit Roborock, switch WireGuard **off**, reopen the app, and verify that the robot, status, map, and controls still work without the tunnel. +8. **Cleanup:** The helper stops the MITM process. Disable Full Trust for the mitmproxy CA on the iPhone. The installed profile can remain for future recovery, but should not remain trusted between sessions. + +If onboarding is interrupted after MITM starts, the script attempts to stop MITM and prints a reminder to turn off WireGuard and certificate trust. **Always verify these settings manually.** + +## Reverse-proxy note + +If your public HTTPS entry point is a reverse proxy (for example, pfSense HAProxy on `443`) forwarding to the local server's internal HTTPS port (commonly `555`), configure the MITM callback with the **externally reachable port**: + +```bash +uv run mitm_redirect.py \ + --local-api https://api-roborock.example.com:443 \ + --sync-secret 'YOUR_CURRENT_ADMIN_SESSION_SECRET' +``` + +Do not assume the upstream default `:555` is reachable from the Mac. Avoid exposing the local server's internal management port directly to the Internet. Prefer private DNS/network access where practical, and follow upstream guidance on securing the server. + +## Troubleshooting + +| Symptom | Check | +| --- | --- | +| `mitm.it` says traffic is not going through mitmproxy | Expected when the iPhone is not routed through the MITM instance. This helper uses **Mac-generated certificate + AirDrop**, not `mitm.it`, for initial certificate transfer. | +| TLS/certificate error during intercepted login | Ensure the installed CA matches the Mac's current `~/.mitmproxy` CA and **Full Trust** is enabled. | +| Verification email does not arrive | Turn WireGuard off, request a new code, and only enable WireGuard before submitting it. | +| Preflight fails | Verify DNS, HTTPS certificate, reverse-proxy routing, callback path, and the active `admin.session_secret`. | +| `Address already in use` | Check for an earlier MITM process and run `./roborock_onboard.sh status` or `stop`. Do not terminate unrelated listeners. | +| App works with WireGuard on but not off | Do not declare success. Inspect the protocol-auth sync result and local server logs. | +| Certificate is absent from the Mac | The wrapper attempts local generation via `mitmdump`/`uv`; verify that the correct CA was generated before installing it. | + +## Security and implementation caveats + +- Temporarily trusting a custom root CA permits interception of TLS traffic routed through that proxy. Use only a Mac and iPhone you control, and revoke trust immediately afterward. +- The CA **private key** must stay on the Mac. Only AirDrop `mitmproxy-ca-cert.cer`, never `mitmproxy-ca.pem` or `mitmproxy-ca.p12`. +- The script stores a sensitive server secret in a local config file. Its process command line may also expose the secret to other local processes/users. Consider a more restrictive credential-handling design before upstreaming. +- The helper's process detection and cleanup are best-effort and should be tested with the actual installed launcher and `uv` version. Existing MITM instances may have different command lines. +- The certificate-generation fallback starts and stops `mitmdump`; verify it does not interfere with any existing proxy instance. +- The success prompts rely on **user confirmation**; the script does not programmatically prove that the map or controls work. +- This helper targets the **official iOS app** and has not been validated as an Android onboarding tool. + +## Contributing upstream + +If the maintainer would like this included, propose it as an **optional macOS helper** alongside an update to `docs/roborock_app.md`. Keep the upstream's normal manual procedure available. Test the complete flow and avoid adding machine-specific hostnames, secrets, certificates, or logs to the pull request. + +Upstream repository: https://github.com/Python-roborock/local_roborock_server + +License and attribution should follow the upstream project's contribution requirements. From 0d0c0197fd0717beb9713d5e9bcdf08fe001d52e Mon Sep 17 00:00:00 2001 From: BlackRockCity Date: Fri, 9 Oct 2026 23:01:11 -0600 Subject: [PATCH 2/7] feat: add interactive macOS iOS onboarding helper Adds an interactive Bash wrapper for the existing Roborock iOS MITM authentication workflow on macOS. The helper validates the local server endpoint, manages the mitmproxy CA certificate and temporary MITM process, guides WireGuard and verification-code authentication, verifies the local authentication handoff, and performs cleanup. --- roborock_onboard.sh | 642 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 642 insertions(+) create mode 100644 roborock_onboard.sh diff --git a/roborock_onboard.sh b/roborock_onboard.sh new file mode 100644 index 00000000..aa7d3291 --- /dev/null +++ b/roborock_onboard.sh @@ -0,0 +1,642 @@ +#!/usr/bin/env bash + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +CONFIG_FILE="$SCRIPT_DIR/.roborock_onboard.conf" +PID_FILE="$SCRIPT_DIR/.roborock_mitm.pid" +LOG_FILE="$SCRIPT_DIR/roborock_mitm.log" +MITM_SCRIPT="$SCRIPT_DIR/mitm_redirect.py" + +MITM_CERT="$HOME/.mitmproxy/mitmproxy-ca-cert.cer" + +MITM_ACTIVE=0 +NORMAL_CLEANUP=0 + + +header() { + echo + echo "============================================================" + echo " $1" + echo "============================================================" + echo +} + + +save_config() { + umask 077 + cat > "$CONFIG_FILE" </dev/null | head -n 1 || true +} + + +kill_mitm_quietly() { + if [[ -f "$PID_FILE" ]]; then + PID="$(cat "$PID_FILE" 2>/dev/null || true)" + + if [[ -n "${PID:-}" ]] && kill -0 "$PID" 2>/dev/null; then + kill "$PID" 2>/dev/null || true + sleep 1 + + if kill -0 "$PID" 2>/dev/null; then + kill -9 "$PID" 2>/dev/null || true + fi + fi + + rm -f "$PID_FILE" + fi + + EXISTING_PID="$(find_existing_mitm)" + + if [[ -n "$EXISTING_PID" ]]; then + kill "$EXISTING_PID" 2>/dev/null || true + sleep 1 + + if kill -0 "$EXISTING_PID" 2>/dev/null; then + kill -9 "$EXISTING_PID" 2>/dev/null || true + fi + fi + + MITM_ACTIVE=0 +} + + +emergency_cleanup() { + EXIT_CODE=$? + + trap - EXIT INT TERM HUP + + if [[ "$NORMAL_CLEANUP" -eq 0 && "$MITM_ACTIVE" -eq 1 ]]; then + header "ONBOARDING ABORTED" + + echo "Stopping temporary MITM server..." + echo + + kill_mitm_quietly + + echo "✓ MITM server stopped." + echo + echo "IMPORTANT: On the iPhone:" + echo + echo " 1. Turn WireGuard OFF." + echo " 2. Go to:" + echo + echo " Settings" + echo " → General" + echo " → About" + echo " → Certificate Trust Settings" + echo + echo " 3. Turn OFF Enable Full Trust for the mitmproxy certificate." + echo + fi + + exit "$EXIT_CODE" +} + + +trap emergency_cleanup EXIT INT TERM HUP + + +stop_mitm() { + header "STOP MITM SERVER" + + STOPPED=0 + + if [[ -f "$PID_FILE" ]]; then + PID="$(cat "$PID_FILE" 2>/dev/null || true)" + + if [[ -n "${PID:-}" ]] && kill -0 "$PID" 2>/dev/null; then + kill "$PID" 2>/dev/null || true + sleep 2 + + if kill -0 "$PID" 2>/dev/null; then + kill -9 "$PID" 2>/dev/null || true + fi + + echo "✓ MITM server stopped (PID $PID)." + STOPPED=1 + fi + + rm -f "$PID_FILE" + fi + + EXISTING_PID="$(find_existing_mitm)" + + if [[ -n "$EXISTING_PID" ]]; then + kill "$EXISTING_PID" 2>/dev/null || true + sleep 2 + + if kill -0 "$EXISTING_PID" 2>/dev/null; then + kill -9 "$EXISTING_PID" 2>/dev/null || true + fi + + echo "✓ Existing MITM server stopped (PID $EXISTING_PID)." + STOPPED=1 + fi + + MITM_ACTIVE=0 + + if [[ "$STOPPED" -eq 0 ]]; then + echo "MITM server is not running." + fi +} + + +status_mitm() { + header "MITM SERVER STATUS" + + EXISTING_PID="$(find_existing_mitm)" + + if [[ -n "$EXISTING_PID" ]]; then + echo "✓ MITM server is running." + echo "PID: $EXISTING_PID" + echo "Log: $LOG_FILE" + else + echo "MITM server is not running." + fi +} + + +configure() { + rm -f "$CONFIG_FILE" + unset ROBOROCK_DOMAIN SYNC_SECRET + + header "ROBOROCK CONFIGURATION" + + load_config + + echo + echo "✓ Configuration saved." + echo + echo "File:" + echo "$CONFIG_FILE" + echo + echo "Permissions are restricted to your user." +} + + +generate_mitm_certificate() { + echo "The mitmproxy CA certificate was not found." + echo + echo "Generating the mitmproxy CA on this Mac..." + echo + + mkdir -p "$HOME/.mitmproxy" + + if command -v mitmdump >/dev/null 2>&1; then + + mitmdump --set confdir="$HOME/.mitmproxy" >/dev/null 2>&1 & + GEN_PID=$! + + sleep 3 + + kill "$GEN_PID" 2>/dev/null || true + wait "$GEN_PID" 2>/dev/null || true + + elif command -v uv >/dev/null 2>&1; then + + ( + cd "$SCRIPT_DIR" + + uv run mitmdump \ + --set confdir="$HOME/.mitmproxy" \ + >/dev/null 2>&1 & + + GEN_PID=$! + + sleep 3 + + kill "$GEN_PID" 2>/dev/null || true + wait "$GEN_PID" 2>/dev/null || true + ) + + else + echo "✗ FAILED: Neither mitmdump nor uv was found." + echo + echo "The script cannot generate the mitmproxy CA." + exit 1 + fi + + if [[ ! -f "$MITM_CERT" ]]; then + echo "✗ FAILED: mitmproxy did not create:" + echo + echo " $MITM_CERT" + echo + exit 1 + fi + + echo "✓ SUCCESS: mitmproxy CA generated." +} + + +prepare_iphone_certificate() { + header "STEP 1: PREPARE THE IPHONE" + + echo "IMPORTANT: Leave WireGuard OFF for now." + echo + + while true; do + read -rp "Is the mitmproxy CA certificate already installed on this iPhone? [y/N]: " CERT_INSTALLED + + case "${CERT_INSTALLED:-n}" in + + y|Y|yes|YES|Yes) + + echo + echo "The certificate is already installed." + echo + echo "On the iPhone go to:" + echo + echo " Settings" + echo " → General" + echo " → About" + echo " → Certificate Trust Settings" + echo + echo "Under 'Enable Full Trust for Root Certificates':" + echo + echo " Turn ON the mitmproxy certificate." + echo + echo "IMPORTANT: Keep WireGuard OFF." + echo + + read -rp "Press ENTER after Full Trust is ON..." + break + ;; + + + n|N|no|NO|No|"") + + echo + echo "The certificate needs to be transferred from this Mac." + echo + + if [[ -f "$MITM_CERT" ]]; then + echo "✓ Found the mitmproxy CA certificate:" + echo + echo " $MITM_CERT" + else + generate_mitm_certificate + fi + + echo + echo "Opening Finder with the certificate selected..." + + open -R "$MITM_CERT" 2>/dev/null || true + + echo + echo "On the Mac:" + echo + echo " 1. Finder should now show:" + echo + echo " mitmproxy-ca-cert.cer" + echo + echo " 2. AirDrop that file to the iPhone." + echo + echo "On the iPhone:" + echo + echo " 3. Accept the AirDrop." + echo + echo " 4. Go to:" + echo + echo " Settings" + echo " → General" + echo " → VPN & Device Management" + echo + echo " 5. Select the mitmproxy profile and install it." + echo + echo " 6. Then go to:" + echo + echo " Settings" + echo " → General" + echo " → About" + echo " → Certificate Trust Settings" + echo + echo " 7. Under 'Enable Full Trust for Root Certificates'," + echo " turn ON the mitmproxy certificate." + echo + echo "IMPORTANT:" + echo "Installing the certificate profile is not enough." + echo "Full Trust must also be enabled." + echo + echo "Keep WireGuard OFF." + echo + + read -rp "Press ENTER after the certificate is installed and Full Trust is ON..." + break + ;; + + + *) + echo "Please answer y or n." + ;; + esac + done +} + + +start() { + load_config + + if [[ ! -f "$MITM_SCRIPT" ]]; then + echo "ERROR: Cannot find:" + echo + echo " $MITM_SCRIPT" + echo + echo "roborock_onboard.sh and mitm_redirect.py should be" + echo "in the same project directory." + exit 1 + fi + + header "ROBOROCK LOCAL SERVER ONBOARDING" + + echo "Domain: $ROBOROCK_DOMAIN" + + prepare_iphone_certificate + + + header "STEP 2: GET THE ROBOROCK VERIFICATION CODE" + + echo "With WireGuard STILL OFF:" + echo + echo " 1. Open the official Roborock iOS app." + echo " 2. Enter the Roborock account email address." + echo " 3. Request a fresh email verification code." + echo " 4. Wait for the verification code to arrive." + echo " 5. Leave the Roborock app at the code-entry screen." + echo + echo "DO NOT submit the verification code yet." + echo + + read -rp "Press ENTER after you have the code and have NOT submitted it..." + + + header "STEP 3: VERIFY LOCAL SERVER ENDPOINT" + + PREFLIGHT_RESPONSE="$( + curl --http1.1 -sS \ + -w $'\n%{http_code}' \ + "https://${ROBOROCK_DOMAIN}/internal/protocol/user-data" \ + -H 'Content-Type: application/json' \ + -H "X-Local-Sync-Secret: ${SYNC_SECRET}" \ + --data-binary '{"source":"mitm_preflight"}' + )" || { + echo "✗ FAILED: Could not connect to the local Roborock server." + exit 1 + } + + HTTP_CODE="${PREFLIGHT_RESPONSE##*$'\n'}" + RESPONSE_BODY="${PREFLIGHT_RESPONSE%$'\n'*}" + + if [[ "$HTTP_CODE" == "400" ]] && + [[ "$RESPONSE_BODY" == *'"code":40041'* ]] && + [[ "$RESPONSE_BODY" == *'"reason":"missing_user_data"'* ]]; then + + echo "✓ SUCCESS: Local Roborock server is reachable and ready." + + elif [[ "$HTTP_CODE" =~ ^2[0-9][0-9]$ ]]; then + + echo "✓ SUCCESS: Local Roborock server accepted the preflight request." + + else + echo "✗ FAILED: Local Roborock server preflight check failed." + echo + echo "HTTP status: $HTTP_CODE" + echo "Response:" + echo "$RESPONSE_BODY" + exit 1 + fi + + + header "STEP 4: START MITM SERVER" + + EXISTING_PID="$(find_existing_mitm)" + + if [[ -n "$EXISTING_PID" ]] && + kill -0 "$EXISTING_PID" 2>/dev/null; then + + echo "✓ MITM server is already running." + echo " Reusing the existing server." + echo " PID: $EXISTING_PID" + + MITM_PID="$EXISTING_PID" + MITM_ACTIVE=1 + + else + + rm -f "$PID_FILE" + + cd "$SCRIPT_DIR" + + nohup uv run "$MITM_SCRIPT" \ + --local-api "https://${ROBOROCK_DOMAIN}:443" \ + --sync-secret "$SYNC_SECRET" \ + >"$LOG_FILE" 2>&1 & + + MITM_PID=$! + echo "$MITM_PID" > "$PID_FILE" + MITM_ACTIVE=1 + + sleep 3 + + if ! kill -0 "$MITM_PID" 2>/dev/null; then + + MITM_ACTIVE=0 + + echo "✗ FAILED: MITM server exited during startup." + echo + + if grep -q "Address already in use" "$LOG_FILE" 2>/dev/null; then + echo "The MITM listening port is already in use." + echo + echo "Another MITM process may already be running." + echo + echo "Run:" + echo + echo " $0 stop" + echo + echo "Then start onboarding again." + else + echo "MITM server output:" + echo + cat "$LOG_FILE" + fi + + rm -f "$PID_FILE" + exit 1 + fi + + echo "✓ SUCCESS: MITM server started." + echo "PID: $MITM_PID" + echo "Log: $LOG_FILE" + fi + + + header "STEP 5: CONNECT WIREGUARD AND SUBMIT LOGIN" + + echo "On the iPhone:" + echo + echo " 1. Create a NEW Roborock WireGuard tunnel." + echo " Scan the QR code on the MITM website." + echo " A new tunnel must be created each time." + echo + echo " 2. Turn ON the newly created WireGuard tunnel." + echo + echo " 3. Return to the Roborock app." + echo " It should still be waiting at the verification-code screen." + echo + echo " 4. Enter the verification code you obtained while" + echo " WireGuard was OFF." + echo + echo " 5. Submit the login." + echo + echo "The verification-code submission MUST occur with WireGuard ON." + echo + + read -rp "Press ENTER after the Roborock login succeeds..." + + + header "STEP 6: VERIFY ROBOT THROUGH MITM" + + echo "Keep WireGuard ON." + echo "Keep the MITM server running." + echo + echo "In the Roborock app:" + echo + echo " 1. Confirm the Saros 10R appears." + echo " 2. Open the robot's device screen." + echo " 3. Confirm its status loads." + echo " 4. Confirm the MAP loads." + echo + echo "This can take approximately 1.5 minutes." + echo "Do not continue until the robot status and map are working." + echo + + read -rp "Press ENTER after the robot status and map have loaded successfully..." + + + header "STEP 7: TEST WITHOUT THE MITM TUNNEL" + + echo "Leave the MITM server running on this Mac for now." + echo + echo "On the iPhone:" + echo + echo " 1. FORCE-QUIT the Roborock app." + echo " 2. Turn WireGuard OFF." + echo " 3. Reopen the Roborock app normally." + echo " 4. Confirm the Saros 10R appears." + echo " 5. Open the robot's device screen." + echo " 6. Confirm its status loads." + echo " 7. Confirm the map loads." + echo " 8. Confirm normal controls work." + echo + echo "This verifies that the authentication handoff succeeded." + echo + echo "DO NOT continue if the app fails this test." + echo + + read -rp "Press ENTER only after the app works normally with WireGuard OFF..." + + + header "STEP 8: SHUT DOWN MITM" + + echo "Authentication handoff confirmed." + echo + echo "Stopping the temporary MITM server..." + echo + + stop_mitm + + + header "STEP 9: CERTIFICATE CLEANUP" + + echo "On the iPhone:" + echo + echo " 1. Confirm WireGuard is OFF." + echo + echo " 2. Go to:" + echo + echo " Settings" + echo " → General" + echo " → About" + echo " → Certificate Trust Settings" + echo + echo " 3. Turn OFF 'Enable Full Trust' for the mitmproxy certificate." + echo + echo "You may leave the certificate/profile installed." + echo "That makes future recovery easier if the Roborock session expires." + echo + + read -rp "Press ENTER after Full Trust is OFF..." + + NORMAL_CLEANUP=1 + + + header "ONBOARDING COMPLETE" + + echo "✓ Roborock authentication handoff completed." + echo "✓ WireGuard is OFF." + echo "✓ MITM server is stopped." + echo "✓ mitmproxy Full Trust is OFF." + echo + echo "The Roborock app should now operate normally through" + echo "local_roborock_server without the temporary MITM tunnel." +} + + +case "${1:-start}" in + + start) + start + ;; + + stop) + stop_mitm + NORMAL_CLEANUP=1 + ;; + + status) + status_mitm + NORMAL_CLEANUP=1 + ;; + + config) + configure + NORMAL_CLEANUP=1 + ;; + + *) + echo "Usage: $0 {start|stop|status|config}" + NORMAL_CLEANUP=1 + exit 1 + ;; +esac From dfd149bb1e705792a20d9bf5a8a2b9e02f163cc4 Mon Sep 17 00:00:00 2001 From: BlackRockCity Date: Fri, 9 Oct 2026 23:03:08 -0600 Subject: [PATCH 3/7] chore: ignore iOS onboarding runtime files Prevent locally generated onboarding configuration, PID, and log files from being committed. The configuration file may contain the user's local server domain and protocol sync secret. --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 1e8c21ed..e04d4559 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,8 @@ secrets/ config.toml mitm_logs .tmp* + +# Roborock iOS onboarding helper runtime files +.roborock_onboard.conf +.roborock_mitm.pid +roborock_mitm.log From 9dc4ece871a33c375eaa1f78f7ee046247a8845b Mon Sep 17 00:00:00 2001 From: BlackRockCity Date: Sun, 18 Oct 2026 20:53:19 -0600 Subject: [PATCH 4/7] feat: improve iOS onboarding wizard UI and documentation Enhances the Bash onboarding wizard with ANSI colors, Unicode progress indicators, improved instructions, authenticated MITM browser navigation, and extensive developer-facing comments. --- roborock_onboard.sh | 331 ++++++++++++++++++++++++++++++++------------ 1 file changed, 246 insertions(+), 85 deletions(-) diff --git a/roborock_onboard.sh b/roborock_onboard.sh index aa7d3291..449eb395 100644 --- a/roborock_onboard.sh +++ b/roborock_onboard.sh @@ -1,28 +1,90 @@ #!/usr/bin/env bash +# Stop on an unhandled command failure (-e), an unset variable (-u), or a +# failed command inside a pipeline (pipefail). Expected failures are handled +# explicitly with conditionals or `|| true` throughout the wizard. set -euo pipefail +# Keep all wizard files beside this script, regardless of the directory from +# which it is launched. BASH_SOURCE identifies this file; quoting preserves +# paths containing spaces. The hidden configuration contains the session secret; +# the PID file records the temporary server process; the log records its output. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" CONFIG_FILE="$SCRIPT_DIR/.roborock_onboard.conf" PID_FILE="$SCRIPT_DIR/.roborock_mitm.pid" LOG_FILE="$SCRIPT_DIR/roborock_mitm.log" MITM_SCRIPT="$SCRIPT_DIR/mitm_redirect.py" +# mitmproxy generates this public CA certificate in the current user's home. +# Installing it on the iPhone and enabling Full Trust are separate actions. MITM_CERT="$HOME/.mitmproxy/mitmproxy-ca-cert.cer" +# Cleanup state: active means the wizard has started or accepted responsibility +# for a server. Normal cleanup is set only after the intended workflow completes. +# These flags let the exit handler distinguish completion from interruption. MITM_ACTIVE=0 NORMAL_CLEANUP=0 +# Styling is enabled only for an interactive, color-capable terminal. +UI_COLOR=0 +if [[ -t 1 && -z "${NO_COLOR:-}" && "${TERM:-dumb}" != "dumb" ]]; then + UI_COLOR=1 +fi +if (( UI_COLOR )); then + C_RESET=$'\033[0m' + C_CYAN=$'\033[1;36m' + C_GREEN=$'\033[1;32m' + C_YELLOW=$'\033[1;33m' + C_RED=$'\033[1;31m' + C_DIM=$'\033[2m' +else + C_RESET='' C_CYAN='' C_GREEN='' C_YELLOW='' C_RED='' C_DIM='' +fi + +# Draw the shared heading. Titles of the form "STEP N: ..." receive a step +# counter and progress circles; other titles receive the general wizard label. +# All styling variables are empty when color is disabled, keeping output readable. header() { - echo - echo "============================================================" - echo " $1" - echo "============================================================" - echo + local title="$1" step=0 label progress='' i + if [[ "$title" =~ ^STEP[[:space:]]([1-9]):[[:space:]](.*)$ ]]; then + step="${BASH_REMATCH[1]}" + title="${BASH_REMATCH[2]}" + label="STEP ${step} / 9" + else + label="ROBOROCK iOS ONBOARDING" + fi + printf '\n%s╭──────────────────────────────────────────────────────────╮%s\n' "$C_CYAN" "$C_RESET" + printf '%s│ %-56.56s │%s\n' "$C_CYAN" "$label" "$C_RESET" + if (( step > 0 )); then + for ((i=1; i<=9; i++)); do + if ((i<=step)); then progress+='●'; else progress+='○'; fi + done + # Nine Unicode circles occupy nine terminal cells, but more bytes. + # Use a separate ASCII-space field so printf never measures their bytes. + printf '%s│ %s%*s │%s\n' "$C_CYAN" "$progress" 47 '' "$C_RESET" + fi + printf '%s╰──────────────────────────────────────────────────────────╯%s\n' "$C_CYAN" "$C_RESET" + printf '\n%s %s%s\n\n' "$C_CYAN" "$title" "$C_RESET" } +# Display colored status markers without changing the actual workflow. +ui_success() { printf '%s✓ %s%s\n' "$C_GREEN" "$*" "$C_RESET"; } +ui_error() { printf '%s✗ %s%s\n' "$C_RED" "$*" "$C_RESET"; } +ui_warning() { printf '%s! %s%s\n' "$C_YELLOW" "$*" "$C_RESET"; } +# Pause at a human checkpoint. Nothing proceeds until Enter is pressed. +# Ctrl+C invokes the cleanup handler registered below. +ui_pause() { + printf '\n%s────────────────────────────────────────────────────────────%s\n' "$C_DIM" "$C_RESET" + printf '%s [ENTER] %s [Ctrl+C] Cancel%s ' "$C_CYAN" "$1" "$C_RESET" + read -r +} + +# Persist the domain and admin session secret so later runs need not ask again. +# umask 077 limits newly created files to this user; chmod also restricts an +# existing configuration file. This file is sourced as shell code on later runs, +# so treat it as a trusted local file and do not share it. save_config() { umask 077 cat > "$CONFIG_FILE" <