From 4216b9a9278815a9f19f9496827578303af5a3be Mon Sep 17 00:00:00 2001 From: Andrea Collet Date: Tue, 24 Nov 2026 11:39:48 +0100 Subject: [PATCH 1/2] docs: fill functional and technical documentation scaffolding Replaces TODO placeholders in intent.md, README.md, CONTRIBUTING.md, SECURITY.md and docs/{architecture,deployment,testing,security/threat-model}.md with real content matching the current single-maintainer, read-only, bring-your-own-session CLI. Scopes intent.md to manual (not automated) profile read/edit and future swipe actions. Co-Authored-By: Claude Sonnet 5 --- .env.example | 14 +++++++++++ CONTRIBUTING.md | 10 +++++--- README.md | 19 ++++++++++---- SECURITY.md | 5 ++-- docs/architecture.md | 47 ++++++++++++++++++++++++++++++++--- docs/deployment.md | 25 ++++++++++++++++--- docs/security/threat-model.md | 7 +++++- docs/testing.md | 21 +++++++++++----- intent.md | 33 ++++++++++++++++++++---- 9 files changed, 151 insertions(+), 30 deletions(-) diff --git a/.env.example b/.env.example index b55ac6c..a303305 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,16 @@ # Copy to .env (git-ignored). Names and safe placeholders only: never real credentials, # tokens or production endpoints. + +# Where the saved session lives. Default: OS config dir (~/.config/hinge-cli/session.json +# or %APPDATA%\hinge-cli\session.json). Leave unset unless you need a non-default path. +HINGE_SESSION_FILE= + +# Password-manager reference in place of a session file, e.g. op://Private/hinge/session +# or bw://hinge-session. When set, nothing is written to disk. See docs/auth.md. +HINGE_SESSION_REF= + +# Only needed for `hinge inspect` (Appium/WebDriverAgent exploration), not for tier/limits/auth. +HINGE_APPIUM_URL=http://127.0.0.1:4723 +HINGE_UDID= +HINGE_BUNDLE_ID=co.hinge.mobile.ios +HINGE_TEAM_ID= diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 00d376a..f30c363 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,8 +19,12 @@ Enable the template once: `git config commit.template .gitmessage.txt`. - Dependency changes reviewed explicitly (new packages, version bumps, lockfile diff). ## Review roles -- Reviewer: TODO (who reviews, and who may approve changes to sensitive paths — see CODEOWNERS where supported). -- Single-maintainer repository: document how self-review is done (checklist in the PR template, cooling-off before merge). +- Reviewer: @ifthenelse approves all changes; CODEOWNERS requires their review on every path, and on + `.github/` and `docs/security/` specifically. +- Single-maintainer repository: self-review follows the PR requirements above (verify green, tests + updated, docs/ADR updated) plus a 24h cooling-off before merging anything touching `src/secrets.ts`, + `src/session-store.ts`, `src/api.ts`, or `.github/workflows/`. ## Escalation -TODO: whom to contact for blocked reviews, security concerns or production incidents. +Security concerns: see [SECURITY.md](SECURITY.md). Blocked reviews or anything else: open a GitHub +issue — there is no other channel for this single-maintainer project. diff --git a/README.md b/README.md index 7a41b5a..657c8a5 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,21 @@ # hinge-cli -> TODO: one paragraph — what this is and who it is for. Business intent lives in [intent.md](intent.md). +An unofficial, read-only command-line client for your own Hinge account. It talks directly to +Hinge's real HTTP API (reverse-engineered, not UI automation) using a session you capture from your +own phone, and reports things the app shows but doesn't let you script: your subscription tier, +like/rose limits. For members who want to check or audit their own account from a terminal or a +script, on Windows, macOS or Linux. Business intent lives in [intent.md](intent.md). | | | | --- | --- | | Owner | Andrea Collet | -| Support | TODO: team channel / contact | +| Support | GitHub issues on this repository (single-maintainer project — see CONTRIBUTING.md) | ## Architecture -TODO: short summary. Details: [docs/architecture.md](docs/architecture.md); decisions: [docs/adr/](docs/adr/). +A single local binary (`hinge`) calls `prod-api.hingeaws.net` directly with a member-supplied +session; there is no server component. Full summary: [docs/architecture.md](docs/architecture.md); +decisions: [docs/adr/](docs/adr/). ## Prerequisites @@ -23,13 +29,16 @@ TODO: short summary. Details: [docs/architecture.md](docs/architecture.md); deci ## Commands - Verify everything: `scripts/verify` +- Build: `npm run build` · Import a captured session: `hinge auth import ` · Check it: + `hinge auth status` · Read your account: `hinge tier`, `hinge limits`. Capturing a session in the + first place is a manual, documented process: [docs/auth.md](docs/auth.md). ## Environment model | Environment | Purpose | Notes | | --- | --- | --- | -| local | development | configured through `.env` (see `.env.example`) | -| TODO | TODO | TODO | +| local | development, and the only environment this tool runs in | configured through `.env` (see `.env.example`); no `.env` is required to build/test, only to import/use a real session | +| npm registry | distribution | versioned release, see docs/deployment.md — no staging/production split, this is a local CLI | ## Deployment and recovery diff --git a/SECURITY.md b/SECURITY.md index c17ac8e..e98c291 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -7,8 +7,9 @@ | older | no | ## Reporting a vulnerability -TODO: reporting route (private advisory or security mailbox). Do not open public issues for vulnerabilities. -We aim to acknowledge reports within TODO business days. +Use GitHub's private vulnerability reporting for this repository (Security tab → "Report a +vulnerability"). Do not open public issues for vulnerabilities. We aim to acknowledge reports within +5 business days. ## Secure development expectations - No credentials, tokens or confidential incident data in the repository, issues or this file. diff --git a/docs/architecture.md b/docs/architecture.md index 937f12f..75f604a 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -3,13 +3,52 @@ One canonical location for the current architecture. Link to authoritative diagrams rather than copying them. ## System context -TODO: what the system does, its users and neighbouring systems. +hinge-cli is a single Node.js/TypeScript binary (`hinge`) that a Hinge member runs locally. It makes +direct HTTPS calls to Hinge's own backend (`prod-api.hingeaws.net`) using session headers the member +captured from their own phone — it does not drive the Hinge app's UI and does not go through Appium +at runtime. Appium/WebDriverAgent is a one-time exploration tool (`hinge inspect`), not part of the +request path. There is no server component and no multi-user backend: each install talks only to +Hinge's API and to the member's own secret store. + +``` +member's terminal ── hinge ──▶ src/cli.ts + │ + ┌─────────────┼─────────────┐ + ▼ ▼ ▼ + session-store.ts api.ts session.ts (Appium, `inspect` only) + │ │ + ▼ ▼ + secrets.ts prod-api.hingeaws.net (Hinge's real API) + (op:// bw:// keychain:// cmd:// env://) +``` ## Components and boundaries -TODO: components, responsibilities, ownership. +- **`src/cli.ts`** — commander-based entrypoint; owns argument parsing, the `--json` flag, and the + top-level error-to-exit-code mapping. No business logic lives here beyond wiring. +- **`src/api.ts`** — the only module that talks to Hinge. `call()` issues authenticated GETs and + normalizes 401/403/non-2xx into plain errors that never echo the token. `describeTier()` maps the + real `/store/v2/account` response shape into `TierInfo`. +- **`src/session-store.ts`** — owns where a session lives (file or password-manager reference), + validates untrusted JSON on import (`parseSession`, header allowlist, `authorization` required), + and the cross-platform config-path logic. +- **`src/secrets.ts`** — resolves `scheme://` references (`env://`, `op://`, `bw://`, `keychain://`, + `cmd://`) to a secret value. The only module allowed to shell out for credentials. +- **`src/session.ts`** — Appium/WebDriverAgent connection used solely by `hinge inspect`, the + exploration command used while reverse-engineering the API. Not used by `tier`/`limits`/`auth`. ## Data flows and integration contracts -TODO: main flows; contracts live in `docs/api/` and `docs/data-contracts/`. +1. **Capture (manual, one-time, outside the CLI):** member runs mitmproxy against their own phone + with `tools/hinge_token.py` to extract session headers, per `docs/auth.md`. +2. **Import:** `hinge auth import ` → `session-store.parseSession` (validates/allowlists + headers) → `saveSession` (0600 file, or writes nothing if `HINGE_SESSION_REF` is set) → source + file deleted by default. +3. **Authenticated call:** `hinge tier`/`limits` → `loadSession()` (file or `resolveSecret` via + `HINGE_SESSION_REF`) → `api.call(path, session)` → Hinge REST API → response mapped and printed. + +Endpoint inventory, headers observed, and the (unimplemented) login/attestation sequence: +[`docs/api-inventory.md`](api-inventory.md). ## Trust boundaries -TODO: see [threat model](security/threat-model.md). +The member's captured session header is the only secret in the system; everything downstream of +`loadSession()` treats it as sensitive and no code path logs or echoes it (see `secret` command, +which reports length only). See the [threat model](security/threat-model.md). diff --git a/docs/deployment.md b/docs/deployment.md index 4e96866..9bd891c 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -1,15 +1,32 @@ # Deployment +hinge-cli has no server and no hosted environment — "deployment" means publishing a versioned npm +package that members install locally. There is no staging/production split for a local CLI. + ## Environments and promotion path | Environment | Purpose | Promotion from | Approval | | --- | --- | --- | --- | -| TODO | TODO | TODO | TODO | +| local (dev) | member's own machine, running against the real Hinge API with their own session | n/a | n/a | +| npm registry | distributable, versioned release | `main` branch, tagged | maintainer (self-review; single-maintainer repo, see CONTRIBUTING.md) | ## Release -TODO: release command(s); the version comes from its single source (see AGENTS.md). +1. `npm version ` on `main` (bumps `package.json`, the single version source). +2. `npm run build` (`tsc -p tsconfig.build.json`) to produce `dist/`. +3. `scripts/verify` must be green. +4. `git push --follow-tags`, then `npm publish` (not yet automated — no publish job exists in + `.github/workflows/`; this is a manual step today, tracked as an open item below). ## Smoke tests -TODO +After install (`npm install -g hinge-cli` or `npm link`): +- `hinge doctor` — checks Appium reachability (only relevant if `inspect` will be used). +- `hinge auth status` — confirms a session, once imported, is accepted by Hinge's API. +- `hinge tier` — confirms a real authenticated call round-trips correctly. ## Rollback -Conditions: TODO. Steps: TODO. +There is nothing running to roll back (no server). If a published npm version is broken: +- `npm deprecate hinge-cli@ ""` to warn installers off it. +- Publish a patched version; members on the broken version re-run `npm install`. + +## Open item +No CI job publishes to npm yet, and CI/tests currently run on `ubuntu-latest` only even though the +tool targets Windows/macOS/Linux — a Windows/macOS matrix job is not yet in `.github/workflows/ci.yml`. diff --git a/docs/security/threat-model.md b/docs/security/threat-model.md index 2aa52d1..bab680e 100644 --- a/docs/security/threat-model.md +++ b/docs/security/threat-model.md @@ -4,4 +4,9 @@ Update when architecture or exposure changes. | Asset | Actor | Entry point | Trust boundary | Abuse case | Mitigation | Residual risk | | --- | --- | --- | --- | --- | --- | --- | -| TODO | TODO | TODO | TODO | TODO | TODO | TODO | +| Hinge session header (bearer-equivalent) | Malware/other local process on the member's machine | Session file on disk / env var / password-manager process | OS file permissions and OS process boundary | Local process reads the session file and impersonates the member to Hinge | File written mode 0600, directory 0700 (`session-store.ts`); `HINGE_SESSION_REF` keeps the secret out of the filesystem entirely, resolved on demand via the member's password manager | Mode bits are a no-op on Windows (relies on per-user `%APPDATA%` ACL instead) — documented, not yet hardened to the OS credential store | +| Hinge session header | Shoulder-surfing / shell history / CI logs | `hinge secret `, error messages | CLI output boundary | Secret value printed to stdout/stderr or committed to logs | `secret` command reports length only, never the value; `api.ts` error paths are built to never interpolate the header | None known; relies on no future code path echoing the header — worth a lint rule if the codebase grows | +| Captured session file | The member, during capture | `tools/hinge_token.py` output file | Local filesystem | File left on disk after import, later committed or backed up | `hinge auth import` deletes the source file by default (`--keep` opts out); documented cleanup steps in `docs/auth.md` | Depends on the member actually using `auth import` rather than hand-copying the header elsewhere | +| Other Hinge members' data | The CLI author, during API reverse-engineering | mitmproxy capture of the member's own app traffic | Hinge's platform boundary | Capture incidentally includes another member's profile/message content relayed through the member's own session | Captures were deleted after use; `docs/api-inventory.md` records only endpoints/headers/ordering, no bodies, tokens or third-party content | None for past captures (deleted); future captures must follow the same discipline — not yet enforced by tooling, only by process | +| Hinge's production API | This project's own CI | GitHub Actions runners | Network boundary to a third party | An automated "pentest" workflow sends attack traffic to Hinge's live infrastructure | No such job exists; `security.yml` explicitly scopes to static/dependency scanning instead (see comment at the top of that file) | None — this is a closed decision, not a residual risk | +| npm dependencies | Supply chain | `package.json` / lockfile | Build boundary | A compromised or vulnerable transitive dependency ships in a release | Dependabot (npm + actions, weekly), `npm audit --audit-level=high` in CI, CodeQL static analysis | Standard supply-chain residual risk; mitigated, not eliminated | diff --git a/docs/testing.md b/docs/testing.md index becd6f4..48bd966 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -1,17 +1,26 @@ # Testing ## Strategy -TODO: what is covered by which kind of test. +Unit tests cover the modules that don't need a live Hinge session or a real phone: secret resolution, +session parsing/storage, and the API client's response mapping (success, 401, 500, free-tier fallback) +against fake `fetch` implementations. Nothing in CI calls Hinge's real API or Appium — those require +live, member-specific state (a captured session, a connected iPhone) that isn't safe or reproducible +in CI. ## Suites | Suite | Location | Speed | Run with | | --- | --- | --- | --- | -| unit | `tests/unit/` | fast | `scripts/verify` | -| integration | TODO | TODO | TODO | -| e2e | TODO | slow, opt-in | TODO | +| unit | `test/*.test.ts` | fast (<1s) | `npm test` / `scripts/verify` | +| integration (live Hinge API) | none yet | — | manual: `hinge tier` against a real imported session | +| e2e (Appium/`hinge inspect`) | none | slow, opt-in | manual, requires a connected iPhone + WebDriverAgent | ## Fixtures and environments -Fixtures are kept apart from production data. Tests that touch live or state-changing systems are opt-in and isolated. +Unit tests use literal fixture objects (fake sessions, fake `Account` JSON shapes) inline in +`test/core.test.ts` — no fixtures touch a real captured session file. Tests that would touch a live +or state-changing system (a real Hinge session, a real phone) are intentionally not automated; they +are manual smoke checks (see `docs/deployment.md`). ## Definition of a passing release -`scripts/verify` green in CI, plus: TODO. +`scripts/verify` green in CI (typecheck + `node --test`), plus: a manual `hinge auth status` / +`hinge tier` check against one real account before publishing, since no automated test exercises +the real API contract. diff --git a/intent.md b/intent.md index c1d76ab..9a2c786 100644 --- a/intent.md +++ b/intent.md @@ -3,18 +3,41 @@ Durable statement of intent. It is not a requirements backlog. ## Business problem -TODO: the problem and who has it. +Hinge has no official API client and no data-export tooling for a member's own account: checking +subscription tier, remaining likes, or automating anything beyond what the mobile app's UI exposes +requires manually tapping through the app. There is no way to script, audit, or integrate a member's +own Hinge usage from a terminal or CI job. ## Intended outcomes -- TODO +- A member can read, edit and check their own profile and account (subscription tier, like/rose + limits) from the command line, on Windows, macOS or Linux, without opening the mobile app. +- Session credentials are supplied by the member (captured from their own device) and stored through + a password manager or a local file with restrictive permissions — never hardcoded, never shared + across users. +- The reverse-engineered API surface is documented (`docs/api-inventory.md`) so the client's behaviour + is auditable rather than opaque. +- **Future (not yet built):** browse Discover/Standout candidates from the terminal — rendering their + photos inline (Kitty/iTerm2/Sixel graphics protocol where supported, ASCII art otherwise) — and let + the member manually like or pass. This is a manual, one-decision-at-a-time interface change (a + different client for the same human decision the app already asks for), not automation of the + decision itself. ## Non-goals -- TODO +- No AI- or script-driven decision-making on who to like/pass/message — every like/pass/message + action is a single explicit command run by the member for one candidate; there is no "auto-swipe" + or "auto-match" mode, and none is planned. +- No automated/bulk messaging, mass-liking, or any action that mimics bot-like use of the platform. +- No multi-account or on-behalf-of-other-users operation — this is a single-member, bring-your-own-session tool. +- No reimplementation of Hinge's phone+SMS login flow in this version — it requires passing Apple + App Attest, which a plain CLI cannot satisfy (see `docs/api-inventory.md`, "Open risk for `hinge auth login`"). +- No live testing (security or otherwise) against Hinge's production infrastructure from this repo's CI. ## Success measures | Measure | Target | Source | | --- | --- | --- | -| TODO | TODO | TODO | +| `hinge tier` / `hinge limits` return correct, current account data | Matches what the app shows | Manual comparison against the Hinge app | +| Session import works without a captured credential ever being committed or logged | 0 leaked secrets | `gitleaks` in CI, manual review | +| CLI runs unmodified on Windows, macOS, Linux | `scripts/verify` green on all three | CI matrix (currently ubuntu-only — see open item in `docs/testing.md`) | ## Accountable owners -- Andrea Collet — TODO: role +- Andrea Collet — sole maintainer; owns design, security review, and release decisions. From d85704281fee1dab4ea9204e05d8ec2cc19b4b53 Mon Sep 17 00:00:00 2001 From: Andrea Collet Date: Sat, 28 Nov 2026 03:18:03 +0100 Subject: [PATCH 2/2] feat: guided `hinge auth capture` for non-technical members Co-Authored-By: Claude Sonnet 5 --- CHANGELOG.md | 7 ++++ Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 2 +- docs/auth.md | 13 ++++-- src/capture.rs | 110 +++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 13 ++++++ 7 files changed, 142 insertions(+), 7 deletions(-) create mode 100644 src/capture.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index ac34449..66d828f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ rather than editing several version sources by hand. Format: [Keep a Changelog]( ## [Unreleased] +## [0.2.1] - 2026-11-28 +### Added +- `hinge auth capture`: runs the session-capture steps for you (starts the local proxy, prints what + to do on the phone, waits, imports, cleans up) instead of requiring mitmproxy to be run by hand. + `hinge auth import ` is unchanged and still works for anyone who prefers the manual steps or + needs to script the capture themselves. + ## [0.2.0] - 2026-11-28 ### Changed - **Rewritten in Rust** (edition 2024; clap, tokio, reqwest with rustls, serde). All commands and diff --git a/Cargo.lock b/Cargo.lock index 7c3c17c..053c768 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -360,7 +360,7 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hinge-cli" -version = "0.2.0" +version = "0.2.1" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index 570856a..102fe6e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hinge-cli" -version = "0.2.0" +version = "0.2.1" edition = "2024" description = "Command-line client for your own Hinge account, built on its reverse-engineered HTTP API." license = "MIT" diff --git a/README.md b/README.md index ca512fb..3f096b8 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ Then capture a session from your own device ([docs/auth.md](docs/auth.md)), impo your account: ```sh -hinge auth import +hinge auth capture # walks you through it on your phone, no separate tools to run by hand hinge auth status hinge tier hinge limits diff --git a/docs/auth.md b/docs/auth.md index 23732ec..cff19e2 100644 --- a/docs/auth.md +++ b/docs/auth.md @@ -1,9 +1,17 @@ # Authentication -hinge-cli has no official login. It reuses the session your own Hinge app already has, captured once from your own phone. +hinge-cli has no official login: Hinge's own sign-in requires a device-bound check this CLI can't produce +(the server expects a hardware-backed attestation tied to the real app, not just a phone number and a code). +So it reuses the session your own Hinge app already has, captured once from your own phone. Hinge's terms may forbid this; automation can get an account flagged. Use your own account only. ## Capture (once, per device) +Run `hinge auth capture`. It starts the local capture step for you and prints exactly what to do on +your phone, in order; it waits up to 5 minutes, then saves the session and cleans up by itself. It +needs [mitmproxy](https://mitmproxy.org) installed (the command tells you if it isn't). + +**Manual steps (what `auth capture` does for you, if you'd rather run it by hand, or need to automate +a non-interactive capture):** 1. Install [mitmproxy](https://mitmproxy.org) and run `HINGE_OUT=hinge-session.json mitmdump -s tools/hinge_token.py`. 2. On the phone: set the Wi-Fi proxy to this computer (port 8080), open `http://mitm.it`, install the profile and enable full trust under Settings → General → About → Certificate Trust Settings. Turn any VPN off. 3. Force-quit and reopen Hinge. When `hinge-session.json` appears, stop mitmproxy. @@ -15,9 +23,6 @@ Hinge's terms may forbid this; automation can get an account flagged. Use your o - Password manager: set `HINGE_SESSION_REF` to an `op://`, `bw://`, `keychain://` or `cmd://` reference holding the same JSON. Nothing is written to disk. - `hinge auth logout` deletes the saved session. Tokens expire; repeat the capture when `hinge auth status` fails. -## Not done yet -Phone-number + SMS login inside the CLI (needs the login traffic captured). - ## Note: user agent `hinge auth import` keeps only an allow-list of headers and no longer stores `user-agent`: every request the CLI sends identifies as a generic Android phone instead (`src/api.rs`). Sessions imported by an diff --git a/src/capture.rs b/src/capture.rs new file mode 100644 index 0000000..ec50edb --- /dev/null +++ b/src/capture.rs @@ -0,0 +1,110 @@ +//! Guided session capture: wraps the manual mitmproxy steps in `docs/auth.md` into one command, so a +//! member without a technical background can run `hinge auth capture` instead of mitmproxy by hand. +use crate::session_store::{Session, parse_session, real_env, save_session, session_path}; +use anyhow::{Context, Result, bail}; +use std::io::Write; +use std::net::IpAddr; +use std::path::PathBuf; +use std::process::{Child, Command, Stdio}; +use std::time::{Duration, Instant}; + +const SCRIPT: &str = include_str!("../tools/hinge_token.py"); +const PROXY_PORT: u16 = 8080; +const TIMEOUT: Duration = Duration::from_secs(300); + +fn local_ip() -> Option { + // shortcut: UDP "connect" picks the outbound interface without sending a packet; good enough to + // print a LAN address for the phone to type in, falls back to "your computer's IP" if it fails. + let sock = std::net::UdpSocket::bind("0.0.0.0:0").ok()?; + sock.connect("8.8.8.8:80").ok()?; + sock.local_addr().ok().map(|a| a.ip()) +} + +struct Proxy(Child); +impl Drop for Proxy { + fn drop(&mut self) { + self.0.kill().ok(); + self.0.wait().ok(); + } +} + +pub fn capture(print: &dyn Fn(&str)) -> Result<(Session, PathBuf)> { + if Command::new("mitmdump") + .arg("--version") + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .status() + .is_err() + { + bail!( + "mitmproxy is not installed. Install it from https://mitmproxy.org, then run `hinge auth capture` again." + ); + } + + let script = std::env::temp_dir().join(format!("hinge_token_{}.py", std::process::id())); + std::fs::write(&script, SCRIPT)?; + let out = std::env::temp_dir().join(format!("hinge_session_{}.json", std::process::id())); + std::fs::remove_file(&out).ok(); + + let child = Command::new("mitmdump") + .args([ + "-s", + script.to_str().unwrap(), + "-p", + &PROXY_PORT.to_string(), + "-q", + ]) + .env("HINGE_OUT", &out) + .stdout(Stdio::null()) + .stderr(Stdio::piped()) + .spawn() + .context("could not start mitmdump")?; + let _proxy = Proxy(child); // killed on every return path, including early bail!s below + + let ip = local_ip().map_or_else( + || "".to_string(), + |ip| ip.to_string(), + ); + print(&format!( + "Capturing your Hinge session. On your phone, with the SAME Wi-Fi network as this computer and any VPN off:\n\ + \n\ + 1. Set the Wi-Fi proxy to {ip} : {PROXY_PORT}\n\ + 2. Open http://mitm.it in a browser on the phone, install the certificate, then enable full trust for it\n\ + (iPhone: Settings > General > About > Certificate Trust Settings)\n\ + 3. Force-quit the Hinge app and reopen it\n\ + \n\ + Waiting up to 5 minutes for your session... (Ctrl+C to cancel)" + )); + + let start = Instant::now(); + while !out.exists() { + if start.elapsed() > TIMEOUT { + bail!( + "No session was captured within 5 minutes. Check the phone's proxy and certificate trust, then try again." + ); + } + std::thread::sleep(Duration::from_millis(500)); + } + std::thread::sleep(Duration::from_millis(300)); // the file is written, then closed; avoid a half-written read + let text = std::fs::read_to_string(&out)?; + std::fs::remove_file(&out).ok(); + std::fs::remove_file(&script).ok(); + + print( + "Got it. Turn the phone's Wi-Fi proxy back off and remove the mitmproxy certificate when you're done.", + ); + Ok(( + parse_session(&text)?, + session_path(&real_env, std::env::consts::OS), + )) +} + +pub fn run() -> Result { + let stdout_print = |s: &str| { + println!("{s}"); + std::io::stdout().flush().ok(); + }; + let (session, path) = capture(&stdout_print)?; + save_session(&session, &path)?; + Ok(path) +} diff --git a/src/main.rs b/src/main.rs index f7e2086..a661349 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ mod api; mod appium; +mod capture; mod secrets; mod session_store; @@ -58,6 +59,8 @@ enum AuthCmd { #[arg(long)] keep: bool, }, + /// walk you through capturing a session from your own phone (no separate tools to run by hand) + Capture, /// check that the saved session works Status, /// delete the saved session @@ -167,6 +170,16 @@ async fn run(cli: Cli) -> Result<()> { .await?; out(j, &json!({ "ok": true }), "session OK".into()) } + Cmd::Auth { + cmd: AuthCmd::Capture, + } => { + let path = capture::run()?; + out( + j, + &json!({ "ok": true }), + format!("session saved to {}", path.display()), + ) + } Cmd::Auth { cmd: AuthCmd::Logout, } => {