Skip to content

Add interactive macOS helper for Roborock iOS authentication - #149

Merged
Lash-L merged 8 commits into
Python-roborock:mainfrom
BlackRockCity:ios-mitm-onboarding-helper
Nov 29, 2026
Merged

Lash-L merged 8 commits into
Python-roborock:mainfrom
BlackRockCity:ios-mitm-onboarding-helper

Conversation

@BlackRockCity

@BlackRockCity BlackRockCity commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds an interactive macOS Bash wizard for connecting the official Roborock iOS app to an already configured Roborock Local Server.

The existing MITM login procedure requires carefully ordered certificate, email-code, and WireGuard steps. roborock_onboard.sh guides users through that process, checks configuration early, manages the temporary MITM proxy, and provides clear recovery instructions.

It builds on the existing mitm_redirect.py workflow. It does not install the server, provision robot Wi-Fi, or replace the project's robot onboarding procedure.

Guided onboarding workflow

Before the numbered steps, the wizard verifies the server connection and Protocol Sync Secret. Users can correct configuration problems before changing iPhone trust settings or requesting a short-lived verification code.

The wizard then guides users through these nine steps:

  1. Prepare the iPhone: Locate or generate the public mitmproxy CA certificate, transfer it to the iPhone, install the profile, and enable Full Trust while WireGuard remains off.
  2. Get the Roborock verification code: Request the code with WireGuard off, save it for manual entry, and leave the app at the code-entry screen without submitting it.
  3. Prepare MITM connection: Explain that the launcher will perform a fresh server check at startup.
  4. Start MITM server: Start the temporary proxy and open its authenticated Capture page.
  5. Connect WireGuard and submit login: Delete the previous Roborock MITM tunnel, scan the current session's QR code, enable the new tunnel, and manually enter the saved code.
  6. Verify robot through MITM: Confirm that your robot(s), status, and maps load.
  7. Test without the MITM tunnel: Force-quit the app, disable WireGuard, reopen the app, and confirm normal operation.
  8. Shut down MITM: Stop the wizard's temporary proxy and background helpers.
  9. Certificate cleanup: Disable temporary certificate trust and follow instructions to remove the current session's sensitive captures.

Phone settings, login, maps, and controls require user confirmation. Manual checkpoints have no startup timeout.

Terminal interface and usability

  • Boxed headings, nine-step progress indicators, and color-coded messages.
  • Confirmation prompts, clearer spacing, and corrected Unicode alignment.
  • Readable output without ANSI colors, including support for NO_COLOR.
  • Clear instructions for finding the Protocol Sync Secret and pasting it into a hidden prompt.
  • config, status, and stop commands for configuration and recovery.
  • Beginner-friendly explanations of server addresses, ports, and temporary proxy shutdown.

Server verification and address handling

  • Checks the configured HTTPS endpoint with a ten-second total request limit.
  • Requires HTTP 400 with structured JSON data.reason equal to missing_user_data; JSON spacing and key order do not matter.
  • Stops on connection, certificate, access, redirect, or unexpected-response failures.
  • Defaults host-only addresses to HTTPS port 555 and preserves explicit ports, including reverse-proxy port 443.
  • Normalizes pasted http:// and https:// prefixes while retaining HTTPS connections.
  • Preserves the launcher's independent preflight at MITM startup.

Credential handling and authenticated browser access

  • Treats saved configuration as literal data rather than executable shell code.
  • Writes configuration atomically with restricted permissions.
  • Rejects empty and whitespace-only secrets.
  • Transports secrets through environment variables or standard input rather than secret-bearing command arguments. Environment transport does not prevent privileged or same-user inspection.
  • Disables mitmweb's automatic browser opener and opens the authenticated Capture page only after validating the current session token against the live /flows endpoint.
  • Uses a 90-second authenticated-interface readiness window after a separate short supervisor-startup allowance.
  • Provides manual browser recovery instructions without falling back to an unauthenticated page.

