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, } => {