Skip to content

Commit d1a5789

Browse files
therealalephclaude
andauthored
v1.0.2: stable release signature, idempotent Stop, top-level Settings for CA install (#33)
Three fixes + one behaviour change from v1.0.1 reports. APK signature is now stable (release.jks committed) ---------------------------------------------------- v1.0.0 and v1.0.1 signed release APKs with Gradle's auto-generated debug keystore, which is randomly generated per machine and per CI runner. Result: every upgrade failed with INSTALL_FAILED_UPDATE_INCOMPATIBLE and users had to uninstall first. Unfixable without a stable key. android/app/release.jks now holds that key, committed to the repo with the password in plaintext in build.gradle.kts. This is fine for a FOSS sideload project without a Play Store identity — the trust model is "trust the source tree you pulled from," not "trust the key we hold." Anyone forking and shipping a rebranded build should generate their own key. One-time cost: v1.0.1 → v1.0.2 STILL requires uninstall, because we're switching signature keys. Every upgrade from v1.0.2 onward is clean. Stop no longer (sometimes) closes the app ----------------------------------------- teardown() is reachable from three paths on two threads: 1. ACTION_STOP onStartCommand branch (mhrv-teardown worker) 2. onDestroy after stopSelf (main thread) 3. VpnService revocation out-of-band (main thread) Running the full native cleanup sequence twice races the two threads through Tun2proxy.stop() → fd.close() → Native.stopProxy(handle) on state that's already been nullified — SIGSEGV source, user-visible as "tap Stop, app disappears." New AtomicBoolean `tornDown` gates entry: first caller wins, every subsequent caller logs "teardown: already done" and returns. onDestroy also wraps the call in try/catch — crashing out of onDestroy takes the whole process with it, which is exactly the bug we're trying to fix. Smoke-tested on emulator: teardown now logs teardown: begin caller=mhrv-teardown ... clean sequence ... teardown: done onDestroy entered teardown: already done, skipping (caller=main) onDestroy done with PID unchanged throughout. CA install now routes to the Settings search -------------------------------------------- Old flow: `Settings.ACTION_SECURITY_SETTINGS` deep-link, then walk "Encryption & credentials → Install a certificate → CA certificate". That path varies wildly between OEMs (Samsung buries it under "Biometrics and security → Other security settings"; Xiaomi under "Passwords & Security → Privacy"; Pixel splits it between "More security settings" and "Privacy controls" depending on Android version). Users got lost. New flow: open the top-level Settings app (`Settings.ACTION_SETTINGS`) and instruct the user to use the Settings search bar to find "CA certificate". Search is consistent across OEMs and Android versions; the menu paths are not. Dialog, snackbar, and `docs/android.md` copy all updated to match. Version bump: 1.0.1 → 1.0.2 (versionCode 101 → 102). releases/mhrv-rs-android-universal-v1.0.1.apk replaced with the v1.0.2 build. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 8910dec commit d1a5789

10 files changed

Lines changed: 114 additions & 51 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mhrv-rs"
3-
version = "1.0.1"
3+
version = "1.0.2"
44
edition = "2021"
55
description = "Rust port of MasterHttpRelayVPN -- DPI bypass via Google Apps Script relay with domain fronting"
66
license = "MIT"

android/app/build.gradle.kts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ android {
1414
applicationId = "com.therealaleph.mhrv"
1515
minSdk = 24 // Android 7.0 — covers 99%+ of live devices.
1616
targetSdk = 34
17-
versionCode = 101
18-
versionName = "1.0.1"
17+
versionCode = 102
18+
versionName = "1.0.2"
1919

2020
// Ship all four mainstream Android ABIs:
2121
// - arm64-v8a — 95%+ of real-world Android phones since 2019
@@ -30,22 +30,39 @@ android {
3030
}
3131
}
3232

33+
signingConfigs {
34+
create("release") {
35+
// Committed keystore — fixed signature across machines and
36+
// across CI runs. Using the auto-generated debug keystore
37+
// (as v1.0.0 / v1.0.1 did) makes every release APK fail to
38+
// install over the previous one with
39+
// INSTALL_FAILED_UPDATE_INCOMPATIBLE, because Android treats
40+
// a signature change as "different app": the user has to
41+
// uninstall first. That's awful UX.
42+
//
43+
// The password is in plaintext because this is an
44+
// open-source project without Play Store identity. A
45+
// forked/rebuilt APK signed with a different key is
46+
// fundamentally a different install path anyway — the
47+
// protection model here is "trust the source tree you
48+
// pulled from," not "trust that we hold a key you can't
49+
// see." If you're forking, generate your own key, commit
50+
// it, and ship.
51+
storeFile = file("release.jks")
52+
storePassword = "mhrv-rs-release"
53+
keyAlias = "mhrv-rs"
54+
keyPassword = "mhrv-rs-release"
55+
}
56+
}
57+
3358
buildTypes {
3459
release {
3560
isMinifyEnabled = false
3661
proguardFiles(
3762
getDefaultProguardFile("proguard-android-optimize.txt"),
3863
"proguard-rules.pro",
3964
)
40-
// Sign release builds with the debug keystore so users can
41-
// sideload the APK without us shipping a proper release key.
42-
// The project has no Play Store presence, so signature
43-
// identity per-build doesn't matter — installability does.
44-
// Gradle auto-creates `~/.android/debug.keystore` on first use;
45-
// CI runners inherit that behaviour. Anyone rebuilding from
46-
// source gets their own signature, which is what we want for
47-
// an open-source project: trust the source, not a key we hold.
48-
signingConfig = signingConfigs.getByName("debug")
65+
signingConfig = signingConfigs.getByName("release")
4966
}
5067
}
5168

android/app/release.jks

2.67 KB
Binary file not shown.

android/app/src/main/java/com/therealaleph/mhrv/CaInstall.kt

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,26 @@ object CaInstall {
147147
}
148148

149149
/**
150-
* Intent that opens the system "Security" settings screen. The exact
151-
* landing page depends on OEM and Android version:
152-
* - Pixel / stock AOSP: Settings → Security
153-
* - from there the user navigates Encryption & credentials →
154-
* Install a certificate → CA certificate → pick our .crt file.
150+
* Intent that opens the TOP-LEVEL system Settings app. The Settings
151+
* search bar is the most portable way to get users to the CA-install
152+
* screen across OEMs — every Android vendor ships the CA install
153+
* flow under a subtly different menu path (Encryption & credentials,
154+
* Other security settings, Privacy → Credentials, etc.), but they
155+
* all respond to a search for "CA certificate".
155156
*
156-
* We tried KeyChain.createInstallIntent first (nicer flow) but on
157-
* Android 11+ that intent just opens a dialog saying "Install CA
158-
* certificates in Settings" with a Close button and no path forward —
159-
* Google intentionally removed the inline install path. Settings is
160-
* the fallback Google themselves point users at.
157+
* Earlier versions used `Settings.ACTION_SECURITY_SETTINGS` which
158+
* landed on Security & privacy directly, but on some OEMs (Samsung,
159+
* Xiaomi, newer Pixel builds) that screen doesn't have the cert
160+
* install entry one tap away and users got stuck. Top-level Settings
161+
* + "search for CA certificate" is the instruction that actually
162+
* works everywhere.
163+
*
164+
* We DO NOT use KeyChain.createInstallIntent — on Android 11+ that
165+
* intent opens a dialog that just says "Install CA certificates in
166+
* Settings" with a Close button and no forward path. Google
167+
* intentionally removed the inline install flow in that release.
161168
*/
162-
fun buildSettingsIntent(): Intent = Intent(Settings.ACTION_SECURITY_SETTINGS)
169+
fun buildSettingsIntent(): Intent = Intent(Settings.ACTION_SETTINGS)
163170
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
164171

165172
/**

android/app/src/main/java/com/therealaleph/mhrv/MhrvVpnService.kt

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ class MhrvVpnService : VpnService() {
3636
private var tun2proxyThread: Thread? = null
3737
private val tun2proxyRunning = AtomicBoolean(false)
3838

39+
// Idempotency guard. teardown() is reachable from three paths:
40+
// 1. ACTION_STOP onStartCommand branch (background thread)
41+
// 2. onDestroy() (main thread, fires whenever stopSelf resolves
42+
// OR Android decides to kill the service)
43+
// 3. Android revoking the VPN profile out-of-band (also onDestroy)
44+
// Running the full native cleanup sequence twice races two threads
45+
// through Tun2proxy.stop(), fd.close(), Native.stopProxy() on state
46+
// that's already been nullified — the second pass was the
47+
// SIGSEGV-or-zombie source. This flag makes the second call a
48+
// no-op.
49+
private val tornDown = AtomicBoolean(false)
50+
3951
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
4052
Log.i(TAG, "onStartCommand action=${intent?.action ?: "<null>"} startId=$startId")
4153
return when (intent?.action) {
@@ -187,7 +199,21 @@ class MhrvVpnService : VpnService() {
187199
* 4. Shut down the Rust proxy runtime (nothing left to forward to).
188200
*/
189201
private fun teardown() {
190-
Log.i(TAG, "teardown: begin (tun2proxy running=${tun2proxyRunning.get()}, proxyHandle=$proxyHandle)")
202+
// Idempotency guard. Without this, onDestroy racing the
203+
// ACTION_STOP background thread has been observed to crash the
204+
// process — two threads into Tun2proxy.stop() and
205+
// Native.stopProxy(handle) where handle has already been zeroed
206+
// is a SIGSEGV waiting to happen. First caller wins, subsequent
207+
// callers return immediately.
208+
if (!tornDown.compareAndSet(false, true)) {
209+
Log.i(TAG, "teardown: already done, skipping (caller=${Thread.currentThread().name})")
210+
return
211+
}
212+
Log.i(
213+
TAG,
214+
"teardown: begin caller=${Thread.currentThread().name} " +
215+
"(tun2proxy running=${tun2proxyRunning.get()}, proxyHandle=$proxyHandle)",
216+
)
191217

192218
// 1. Cooperative stop signal.
193219
if (tun2proxyRunning.get()) {
@@ -200,7 +226,9 @@ class MhrvVpnService : VpnService() {
200226
// ParcelFileDescriptor no longer owns the fd and close() here
201227
// is a no-op; the real fd is owned by tun2proxy (closeFdOnDrop
202228
// = true), which closes it on return from run().
203-
try { tun?.close() } catch (_: Throwable) {}
229+
try { tun?.close() } catch (t: Throwable) {
230+
Log.w(TAG, "tun.close: ${t.message}")
231+
}
204232
tun = null
205233

206234
// 3. Join the worker. 4s is enough in the happy case; if tun2proxy
@@ -219,19 +247,31 @@ class MhrvVpnService : VpnService() {
219247
// on the Rust side, so this is bounded even if the runtime
220248
// has in-flight tasks (common when the Apps Script relay has
221249
// piled up pending 30s timeouts).
222-
if (proxyHandle != 0L) {
223-
Log.i(TAG, "teardown: stopping proxy handle=$proxyHandle")
224-
try { Native.stopProxy(proxyHandle) } catch (t: Throwable) {
250+
val handle = proxyHandle
251+
proxyHandle = 0L
252+
if (handle != 0L) {
253+
Log.i(TAG, "teardown: stopping proxy handle=$handle")
254+
try { Native.stopProxy(handle) } catch (t: Throwable) {
225255
Log.e(TAG, "Native.stopProxy threw: ${t.message}", t)
226256
}
227-
proxyHandle = 0L
228257
}
229258
Log.i(TAG, "teardown: done")
230259
}
231260

232261
override fun onDestroy() {
233-
teardown()
262+
Log.i(TAG, "onDestroy entered")
263+
try {
264+
teardown()
265+
} catch (t: Throwable) {
266+
// Belt-and-suspenders. Crashing out of onDestroy takes the
267+
// whole process with it — user-visible as the app closing
268+
// right when they tap Stop, which is exactly the symptom we
269+
// are trying to fix. Anything that gets here is logged and
270+
// swallowed.
271+
Log.e(TAG, "onDestroy teardown threw: ${t.message}", t)
272+
}
234273
super.onDestroy()
274+
Log.i(TAG, "onDestroy done")
235275
}
236276

237277
private fun buildNotif(proxyPort: Int): Notification {

android/app/src/main/java/com/therealaleph/mhrv/ui/HomeScreen.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fun HomeScreen(
115115
append("Certificate not yet installed.")
116116
if (!o.downloadPath.isNullOrBlank()) {
117117
append(" Saved to ${o.downloadPath}. ")
118-
append("In Settings: Encryption & credentials → Install a certificate → \"CA certificate\" (not VPN, not Wi-Fi) → pick that file.")
118+
append("In Settings, search for \"CA certificate\" and install from there — NOT \"VPN & app user certificate\" or \"Wi-Fi\".")
119119
} else {
120120
append(" Tap Install again to retry.")
121121
}
@@ -374,11 +374,13 @@ fun HomeScreen(
374374
Text(
375375
"On Android 11+ the system removed the inline install path, so " +
376376
"tapping Install will: (1) save a PEM copy to Downloads/mhrv-ca.crt, " +
377-
"(2) open Security settings. From there navigate to Encryption & " +
378-
"credentials → Install a certificate → pick \"CA certificate\" (NOT " +
379-
"\"VPN & app user certificate\" or \"Wi-Fi certificate\") → select " +
380-
"mhrv-ca.crt from Downloads. If you don't have a screen lock, Android " +
381-
"will ask you to add one first."
377+
"(2) open the Settings app.\n\n" +
378+
"Inside Settings, tap the search bar and type \"CA certificate\". " +
379+
"Open the result labelled \"CA certificate\" (NOT \"VPN & app user " +
380+
"certificate\" or \"Wi-Fi certificate\"). Pick mhrv-ca.crt from " +
381+
"Downloads when prompted. If you don't have a screen lock, Android " +
382+
"will ask you to add one first — that's an OS requirement for " +
383+
"installing any user CA."
382384
)
383385
if (fp != null) {
384386
Text("Subject: ${cn ?: "(unknown)"}", style = MaterialTheme.typography.labelMedium)
@@ -911,10 +913,10 @@ private fun HowToUseCard(listenPort: Int) {
911913
Text(
912914
"1. Paste one or more Apps Script deployment URLs (or bare IDs) and your auth_key.\n" +
913915
"2. Tap Install MITM certificate. Confirm the dialog — the cert is saved to " +
914-
"Downloads/mhrv-ca.crt and Security settings opens. Navigate: Encryption & " +
915-
"credentials → Install a certificate → \"CA certificate\" (NOT \"VPN & app user " +
916-
"certificate\" or \"Wi-Fi\"). Pick mhrv-ca.crt from Downloads. You'll be asked to " +
917-
"set a screen lock if you don't have one (Android requirement).\n" +
916+
"Downloads/mhrv-ca.crt and the Settings app opens. Use Settings' search bar " +
917+
"to find \"CA certificate\", tap that result (NOT \"VPN & app user certificate\" " +
918+
"or \"Wi-Fi\"), and pick mhrv-ca.crt from Downloads. You'll be asked to set a " +
919+
"screen lock if you don't have one (Android requirement).\n" +
918920
"3. Before tapping Start, expand \"SNI pool + tester\" and hit \"Test all\". If " +
919921
"every entry times out, your google_ip is unreachable — replace it with one that " +
920922
"resolves locally (e.g. `nslookup www.google.com` on any working device).\n" +

docs/android.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,9 @@ This step is annoying but unavoidable: the proxy terminates TLS on your behalf s
8989

9090
1. In the app, tap **Install MITM certificate**.
9191
2. Read the confirmation dialog — it shows the certificate fingerprint (handy to verify later). Tap **Install**.
92-
3. The app saves `Downloads/mhrv-ca.crt` and deep-links Android into **Settings → Security & privacy** (or similar; wording varies by OEM).
92+
3. The app saves `Downloads/mhrv-ca.crt` and opens the top-level **Settings** app.
9393
4. If you don't have a screen lock: Android will prompt you to set one. **You have to.** User CAs require a screen lock, period. Set PIN/pattern/password. You can remove it after install if you really want; the cert stays installed.
94-
5. In Settings, navigate: **Encryption & credentials → Install a certificate → "CA certificate"**.
95-
- On Pixel / stock Android: `Security → More security settings → Encryption & credentials → Install a certificate → CA certificate`.
96-
- On Samsung: `Biometrics and security → Other security settings → Install from device storage → CA certificate`.
97-
- On Xiaomi/MIUI: `Passwords & Security → Privacy → Encryption & credentials → Install a certificate → CA certificate`.
94+
5. In Settings, tap the **search bar at the top** and type `CA certificate`. Pick the result labelled **"CA certificate"** (or on some OEMs "Install CA certificate"). The menu path varies wildly between Pixel / Samsung / Xiaomi / etc., which is why searching beats navigating.
9895
- **Do NOT** pick "VPN & app user certificate" or "Wi-Fi certificate" — wrong category, won't work.
9996
6. Android warns you: **"Your network may be monitored by an unknown third party"**. That's us. Tap **Install anyway**.
10097
7. Pick **Downloads** → tap **mhrv-ca.crt**. Give it a friendly name (or accept the default). Tap **OK**.

releases/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
This folder contains the prebuilt binaries from the latest release, committed directly to the repository for users who cannot reach the GitHub Releases page.
44

5-
Current version: **v1.0.1**
5+
Current version: **v1.0.2**
66

77
| File | Platform | Contents |
88
|---|---|---|
9-
| `mhrv-rs-android-universal-v1.0.1.apk` | Android 7.0+ (all ABIs) | Universal APK — arm64-v8a, armeabi-v7a, x86_64, x86 in one file |
9+
| `mhrv-rs-android-universal-v1.0.2.apk` | Android 7.0+ (all ABIs) | Universal APK — arm64-v8a, armeabi-v7a, x86_64, x86 in one file |
1010
| `mhrv-rs-linux-amd64.tar.gz` | Linux x86_64 | `mhrv-rs`, `mhrv-rs-ui`, `run.sh` |
1111
| `mhrv-rs-linux-arm64.tar.gz` | Linux aarch64 | `mhrv-rs`, `run.sh` (CLI only) |
1212
| `mhrv-rs-raspbian-armhf.tar.gz` | Raspberry Pi / ARMv7 hardfloat | `mhrv-rs`, `run.sh` (CLI only) |
@@ -45,7 +45,7 @@ Extract `mhrv-rs-windows-amd64.zip`, then double-click `run.bat` inside the extr
4545

4646
### Android
4747

48-
Copy `mhrv-rs-android-universal-v1.0.1.apk` to your phone, tap it from the Files app, and allow "Install unknown apps" for whichever app is opening the APK (Files, Chrome, etc.). See [the Android guide](../docs/android.md) for the full walk-through of the first-run steps (Apps Script deployment, MITM CA install, VPN permission, SNI tester).
48+
Copy `mhrv-rs-android-universal-v1.0.2.apk` to your phone, tap it from the Files app, and allow "Install unknown apps" for whichever app is opening the APK (Files, Chrome, etc.). See [the Android guide](../docs/android.md) for the full walk-through of the first-run steps (Apps Script deployment, MITM CA install, VPN permission, SNI tester).
4949

5050
See the [main README](../README.md) for desktop setup (Apps Script deployment, config, browser proxy settings).
5151

@@ -55,7 +55,7 @@ See the [main README](../README.md) for desktop setup (Apps Script deployment, c
5555

5656
این پوشه شامل فایل‌های آخرین نسخه است و مستقیماً در ریپو قرار گرفته برای کاربرانی که به صفحهٔ GitHub Releases دسترسی ندارند.
5757

58-
نسخهٔ فعلی: **v1.0.1**
58+
نسخهٔ فعلی: **v1.0.2**
5959

6060
### دانلود از طریق ZIP
6161

@@ -73,6 +73,6 @@ cd mhrv-rs-macos-arm64
7373

7474
**ویندوز:** فایل `mhrv-rs-windows-amd64.zip` را extract کنید و داخل پوشه روی `run.bat` دو بار کلیک کنید (UAC را قبول کنید تا گواهی MITM نصب شود).
7575

76-
**اندروید:** فایل `mhrv-rs-android-universal-v1.0.1.apk` را روی گوشی کپی کنید، از Files app روی آن tap کنید و اجازهٔ "نصب برنامه‌های ناشناس" را بدهید. راهنمای کامل شروع به کار (دیپلوی Apps Script، نصب CA، اجازهٔ VPN، تستر SNI) در [راهنمای اندروید](../docs/android.md) هست.
76+
**اندروید:** فایل `mhrv-rs-android-universal-v1.0.2.apk` را روی گوشی کپی کنید، از Files app روی آن tap کنید و اجازهٔ "نصب برنامه‌های ناشناس" را بدهید. راهنمای کامل شروع به کار (دیپلوی Apps Script، نصب CA، اجازهٔ VPN، تستر SNI) در [راهنمای اندروید](../docs/android.md) هست.
7777

7878
برای راه‌اندازی کامل دسکتاپ (دیپلوی Apps Script، config، تنظیم proxy مرورگر) به [README اصلی](../README.md) مراجعه کنید.
36.4 MB
Binary file not shown.

0 commit comments

Comments
 (0)