Process management and cleanup

  • Verifies ownership before stopping the temporary proxy and its background helpers.
  • Requires an existing managed session to be stopped before starting fresh.
  • Leaves unrelated processes, other project folders, and unverified legacy sessions untouched.
  • Reports an occupied port 8081 without stopping its listener or overwriting the existing startup log.
  • Prevents concurrent wizard runs with a lock and attempts cleanup on cancellation or failure.
  • Bounds and supervises certificate generation without sudo or macOS Keychain changes.

Captures can contain complete request and response data, including login tokens, credentials, and rriot keys. The guide explicitly instructs users to delete only the identified session's captures after successful onboarding and remove the separate startup log when troubleshooting is finished. Capture deletion remains manual.

Documentation and maintainability

Extensive inline Bash comments explain configuration parsing, credential transport, verification, certificate generation, process ownership, browser authentication, cleanup, and the required login sequence.

The user guide has been rewritten to match the implementation and address maintainer feedback. Development notes, publishing instructions, obsolete behavior, and unsupported testing claims have been removed.

The guide is linked from the iPhone section and MkDocs navigation. Shared-file changes are minimal and preserve upstream's manual procedure, plugin-refresh documentation, and all existing navigation entries.

Runtime ignore rules cover saved configuration, session state, locks, certificate diagnostics, and startup logs. Traffic captures retain their existing ignore coverage.

Proof that it works

Tested by author on:

  • Vacuum model: Saros 10R
  • Roborock Firmware version: 02.50.56
  • Roborock Local Server version: 1.2.1
  • iOS version: 27.2.1
  • Roborock iOS app version: 4.70.02
  • Host tooling: macOS Bash 3.2.57; Python 3.12.11 for static checks.

What I did and what happened:

  • /bin/bash -n roborock_onboard.sh passed.
  • git diff --check upstream/main passed.
  • All 17 documented shell examples passed syntax checks without executing their commands.
  • Static checks passed for 18 relative links and anchors, 21 navigation targets, and the exact nine-step order.
  • Comparisons confirmed that the mobile-app page and MkDocs configuration preserve upstream content and ordering apart from the added wizard links.

The strict MkDocs build could not start because mkdocs was unavailable. Relevant launcher and onboarding-preflight tests could not start because pytest was unavailable.

The author previously reported 64 regression methods and disposable-process and HTTPS/curl smoke tests. The complete harness and execution results were unavailable during review, so these are not listed as independently verified passes. The earlier upstream 295-test result is not evidence for this revised helper.

Successful end-to-end onboarding of the final revision on a real iPhone and Roborock remains unverified.

Compatibility and remaining limitations

  • Targets macOS, including its built-in Bash 3.2.
  • Requires uv, uvx, curl, and macOS open.
  • Embedded helpers require Python 3.8 or newer; the project separately requires Python 3.11 through 3.13.
  • Changes no Python implementation, project dependencies, or lockfile.
  • Supports customized HTTPS ports, but does not expose separate robot-messaging ports or service addresses.
  • Interrupted atomic-write files matching .roborock_config.* and .roborock_pid.* still need ignore coverage.
  • Real-device validation and execution of the documentation build and regression tests remain outstanding.

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.
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.
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.
Enhances the Bash onboarding wizard with ANSI colors, Unicode
progress indicators, improved instructions, authenticated MITM
browser navigation, and extensive developer-facing comments.
@BlackRockCity

Copy link
Copy Markdown
Contributor Author

Substantial revision: V2
After some testing, I've substantially revised the onboarding helper since the original submission.
This update introduces an enhanced terminal wizard interface, improved authentication handling, clearer onboarding instructions, and extensive developer-facing comments throughout the Bash script to improve human readability and maintainability.
The underlying onboarding workflow remains unchanged.
This revision supersedes V1. Please review the latest commit.

Update `docs/ios_mitm_onboarding.md` for the V2 onboarding helper.

- Document the nine-step terminal wizard, ANSI colors, Unicode panels, and `NO_COLOR` support.
- Clarify saving the verification code for manual entry after enabling WireGuard.
- Require a fresh Roborock MITM WireGuard tunnel for each session.
- Explain authenticated mitmweb URLs and `web_open_browser=false`.
- Add troubleshooting for authentication errors, duplicate browser tabs, and startup failures.
- Preserve the existing installation, reverse-proxy, and security guidance.
- Compare implementation claims against the available script and retain conservative testing caveats.

