communicate: WhatsApp registration - exact official UA sanitization (regex [^,.\w()-]->_ per token, decompiled C09990d9); token/e2e/cert verified byte-identical to official 2.26.29.73
- Commit
dced00c8ecc8d0df8d012559c9de52f47ba1a97c- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-16 20:30 UTC (3 months ago)
- Parents
e9fa0f6
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 fae90576ce..a5e1239668 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@@ -533,10 +533,20 @@ class RegistrationHttpClient( } } - /** WhatsApp/<ver> Android/<osrel> Device/<manufacturer>-<model> (server parses platform here). */+ /**+ * `WhatsApp/<ver> Android/<osrel> Device/<manufacturer>-<model>` — byte-for-byte the official+ * app's registration UA (decompiled `X/C09990d9.A01`, com.whatsapp 2.26.29.73): app name+ * "WhatsApp", version, "Android"/osRelease, "Device/"manufacturer-model, with a trailing+ * empty token (`Voip.REJECT_REASON_DECLINED == ""`). Each device token (osRelease, manufacturer,+ * model) is sanitized with WhatsApp's exact regex `[^,.\w\-()]` → "_" (NOT just spaces). The+ * server derives `platform` from this UA.+ */ private fun userAgent(): String {- val device = "${Build.MANUFACTURER}-${Build.MODEL}".replace(' ', '_')- return "WhatsApp/${WhatsAppProtocol.WA_VERSION_NAME} Android/${Build.VERSION.RELEASE} Device/$device"+ val san = Regex("[^,.\\w()\\-]")+ val os = san.replace(Build.VERSION.RELEASE.orEmpty(), "_")+ val mfr = san.replace(Build.MANUFACTURER.orEmpty(), "_")+ val model = san.replace(Build.MODEL.orEmpty(), "_")+ return "WhatsApp/${WhatsAppProtocol.WA_VERSION_NAME} Android/$os Device/$mfr-$model" } private fun parse(body: String): JSONObject = try {
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 862e8d8a22..38051c2a17 100644--- a/communicate/src/test/java/com/vayunmathur/communicate/whatsapp/WhatsAppRegistrationBadParamRegressionTest.kt+++ b/communicate/src/test/java/com/vayunmathur/communicate/whatsapp/WhatsAppRegistrationBadParamRegressionTest.kt@@ -46,9 +46,13 @@ class WhatsAppRegistrationBadParamRegressionTest { } private fun userAgent(manufacturer: String, model: String, osRelease: String): String {- // Exact mirror of RegistrationHttpClient.userAgent(): only device token underscored.- val device = "$manufacturer-$model".replace(' ', '_')- return "WhatsApp/${WhatsAppProtocol.WA_VERSION_NAME} Android/$osRelease Device/$device"+ // Exact mirror of RegistrationHttpClient.userAgent(): per-token sanitize with WhatsApp's+ // regex [^,.\w()-] -> "_" (decompiled X/C09990d9.A01).+ val san = Regex("[^,.\\w()\\-]")+ val os = san.replace(osRelease, "_")+ val mfr = san.replace(manufacturer, "_")+ val mdl = san.replace(model, "_")+ return "WhatsApp/${WhatsAppProtocol.WA_VERSION_NAME} Android/$os Device/$mfr-$mdl" } private fun tryReadSource(relative: String): String? {