communicate: WhatsApp registration - stop sending non-official integrity blob (_gi/aid/_gp) + e_pq bundle; restore verified param set
- Commit
4803ccd99e5d4a1e96d2ec01a54cdc14c0c4bad5- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-16 18:39 UTC (3 months ago)
- Parents
7c90bf3
Diff
communicate/src/main/java/com/vayunmathur/communicate/data/whatsapp/registration/RegistrationHttpClient.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/data/whatsapp/registration/RegistrationHttpClient.kt b/communicate/src/main/java/com/vayunmathur/communicate/data/whatsapp/registration/RegistrationHttpClient.ktindex 441a6cf165..e3a52ff467 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/data/whatsapp/registration/RegistrationHttpClient.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/data/whatsapp/registration/RegistrationHttpClient.kt@@ -438,12 +438,19 @@ class RegistrationHttpClient( * NOT sent — they are bound to the official signed WhatsApp app identity and an unofficial * client cannot mint server-valid tokens (documented, not faked). *- * Inclusion per endpoint:+ * DEFAULT OFF (see [SEND_INTEGRITY_SIGNALS]): the honest signals we *can* compute+ * (`_gi` = ENC of THIS app's apk/cert/package, `aid`, `_gp`) positively identify the client+ * as non-WhatsApp, which is strictly worse than omitting them. The last live-verified+ * registration (whatsapp-documentation.md §2, pre-`e7e120`) sent NONE of these, so by default+ * we restore that verified param set and this method is a no-op.+ *+ * Inclusion per endpoint (only when the switch is flipped on for experimentation): * - EXIST: aid,_gi,_gp,_ge,_ga,_gs,db (+profile_name; no t) * - CODE: aid,_gi,_gp,_ge,_ga,_gs,t,hasav * - REGISTER: aid,_gi,_gp,_ge,_ga,_gs,t */ fun addIntegrity(kind: EndpointKind) {+ if (!SEND_INTEGRITY_SIGNALS) return val s = runCatching { RegistrationIntegrity.collect(context) }.getOrNull() ?: return if (s.aid.isNotEmpty()) a01("aid", s.aid) a02("_gi", s.gi)@@ -520,6 +527,21 @@ class RegistrationHttpClient( companion object { private const val TAG = "WARegHttp"++ /**+ * Master switch for the Phase-B device-integrity signals+ * (`aid`,`_gi`,`_gp`,`_ge`,`_ga`,`_gs`,`t`,`hasav`,`db`,`profile_name`) added in `e7e120`.+ *+ * DEFAULT **false** — restores the last live-verified registration param set+ * (whatsapp-documentation.md §2 / base commit `33dd602`, which returned `status:ok`). These+ * signals were added AFTER that success and never validated live; critically `_gi` is an ENC+ * blob the server decrypts to `package=com.vayunmathur.communicate` + this app's apk/cert+ * hash, and `aid`/`_gp` further fingerprint the non-official app. Since we also cannot mint+ * the server-required Play-Integrity / reCAPTCHA-Enterprise proofs, sending honest-but-wrong+ * -app integrity can only hurt. Flip to `true` only to experiment (the wire shapes are still+ * validated by WhatsAppRegistrationBadParamRegressionTest.addIntegrity_perEndpointCorrectFields).+ */+ private const val SEND_INTEGRITY_SIGNALS = false } /** WAMSYS endpoint kinds that carry per-endpoint integrity params (w2.md §3.1-3.3). */
communicate/src/main/java/com/vayunmathur/communicate/data/whatsapp/registration/RegistrationKeys.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/data/whatsapp/registration/RegistrationKeys.kt b/communicate/src/main/java/com/vayunmathur/communicate/data/whatsapp/registration/RegistrationKeys.ktindex 6c58f01ce7..bc97446450 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/data/whatsapp/registration/RegistrationKeys.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/data/whatsapp/registration/RegistrationKeys.kt@@ -23,6 +23,15 @@ class RegistrationKeys private constructor( fun registerBundleFields(): Map<String, String> = bundleFields(authScaffold) companion object {+ /**+ * DEFAULT **false** — do not attach the post-quantum `e_pq_last_resort_*` bundle to the+ * `/v2` registration request. Restores the last live-verified param set (base commit+ * `33dd602`, which returned `status:ok` with only the classic 7-field bundle); the PQ bundle+ * added in `e7e120` was never validated live and its server acceptance is User-Agent-gated.+ * Flip to `true` to generate + attach it (bundleFields still enforces all-or-none).+ */+ const val EMIT_PQ_LAST_RESORT = false+ fun generate(phoneNumber: String): RegistrationKeys { val rng = SecureRandom() @@ -35,12 +44,20 @@ class RegistrationKeys private constructor( val signature = WhatsAppE2E.signSignedPreKey(identity.privateKey, signedPreKey.publicKey) - // Post-quantum last-resort prekey (Phase B 2d). Best-effort: if the KEM API/native- // signer is unavailable the PQ fields stay empty and bundleFields omits e_pq_* entirely- // (all-or-none), so classic registration still works.- val pq = try {- WhatsAppPqPreKey.generate(identity.privateKey, WhatsAppRegistrationConstants.PQ_LAST_RESORT_KEY_ID)- } catch (t: Throwable) {+ // Post-quantum last-resort prekey (Phase B 2d). DEFAULT OFF ([EMIT_PQ_LAST_RESORT]):+ // this e_pq_* bundle was added in `e7e120` AFTER the last live-verified registration+ // (whatsapp-documentation.md §2 sent only the classic 7-field bundle) and was never+ // validated live; server PQ expectation is User-Agent-gated, so an unexpected/mismatched+ // e_pq_* can draw bad_param. When off, the fields stay empty and bundleFields omits+ // e_pq_* entirely (all-or-none), matching the verified param set. Best-effort even when+ // enabled: a KEM/native-signer failure also leaves the fields empty.+ val pq = if (EMIT_PQ_LAST_RESORT) {+ try {+ WhatsAppPqPreKey.generate(identity.privateKey, WhatsAppRegistrationConstants.PQ_LAST_RESORT_KEY_ID)+ } catch (t: Throwable) {+ null+ }+ } else { null }
communicate/src/test/java/com/vayunmathur/communicate/whatsapp/WhatsAppRegistrationBadParamRegressionTest.kt
diff --git a/communicate/src/test/java/com/vayunmathur/communicate/whatsapp/WhatsAppRegistrationBadParamRegressionTest.kt b/communicate/src/test/java/com/vayunmathur/communicate/whatsapp/WhatsAppRegistrationBadParamRegressionTest.ktindex 684ae6f6ba..54cc6b0870 100644--- a/communicate/src/test/java/com/vayunmathur/communicate/whatsapp/WhatsAppRegistrationBadParamRegressionTest.kt+++ b/communicate/src/test/java/com/vayunmathur/communicate/whatsapp/WhatsAppRegistrationBadParamRegressionTest.kt@@ -366,7 +366,13 @@ class WhatsAppRegistrationBadParamRegressionTest { val snippet = src.substring(existIdx, minOf(src.length, existIdx + 2000)) assertTrue(snippet.contains("token"), "checkExist must include token param (bad_param fix w2.md §3.1)") assertTrue(snippet.contains("computeToken"), "checkExist token must be via computeToken")- assertTrue(snippet.contains("EndpointKind.EXIST"), "checkExist must addIntegrity(EXIST)")+ // Phase-B device-integrity signals are gated OFF by default (restored verified-live+ // param set from base commit 33dd602): _gi/aid/_gp must NOT be sent, so the master+ // switch has to be disabled. (The addIntegrity() body itself early-returns on it.)+ assertTrue(+ src.contains("SEND_INTEGRITY_SIGNALS = false"),+ "integrity signals must be gated OFF by default (restored verified-live param set)",+ ) } }