Validation: `bash -n` passed for the available helper. Full end-to-end onboarding testing remains outstanding.
@Lash-L Lash-L self-assigned this Oct 22, 2026
@Lash-L Lash-L added area: official-app Official Roborock Android/iOS apps, login and plugins. feature PR adding capability; under this two-type scheme also covers additive documentation. labels Nov 15, 2026

@Lash-L Lash-L left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review: changes requested

Thanks for this. A guided wizard for the iOS MITM login is useful, and the script itself is careful about some things that matter: it uses no sudo, makes no keychain or trust changes on the Mac (it only reveals the existing ~/.mitmproxy/mitmproxy-ca-cert.cer in Finder), creates the config with umask 077 + chmod 600, creates the log with mode 0600, never echoes the secret, and only opens a mitmweb token URL after it checks that URL against the live /flows endpoint. --set web_open_browser=false does reach mitmweb, because mitm_redirect.py appends the unknown args it collects with parse_known_args() to the mitmweb command (mitm_redirect.py:693,763). The iPhone-side steps (AirDrop profile install, Full Trust, the code-entry screen not allowing paste, WireGuard tunnel reuse) could not be checked here. They are iOS behaviour, which isn't in the decompiled sources.

Blocking

  1. roborock_onboard.sh:514,579: the port is hardcoded to 443. The preflight goes to https://${ROBOROCK_DOMAIN}/... and the launcher is always given --local-api https://${ROBOROCK_DOMAIN}:443. The default stack serves HTTPS on :555 (mitm_redirect.py DEFAULT_LOCAL_API_PORT = 555, docs/roborock_app.md), so on a default install without a reverse proxy the wizard fails at Step 3 and can't be used. If someone types host:555, the result is https://host:555:443. Fix: accept host[:port], check it (for example ^[A-Za-z0-9.-]+(:[0-9]+)?$), and pass it to --local-api unchanged so mitm_redirect.py applies its own :555 default. Use the same authority for the curl preflight, or drop that preflight entirely: mitm_redirect.py already runs the same preflight and refuses to start if it fails (mitm_redirect.py:737-742).

  2. roborock_onboard.sh:692,713: "Confirm the Saros 10R appears" is the author's own model. Say "your robot(s)" instead.

  3. docs/ios_mitm_onboarding.md: several sections are notes to the author, not to users, and they contradict the PR:

    • "Developer notes and testing status" says the copy it reviewed "does not contain extensive commentary" and "Do not describe the final revision as independently end-to-end tested". Meanwhile the PR body says end-to-end testing is done.
    • The Quick start says to "Add .roborock_onboard.conf … to .gitignore before publishing the helper". This PR already does that.
    • The Files tree says "Community helper; add this file".
    • "Contributing upstream" asks whether "the maintainer would like this included".
    • "Requirements" says to rename mitm_redirect_fixed_v2.py.

    Please remove these, keep the user-facing content, use relative links instead of absolute GitHub URLs, and add the page to mkdocs.yml nav and link it from the iPhone section of docs/roborock_app.md. As it stands the page is orphaned and doesn't appear in the published docs.

Should fix

  1. roborock_onboard.sh:516,580: the sync secret goes on the command line twice, once as the curl -H "X-Local-Sync-Secret: …" argument and once as --sync-secret "$SYNC_SECRET". Any local user can read it with ps while the commands run, and the doc's own caveat already says so. Fix: MITM_LOCAL_SYNC_SECRET="$SYNC_SECRET" uv run "$MITM_SCRIPT" …, which the launcher already reads (mitm_redirect.py:721). If you keep the curl preflight, send the header through stdin (curl -H @- … <<<"X-Local-Sync-Secret: $SYNC_SECRET").
  2. roborock_onboard.sh:90-93,104: the config is written as KEY='$VALUE' and later loaded with source. If a value contains a ', the config breaks: the next run fails with a syntax error, or runs the rest of the line as shell code. Fix: write it with printf 'ROBOROCK_DOMAIN=%q\n' "$ROBOROCK_DOMAIN", or read it back with while IFS='=' read -r k v instead of source.
  3. roborock_onboard.sh:127: pgrep -f 'mitmweb.*mitm_redirect.py' | head -n 1 matches a mitm_redirect.py mitmweb started from any checkout, and only the first match. stop, Step 8 and the abort handler can therefore kill an unrelated MITM session. If the uv→python→uvx→mitmweb chain leaves more than one matching process, the others survive. The kill -9 fallback on the uv PID (lines 143, 224) also does not reach the mitmweb grandchild. Fix: match the absolute "$MITM_SCRIPT" path and loop over every match (pkill -TERM -f -- "-s $MITM_SCRIPT", then wait, then -KILL).
  4. roborock_onboard.sh:321: the fallback uv run mitmdump cannot work. mitmproxy is not a project dependency (pyproject.toml), so the command fails silently (its output goes to /dev/null) and the user only sees "mitmproxy did not create …". Use uvx --from mitmproxy mitmdump, the same way mitm_redirect.py does.
  5. Neither the docs nor Step 9 mention mitm_logs/<session>/. mitm_redirect.py _log_flow writes the full request and response headers and bodies there, including the Roborock cloud login response with the user's token and rriot keys. Tell users to delete that directory after onboarding, or offer to do it in Step 9.

Nits

  • roborock_onboard.sh:537: the preflight never sends user_data, so the server cannot return 2xx (server.py _handle_protocol_sync_route). A 2xx here would most likely come from a proxy or captive page. Treat it as a failure.
  • roborock_onboard.sh:765-767: "✓ WireGuard is OFF" and "✓ Full Trust is OFF" are printed as successes, but nothing checks them. Word them as reminders.
  • roborock_onboard.sh:170: on Ctrl+C, $? is the status of the last command, so an aborted run can exit 0.
  • roborock_onboard.sh:111: only https:// is stripped from the domain, not http://.

Checks: bash -n passes, the merge into main is clean, and the full test suite passes (uv run --extra dev pytest -q: 295 passed; the PR adds no tests). The helper itself was not run.

I've converted this PR to draft while these are addressed. Mark it ready for review again once they're fixed and it will go through another review.


This is an automated review by Claude Code, checked against the decompiled Roborock app (APK + device plugin bundles), python-roborock and a vacuum firmware dump. It can be incorrect, so please reply if any finding looks wrong.

@Lash-L Lash-L added the failing auto review Automated review requested changes before merge label Nov 25, 2026
@Lash-L
Lash-L marked this pull request as draft November 25, 2026 01:38
Improve server verification, credential handling, authenticated MITM startup, process ownership, session management, and recovery behavior.

Complete user-facing documentation, MkDocs integration, and runtime file exclusions.
@BlackRockCity

BlackRockCity commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Substantial revision V3 addressing maintainer feedback

I've substantially revised the macOS iOS onboarding wizard in commit 3cc654d to address the review findings.

The revision includes:

  • Hidden credential entry and literal configuration data written atomically with restricted permissions.
  • Server connectivity and Protocol Sync Secret validation before any iPhone trust changes or verification-code requests.
  • Support for hostnames, IP addresses, and explicit HTTPS ports.
  • Authenticated mitmweb readiness checks and browser navigation.
  • Verified process ownership, safer shutdown, concurrent-run protection, and recovery instructions.
  • Explicit instructions for manually removing sensitive session captures and startup logs.
  • Expanded runtime-file exclusions in .gitignore.
  • Extensive inline comments explaining implementation decisions and security-sensitive operations.

The user guide now matches the implementation and addresses the requested documentation corrections, including relative links, MkDocs navigation, and a link from the existing iPhone instructions. The wording also explains connection settings and temporary proxy shutdown more clearly for beginners.

The branch has been synchronized with upstream. Existing upstream content, including plugin-refresh documentation, the manual onboarding alternative, and all navigation entries, has been preserved.

Testing claims now reflect the available evidence: Bash syntax and static documentation checks passed. The author tested this script on his setup.

Thank you for the detailed review and feedback.

@BlackRockCity
BlackRockCity marked this pull request as ready for review November 25, 2026 06:33

@Lash-L Lash-L left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review: passed (nits)

Now that this has passed the automated review, I'll do a human review and then either request changes or merge it.

Thanks for the V3 rework. The process supervisor, the literal config format and the preflight that matches the launcher are a solid improvement.

Earlier items

  1. Hardcoded :443: fixed. normalize_endpoint accepts host[:port] and --local-api "$ROBOROCK_DOMAIN" is passed unchanged, so mitm_redirect.py applies its own :555 default (mitm_redirect.py:694-701). The curl preflight drops an explicit :443 the same way the launcher's local_api_http does.
  2. "Saros 10R": fixed. It now says "your robot(s)".
  3. Notes to the author in the docs: fixed. The developer-notes, contributing and _fixed_v2 text is gone, links are relative, the page is in the mkdocs.yml nav and roborock_app.md links to it.
  4. Secret in argv: fixed. It goes in through MITM_LOCAL_SYNC_SECRET (mitm_redirect.py:721), and the curl header is read from stdin.
  5. Sourced config: fixed. A v2 literal key=value file is written atomically and never sourced.
  6. pgrep matching: fixed. Shutdown now only signals a process group whose supervisor is checked by start time and argv. Scan matches are only reported, never killed.
  7. uv run mitmdump: fixed. It now uses uvx --from mitmproxy mitmdump.
  8. mitm_logs/<session>/: fixed. capture_cleanup_guidance finds the session from the [LOG] Rewritten line (mitm_redirect.py:216) and the docs warn about it.
  9. Nits: all fixed. A 2xx is rejected (it needs 400 + missing_user_data, which matches server.py:937). The phone-state messages are now reminders. Signals exit 130/143/129. http:// is stripped.

New nits (non-blocking)

  • roborock_onboard.sh:341-342: command -v python3 always finds /usr/bin/python3 on macOS, including the Command Line Tools stub on Macs without CLT. The uv python find fallback then never runs, and check_requirements reports "Python 3.8 or newer is required" even though uv is installed. Fix: check that the candidate actually runs ("$candidate" -c 'import sys') before you accept it, otherwise fall back to uv python find.
  • roborock_onboard.sh:234: a malformed v2 line returns 1 without a message, so start exits silently. Print the same "Run '$0 config'" hint as the other branches.
  • roborock_onboard.sh:304-310: the secret prompt only gives the Home Assistant path. Docker users need "admin page → Protocol Auth" (docs/home_assistant.md:61). The rest of the repo also says "add-on", not "Apps".
  • roborock_onboard.sh:1507: stop_mitm prints its own "STOP MITM SERVER" box straight after the Step 8 header. Pass a flag to skip it.
  • roborock_onboard.sh:1262: the mitmweb token ends up in open's argv. This is minor and probably unavoidable, but the comments promise "out of process arguments", so a short note would help.

Unverifiable

The iPhone side can't be checked from the app sources: AirDrop install of the .cer, the profile under VPN & Device Management, Full Trust, the app not allowing a pasted code, and a code requested with WireGuard off still working when submitted through the tunnel. The manual iPhone procedure uses mitm.it instead of AirDrop. Both should work, but only the author's testing backs this route.

Checks

shellcheck (shellcheck-py, -S style) is clean and bash -n passes. The merge into main is clean and the full test suite passes (uv run --extra dev pytest -q: 785 passed; the PR adds no tests). The wizard itself was not run.


This is an automated review by Claude Code, checked against the decompiled Roborock app (APK + device plugin bundles), python-roborock and a vacuum firmware dump. It can be incorrect, so please reply if any finding looks wrong.

@Lash-L Lash-L added passed auto review Automated review found no blocking issues and removed failing auto review Automated review requested changes before merge labels Nov 25, 2026
@Lash-L

Lash-L commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Thank you! I tried it out tonight and i like it!

Screenshot for context for anyone else who comes across this PR

image

@Lash-L
Lash-L merged commit 249315f into Python-roborock:main Nov 29, 2026
3 checks passed
@BlackRockCity
BlackRockCity deleted the ios-mitm-onboarding-helper branch November 30, 2026 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: official-app Official Roborock Android/iOS apps, login and plugins. feature PR adding capability; under this two-type scheme also covers additive documentation. passed auto review Automated review found no blocking issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants