Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / auto / docs / FINDINGS.md
| 1 | # Android Auto (gearhead) teardown — for MA Auto |
| 2 | |
| 3 | Source: Pixel 7 Pro (`cheetah`), `com.google.android.projection.gearhead` |
| 4 | version **17.5.663214-release** (versionCode 175663214, minSdk 32, targetSdk 37). |
| 5 | |
| 6 | APKs pulled to `apk/` (base + arm64_v8a + en + xxxhdpi). |
| 7 | jadx output in `jadx-out/` (26,173 java files, 235 decompile errors — non-fatal). |
| 8 | Raw dex in `dex/`, extracted PEMs in `certs/`. |
| 9 | |
| 10 | --- |
| 11 | |
| 12 | ## 1. What role it holds |
| 13 | |
| 14 | `android.app.role.SYSTEM_AUTOMOTIVE_PROJECTION`, confirmed live on device: |
| 15 | |
| 16 | ``` |
| 17 | $ adb shell cmd role get-role-holders android.app.role.SYSTEM_AUTOMOTIVE_PROJECTION --user 0 |
| 18 | com.google.android.projection.gearhead |
| 19 | ``` |
| 20 | |
| 21 | Role definition (`packages/modules/Permission/PermissionController/res/xml/roles.xml:624`): |
| 22 | |
| 23 | - `defaultHolders="config_systemAutomotiveProjection"` → pinnable from an RRO exactly |
| 24 | like the five roles we already pin in `MaosFrameworkResRRO`. |
| 25 | - `exclusive`, `static`, `systemOnly`, `visible="false"` — no user-facing picker, |
| 26 | it is a build-time assignment. |
| 27 | - Grants: microphone / location / nearby_devices / notifications permission sets, plus |
| 28 | `ADD_ALWAYS_UNLOCKED_DISPLAY`, `ADD_TRUSTED_DISPLAY`, `CREATE_VIRTUAL_DEVICE`, |
| 29 | `CAPTURE_SECURE_VIDEO_OUTPUT`, `TOGGLE_AUTOMOTIVE_PROJECTION`, |
| 30 | `ASSOCIATE_COMPANION_DEVICES`, `REQUEST_COMPANION_PROFILE_AUTOMOTIVE_PROJECTION`, |
| 31 | `RECEIVE_SENSITIVE_NOTIFICATIONS`, `GET_INTENT_SENDER_INTENT`, `CALL_PHONE`, |
| 32 | `READ_CALENDAR`, `READ_CALL_LOG`, `READ_CONTACTS`, `READ_PHONE_STATE`, |
| 33 | `RECEIVE_SMS`, `SEND_SMS`. |
| 34 | - App-ops: `android:receive_sensitive_notifications`, `android:read_restricted_messages`. |
| 35 | |
| 36 | The role is necessary but **nowhere near sufficient**. Gearhead requests 78 permissions; |
| 37 | the role grants ~20 of them. The rest (`MODIFY_AUDIO_ROUTING`, `TETHER_PRIVILEGED`, |
| 38 | `CALL_PRIVILEGED`, `MANAGE_USB`, `POWER_SAVER`, `READ_PRIVILEGED_PHONE_STATE`, |
| 39 | `CHANGE_COMPONENT_ENABLED_STATE`, `MANAGE_USERS`, `CAPTURE_SECURE_VIDEO_OUTPUT`, …) |
| 40 | come from `signature|privileged` + a privapp-permissions allowlist entry. |
| 41 | |
| 42 | --- |
| 43 | |
| 44 | ## 2. Architecture |
| 45 | |
| 46 | Historically the projection stack lived in GMS Core (`com.google.android.gms.car.*`). |
| 47 | It has been **absorbed into gearhead** — `com.google.android.apps.auto.carservice.gmscorecompat.CarChimeraService` |
| 48 | is the in-app replacement, and the whole GAL stack ships in this APK. So there is no |
| 49 | GMS dependency to reverse; everything is here. |
| 50 | |
| 51 | Two layers: |
| 52 | |
| 53 | - **Transport + GAL protocol** — obfuscated into `defpackage`, class families `rs*`, |
| 54 | `rt*`, `ru*`, `rv*`. Log tags `CAR.GAL.*`. |
| 55 | - **Car UI / apps** — `com.google.android.apps.auto.components` (214 files), |
| 56 | `com.google.android.gearhead.*`, plus `androidx.car.app` host support. |
| 57 | |
| 58 | Public-ish parcelable surface in `com.google.android.gms.car.*` (98 files) is a clean |
| 59 | readable spec of the data model: `CarDisplay`, `CarWindowLayoutParams`, |
| 60 | `CarActivityLayoutParams`, `CarSensorEvent`, `CarAudioConfiguration`, `CarCall`, |
| 61 | `navigation/NavigationState`, `control/CarProperty*`, `senderprotocol/Channel`. |
| 62 | |
| 63 | ### GAL subsystems (from log tags) |
| 64 | |
| 65 | `GAL` (control) · `SECURITY` · `VIDEO` · `AUDIO` · `MIC` · `INPUT` · `SENSOR` · |
| 66 | `MEDIA` · `RADIO` · `INST` (instrument cluster) · `BT` · `WIFI` · `CAR` · |
| 67 | `DIAGNOSTICS` · `LATENCY` · `SERVICE` · `SNOOP` · `SYNC` |
| 68 | |
| 69 | Each becomes a numbered channel; `senderprotocol/Channel.java` is the per-channel |
| 70 | state machine (states 0=new 1=opening 2=open 4=closed), and channel open is control |
| 71 | message **7** carrying `{priority, service_id}` — note that order, it is easy to get |
| 72 | backwards. |
| 73 | |
| 74 | ### Two parallel copies of the stack |
| 75 | |
| 76 | As with `rvd`/`rvg` and `jby`/`jca` in the crypto, the whole endpoint layer exists twice: |
| 77 | an `r*` family (`ruq` base, `rth` control, `rvb` sensor, `rug` media) and a `j*` family |
| 78 | (`jbj` base, `izu` control, `jdk` media sink, `jem` video, `jdi` mic, `jar` input). The |
| 79 | `j*` family is the live one — it is what `com.google.android.apps.auto.carservice` |
| 80 | drives. Message IDs agree across both where they overlap. |
| 81 | |
| 82 | ### Frame layout |
| 83 | |
| 84 | ``` |
| 85 | byte 0 channel id |
| 86 | byte 1 flags |
| 87 | bytes 2-3 payload length, big-endian uint16 (on-wire length, post-encryption) |
| 88 | bytes 4-7 total message length, big-endian int32 -- only when FIRST && !LAST |
| 89 | ``` |
| 90 | |
| 91 | | Flag | Bit | Meaning | |
| 92 | |------|-----|---------| |
| 93 | | FIRST | `0x01` | first fragment | |
| 94 | | LAST | `0x02` | last fragment | |
| 95 | | CONTROL | `0x04` | control-channel message | |
| 96 | | ENCRYPTED | `0x08` | payload is TLS-wrapped | |
| 97 | |
| 98 | An unfragmented message is `FIRST|LAST` = `0x03` with a 4-byte header. Default fragment |
| 99 | size is **16128** (`rto.a()`); control messages may not be fragmented at all. Above the |
| 100 | frame, every channel's payload is `[2-byte big-endian message type][protobuf]`, read as |
| 101 | an unsigned `char` so `0xFFFF` works. |
| 102 | |
| 103 | Sender is `rts.a`; receiver is the `rtr` state machine, which replies with a 2-byte |
| 104 | `0xFFFF` framing-error control frame and tears down on malformed input. |
| 105 | |
| 106 | ### Control channel message types |
| 107 | |
| 108 | Read off the dispatch in `defpackage/rth.java`: |
| 109 | |
| 110 | | ID | Dir | Message | |
| 111 | |----|-----|---------| |
| 112 | | 1 | recv | VersionRequest — **the head unit asks first**; two raw big-endian uint16s | |
| 113 | | 2 | send | VersionResponse — major, minor, status, again raw shorts (8-byte frame with the type) | |
| 114 | | 3 | both | SSL handshake data (wrapped/unwrapped by `rvg`) | |
| 115 | | 4 | recv | AuthComplete (`STATUS_SUCCESS`, `..._CERT_EXPIRED`, `..._CERT_NOT_YET_VALID`) | |
| 116 | | 5 | send | ServiceDiscoveryRequest (`xoa`) | |
| 117 | | 6 | recv | ServiceDiscoveryResponse (`xob`, `repeated Service`) | |
| 118 | | 7 / 8 | send / recv | ChannelOpenRequest / Response | |
| 119 | | 11 / 12 | recv / send | PingRequest / PingResponse | |
| 120 | | 14 | recv | NavigationFocusNotification (`NAV_FOCUS_NATIVE` / projected) | |
| 121 | | 15 / 16 | both | ByeByeRequest / Response (reasons: `USER_SELECTION`, `DEVICE_SWITCH`) | |
| 122 | | 18 | send | AudioFocusRequest | |
| 123 | | 19 | recv | AudioFocusNotification (`AUDIO_FOCUS_STATE_*`) | |
| 124 | | 24 | recv | CallAvailabilityStatus | |
| 125 | | 26 | recv | ServiceDiscoveryUpdate (hot-add/update a service) | |
| 126 | | 255 | both | MessageError | |
| 127 | | 65535 | both | FramingError | |
| 128 | |
| 129 | **Messages 1 and 2 are not protobuf.** Every other control message carries a protobuf |
| 130 | payload; version negotiation carries raw big-endian uint16s, written a short at a time |
| 131 | (`jcn.v((short) …)` in `izu`). The response is major, minor, then the status as a signed |
| 132 | enum value truncated to a short, so `STATUS_NO_COMPATIBLE_VERSION` (-1) goes out as |
| 133 | `0xFFFF`. |
| 134 | |
| 135 | **The head unit opens the conversation.** The control endpoint logs "Car requests protocol |
| 136 | version %s" on receiving message 1 — the phone does not send a version request, it answers |
| 137 | one. A sender that speaks first will sit unanswered. Gearhead 17.5 advertises 1.7, and |
| 138 | `rth` gates the service-discovery request on having reached at least 1.6. |
| 139 | |
| 140 | **The head unit advertises the services; the phone consumes the list.** For a sender |
| 141 | reimplementation that inverts the obvious reading: we *parse* `xob`, we do not build it. |
| 142 | |
| 143 | ### Service table (`xnz`) |
| 144 | |
| 145 | Cross-checked against the human-readable dumper `rta.a(xnz)`. |
| 146 | |
| 147 | | Field | Payload | Service | |
| 148 | |-------|---------|---------| |
| 149 | | 1 | required int32 | service id (== the channel id) | |
| 150 | | 2 | `xnx` | SensorSource | |
| 151 | | 3 | `xko` | MediaSink (audio *and* video) | |
| 152 | | 4 | `xjw` | InputSource | |
| 153 | | 5 | `xkp` | MediaSource (mic) | |
| 154 | | 6 | `xht` | Bluetooth | |
| 155 | | 7 | `xnb` | Radio | |
| 156 | | 8 | `xlo` | NavigationStatus | |
| 157 | | 9 | `xkn` | MediaPlaybackStatus | |
| 158 | | 10 | `xmf` | PhoneStatus | |
| 159 | | 11 | `xki` | MediaBrowser | |
| 160 | | 12 | `xoz` | VendorExtension | |
| 161 | | 13 | `xjm` | Notification | |
| 162 | | 14 | `xpl` | WifiProjection | |
| 163 | |
| 164 | Internal purpose enum `rro` is the definitive list of what gearhead implements: |
| 165 | `1 CONTROL, 2 VIDEO_SINK, 3 AUDIO_SINK_GUIDANCE, 4 AUDIO_SINK_SYSTEM, 5 AUDIO_SINK_MEDIA, |
| 166 | 6 AUDIO_SOURCE, 7 SENSOR_SOURCE, 8 INPUT_SOURCE, 9 BLUETOOTH, 10 NAVIGATION_STATUS, |
| 167 | 11 MEDIA_PLAYBACK_STATUS, 12 MEDIA_BROWSER, 13 PHONE_STATUS, 14 NOTIFICATION, 15 RADIO, |
| 168 | 16 VENDOR_EXTENSION, 17 WIFI_PROJECTION, 18 WIFI_DISCOVERY, 19 CAR_CONTROL, |
| 169 | 20 CAR_LOCAL_MEDIA, 21 BUFFERED_MEDIA_SINK, 22 CAR_INTENT`. |
| 170 | |
| 171 | Supporting protos: `xko` MediaSink `{1 codec_type(xkj), 2 audio_type, 3 repeated xhf |
| 172 | audio_configs, 4 repeated xpd video_configs}` · `xhf` AudioConfiguration `{1 required |
| 173 | uint32 sampling_rate, 2 required uint32 number_of_bits, 3 required uint32 channels}` · |
| 174 | `xpd` VideoConfiguration `{1 resolution(xpc), 2 frame_rate, 3 width_margin, |
| 175 | 4 height_margin, 5 density}` · `xkj` codecs `{1 PCM, 2 AAC_LC, 3 H264_BP, 4 AAC_LC_ADTS, |
| 176 | 5 VP9, 6 AV1, 7 H265}` · `xpc` resolutions `{800x480, 1280x720, 1920x1080, 2560x1440, |
| 177 | 3840x2160, 720x1280, 1080x1920, 1440x2560, 2160x3840}`. |
| 178 | |
| 179 | ### Non-control channel message IDs |
| 180 | |
| 181 | Non-control channels use **0x8000-based** IDs, unlike the control channel's small ints. |
| 182 | |
| 183 | **Third jadx-adjacent trap — the `wub.o` off-by-one.** `jdk` and `jdi` dispatch on |
| 184 | `int iO = wub.o(i)`, and `wub.o` maps a wire id to a **1-based enum index** — for this |
| 185 | range it is simply `i + 1` (`0→1, 1→2, 32768→32769, …`). Sends do *not* go through it: |
| 186 | `jbj.o` writes `jcnVar.v((short) i)` with the raw id into a `payload + 2` buffer. So |
| 187 | every `iO ==` comparison in those classes is **one greater than the real wire id**, while |
| 188 | every `k(id, …)` call site is already raw. Reading the comparisons as wire ids gives you |
| 189 | every received media message off by one. `jem` and `jar` override `a()` and compare the |
| 190 | raw id directly, so they do not have this shift. |
| 191 | |
| 192 | The corrected IDs below agree with the public aasdk/openauto tables, which is a useful |
| 193 | independent check on the whole decoding. |
| 194 | |
| 195 | **Media sink — `jdk`, shared by video and all three audio sinks:** |
| 196 | |
| 197 | | Wire ID | Dir | Message | |
| 198 | |---------|-----|---------| |
| 199 | | `0x0000` | recv | MediaDataWithTimestamp — 8-byte timestamp then the payload | |
| 200 | | `0x0001` | recv | MediaData | |
| 201 | | `0x8000` | send | MediaSetupRequest (`xof`) | |
| 202 | | `0x8001` | send | MediaStartRequest (`xoh`) | |
| 203 | | `0x8002` | send | MediaStopRequest (`xoi`, empty) | |
| 204 | | `0x8003` | recv | Config (`xiu`) | |
| 205 | | `0x8004` | recv | MediaAck (`xgz`) — carries the frame counter mod 256 | |
| 206 | | `0x800B` | recv | (no payload) | |
| 207 | | `0x8013` | recv | (`xkq`) | |
| 208 | |
| 209 | **Video — `jem` (service 2), extends `jdk`, compares raw:** |
| 210 | |
| 211 | | Wire ID | Dir | Message | |
| 212 | |---------|-----|---------| |
| 213 | | `0x8007` | send | VideoFocusRequest (`xph` `{2 mode(xpe), 3 reason(xpg)}`) | |
| 214 | | `0x8008` | recv | VideoFocusIndication (`xpf` `{mode, unsolicited}`) | |
| 215 | | `0x800A` | send | UpdateUiConfigRequest (`xow` `{1 xop}`) | |
| 216 | |
| 217 | Video focus modes (`xpe`): `VIDEO_FOCUS_NATIVE`, `VIDEO_FOCUS_PROJECTED`, |
| 218 | `VIDEO_FOCUS_NATIVE_TRANSIENT`, `VIDEO_FOCUS_PROJECTED_NO_INPUT_FOCUS`. Input focus is |
| 219 | derived from video focus rather than negotiated separately. |
| 220 | |
| 221 | **Microphone / MediaSource — `jdi` (service 6). The *car* owns this microphone**, so the |
| 222 | phone receives audio and sends the acks (`jaz`, the concrete subclass, sends `0x8004`). |
| 223 | |
| 224 | | Wire ID | Dir | Message | |
| 225 | |---------|-----|---------| |
| 226 | | `0x0000` | recv | audio data, 8-byte timestamp prefix | |
| 227 | | `0x8004` | send | MediaAck (`xgz`) | |
| 228 | | `0x8006` | recv | MicrophoneRequest (`xkt`) | |
| 229 | |
| 230 | **Input — `jar` (service 8), compares raw:** |
| 231 | |
| 232 | | Wire ID | Dir | Message | |
| 233 | |---------|-----|---------| |
| 234 | | `0x8001` | recv | InputReport (`xjt` `{3 xom touch, 4 xkf key_events}`) | |
| 235 | | `0x8002` | send | KeyBindingRequest | |
| 236 | | `0x8003` | recv | KeyBindingResponse (`xkc` `{status}`) | |
| 237 | |
| 238 | **Sensor — `rvb` (service 7):** |
| 239 | |
| 240 | | Wire ID | Dir | Message | |
| 241 | |---------|-----|---------| |
| 242 | | `0x8001` | send | SensorRequest (`xnu` `{1 sensor_type, 2 min_update_period}`), synchronous, 2000 ms timeout; `-1` unsubscribes | |
| 243 | | `0x8002` | recv | SensorResponse (`xnv`) | |
| 244 | | `0x8003` | recv | SensorBatch (`xnr`) | |
| 245 | | `0x8004` | recv | SensorError (`xns`) | |
| 246 | |
| 247 | 26 sensor types in `xny`: `LOCATION, COMPASS, SPEED, RPM, ODOMETER, FUEL, PARKING_BRAKE, |
| 248 | GEAR, OBDII_DIAGNOSTIC_CODE, NIGHT_MODE, ENVIRONMENT_DATA, HVAC_DATA, |
| 249 | DRIVING_STATUS_DATA, DEAD_RECKONING_DATA, PASSENGER_DATA, DOOR_DATA, LIGHT_DATA, |
| 250 | TIRE_PRESSURE_DATA, ACCELEROMETER_DATA, GYROSCOPE_DATA, GPS_SATELLITE_DATA, TOLL_CARD, |
| 251 | VEHICLE_ENERGY_MODEL_DATA, TRAILER_DATA, RAW_VEHICLE_ENERGY_MODEL, RAW_EV_TRIP_SETTINGS`. |
| 252 | |
| 253 | **Still unmapped: both transports.** Leads for Phase 2: |
| 254 | |
| 255 | - **USB (AOAP)** — start at `com/google/android/gms/carsetup/setup/UsbConnectionHelper.java`, |
| 256 | which is *not* obfuscated, plus `CarUsbReceiver` / `CarUsbReceiverTPlus` and the action |
| 257 | `com.google.android.gms.car.usb.USB_ACCESSORY_FORCE_START`. |
| 258 | - **Wireless** — `WirelessSetupSharedService` and `com.google.android.gms.car.wifi.BT_START`. |
| 259 | `defpackage/ebe.java` is a phenotype-flag dumper holding the whole |
| 260 | `WirelessProjectionInGearhead__*` set, which maps the feature surface without reading the |
| 261 | implementation: Bluetooth ACL/HFP tracking with per-stage timeouts, an RFCOMM fallback |
| 262 | (`fallback_to_rfcomm_on_t_minus`), CDM association driving the trigger |
| 263 | (`associate_bt_devices_and_trigger_wireless_from_cdm`), a WiFi network request supporting |
| 264 | hidden SSIDs, dual-STA, and local-only-network handling. Useful as a checklist of what a |
| 265 | complete wireless bring-up has to handle. |
| 266 | |
| 267 | Two service→endpoint factory indexes exist, one per family: `qqv` implements `ruu` for the |
| 268 | `r*` family, and the `j*` family has its own. Either enumerates every service the stack can |
| 269 | open, if more are needed than the ones tabulated above. |
| 270 | |
| 271 | --- |
| 272 | |
| 273 | ## 3. The crypto — this is the important part |
| 274 | |
| 275 | `defpackage/rth.java:180-209` builds the SSL context: |
| 276 | |
| 277 | ```java |
| 278 | SSLContext ctx = SSLContext.getInstance("TLSv1.2"); |
| 279 | ... |
| 280 | engine.setUseClientMode(false); |
| 281 | engine.setNeedClientAuth(true); |
| 282 | ``` |
| 283 | |
| 284 | **The phone is the TLS server. The head unit is the TLS client, and must present a |
| 285 | client certificate.** Both sides chain to the same private Google root. |
| 286 | |
| 287 | Two certs are embedded (extracted to `certs/blob0.pem`, `certs/blob1.pem`): |
| 288 | |
| 289 | | | Subject | Issuer | Valid | |
| 290 | |-|---------|--------|-------| |
| 291 | | `blob0` (leaf, `defpackage/rvd.java`) | `O=CarService` | `O=Google Automotive Link` | 2014-07-04 → **2026-12-09** | |
| 292 | | `blob1` (root CA, `rve.java`/`rth.java`) | `O=Google Automotive Link` | self | 2014-06-06 → 2044-06-05 | |
| 293 | |
| 294 | The root is loaded into an in-memory keystore under alias `GAL` and is the *only* |
| 295 | trust anchor — the system trust store is not used. |
| 296 | |
| 297 | The leaf's **private key is present in the APK, encrypted**, and is recoverable. |
| 298 | `rth.java` (and an identical duplicate in `jca.java`): |
| 299 | |
| 300 | 1. `state = new byte[48]` (zeroed) |
| 301 | 2. `roc.aQ(leafCertPem.getBytes(UTF_8), state, salt)` |
| 302 | 3. `roc.aQ(rootCertPem.getBytes(UTF_8), state, salt)` |
| 303 | 4. 7 further rounds of `roc.aQ(state, state, salt)` |
| 304 | 5. AES-256 key = `state[0..32]`, IV = `state[32..48]` |
| 305 | 6. `AES/CBC/PKCS5Padding` decrypt → a PEM private key |
| 306 | |
| 307 | `roc.n()` then strips exactly 28 bytes of header and 26 of footer before |
| 308 | base64-decoding into a `PKCS8EncodedKeySpec`, which pins the plaintext to |
| 309 | `-----BEGIN PRIVATE KEY-----\n` + wrapped base64 + `-----END PRIVATE KEY-----\n`. |
| 310 | That is 1704 bytes, padding to the 1712-byte ciphertext exactly. |
| 311 | |
| 312 | `rvd` maps the accessors onto `rvg`'s static arrays **crosswise**, which is easy to |
| 313 | misread: `b()` returns `rvg.c` (the 1712-byte ciphertext) and `c()` returns `rvg.b` |
| 314 | (the 256-byte salt, of which only the first 48 bytes are ever indexed). |
| 315 | |
| 316 | `roc.aQ` itself, from the bytecode: |
| 317 | |
| 318 | ``` |
| 319 | for (v1 = 0; v1 < data.length; v1++) |
| 320 | for (v2 = 0; v2 < 48; v2++) |
| 321 | state[v2] = (byte)((((state[v2]&255)>>7 | (state[v2]&255)*2) + 33) |
| 322 | ^ salt[v2 % salt.length] ^ data[v1]); |
| 323 | ``` |
| 324 | |
| 325 | **jadx renders the outer loop as `for (byte b2 : bArr)`, which caches `data[v1]` |
| 326 | once per outer iteration. The real bytecode does `aget-byte v4, v6, v1` *inside* |
| 327 | the inner loop and re-reads it 48 times.** That is equivalent for the two cert |
| 328 | passes but not for the 7 fold rounds, where `data` and `state` are the same array |
| 329 | and the inner loop overwrites the byte being read. Porting jadx's Java verbatim |
| 330 | produces a plausible-looking but wrong key — `analysis/maauto/disasm.py` dumps the |
| 331 | bytecode that settles it. |
| 332 | |
| 333 | So the key material is whitened with a KDF whose entire input is also in the APK. |
| 334 | No hardware keystore, no server provisioning. |
| 335 | |
| 336 | `analysis/maauto/extract_key.py` recovers it; `verify_tls.sh` confirms the result: |
| 337 | |
| 338 | ``` |
| 339 | gal-client-cert.pem: OK (chains to the GAL root) |
| 340 | key modulus == cert modulus |
| 341 | New, TLSv1.2, Cipher is ECDHE-RSA-AES256-GCM-SHA384 |
| 342 | Verify return code: 0 (ok) (mutual auth, GAL root as sole anchor) |
| 343 | ``` |
| 344 | |
| 345 | Recovered material is in `analysis/maauto/certs/` (gitignored): |
| 346 | `gal-client-cert.pem`, `gal-client-key.pem`, `gal-root.pem`. |
| 347 | |
| 348 | ### A remotely-provisioned path also exists |
| 349 | |
| 350 | `rvg`'s constructor reads six phenotype flags (`adbo.gu()` `a`–`f`): a cert PEM, an |
| 351 | encrypted key blob and a salt, each paired with a SHA-1 checksum. If all three |
| 352 | validate it builds `rvf` from them instead of the hardcoded `rvd`. So Google can |
| 353 | rotate the credential remotely without shipping an APK — which is presumably how |
| 354 | they intend to handle the December expiry. Worth watching: if the phenotype cert |
| 355 | becomes mandatory, the hardcoded one may stop being accepted by head units. |
| 356 | |
| 357 | ### Consequences |
| 358 | |
| 359 | - A third-party **head unit** can authenticate to a real phone by reusing this |
| 360 | GAL-signed cert+key as its client cert. This is exactly how openauto/aasdk work. |
| 361 | - A third-party **phone-side sender** can authenticate to a real car for the same |
| 362 | reason — the car trusts the GAL root and this leaf chains to it. |
| 363 | - **The leaf expires 2026-12-09, ~3 months from now.** Google will rotate it in a |
| 364 | gearhead update. We cannot mint a replacement (no root key), so anything built on |
| 365 | this cert has a hard expiry and would need re-extraction from each new gearhead |
| 366 | release. This is the single biggest risk to any MA Auto that talks to real hardware. |
| 367 | |
| 368 | --- |
| 369 | |
| 370 | ## 4. Protobuf definitions are mechanically recoverable |
| 371 | |
| 372 | Every `x*` class is protobuf-lite gencode with an intact `RawMessageInfo` descriptor in |
| 373 | its `dynamicMethod`, e.g. `defpackage/xhf.java`: |
| 374 | |
| 375 | ```java |
| 376 | return new abpg(a, |
| 377 | "\u0001\u0003\u0000\u0001\u0001\u0003\u0003\u0000\u0000\u0003\u0001ᔋ\u0000\u0002ᔋ\u0001\u0003ᔋ\u0002", |
| 378 | new Object[]{"b", "c", "d", "e"}); |
| 379 | ``` |
| 380 | |
| 381 | The header is ten 13-bit-continuation varints over `char`s: `flags, fieldCount, |
| 382 | oneofCount, hasBitsCount, minFieldNumber, maxFieldNumber, numEntries, mapFieldCount, |
| 383 | repeatedFieldCount, checkInitializedCount`. Each field entry is `fieldNumber`, |
| 384 | `typeAndFlags`, and a `hasBitIndex` for singular fields with presence. In |
| 385 | `typeAndFlags`: `& 0xFF` is the field type ordinal, `0x100` required, `0x200` |
| 386 | enforce-UTF8, `0x400` participates in `checkInitialized`, `0x800` legacy closed enum, |
| 387 | `0x1000` the field has a hasbit. The decoder is `abpe.c()`. |
| 388 | |
| 389 | Worked example — `xhf` decodes to: |
| 390 | |
| 391 | ```proto |
| 392 | message AudioConfiguration { |
| 393 | required uint32 sampling_rate = 1; |
| 394 | required uint32 number_of_bits = 2; |
| 395 | required uint32 number_of_channels = 3; |
| 396 | } |
| 397 | ``` |
| 398 | |
| 399 | **Structure is 100% recoverable; names are not.** Field numbers, wire types, cardinality, |
| 400 | required/optional and packedness are exact. Message and field names are obfuscated |
| 401 | (`xoa`, `c`). Names come from three places: the `rta.a()` and `rvb.j()` debug dumpers, |
| 402 | log format strings, and the public aasdk/openauto `.proto` files, whose field numbers |
| 403 | match what is in this APK. |
| 404 | |
| 405 | `analysis/maauto/dump_protos.py` decodes any class on demand: |
| 406 | |
| 407 | ``` |
| 408 | $ python3 dump_protos.py xhf |
| 409 | message xhf { |
| 410 | required uint32 field1 = 1; // checkInit |
| 411 | required uint32 field2 = 2; // checkInit |
| 412 | required uint32 field3 = 3; // checkInit |
| 413 | } |
| 414 | ``` |
| 415 | |
| 416 | Validated three ways: `xhf` reproduces the known `AudioConfiguration` shape, `xnz` yields |
| 417 | exactly the 9 `checkInit` fields its own header declares, and `xob` reproduces the service |
| 418 | table derived independently from the `rta.a()` dumper. |
| 419 | |
| 420 | ### Two more traps in the descriptor path |
| 421 | |
| 422 | - **`abpe.java:501` is inverted.** jadx renders it as `if ((iCharAt10 & 4096) != 0 || i87 > |
| 423 | 17)` for the *no hasbit* case, i.e. it reads `0x1000` as meaning the field has none. It |
| 424 | is the other way round. `xhf`'s fields are `0x150B` = hasbit | checkInit | required | |
| 425 | UINT32 and each is followed by a hasbit index. |
| 426 | - **Java escapes in the descriptor string.** The descriptor is a UTF-16 string full of |
| 427 | small code points, so field number 8 is written `\b`, 12 is `\f` and 13 is `\r`. An |
| 428 | unescaper that only handles `\uXXXX` and `\n` leaves those as a literal backslash plus a |
| 429 | letter and silently shifts every later field by one — which is what made `xnz` decode |
| 430 | correctly through field 7 and turn to noise afterwards. Chained `str.replace` calls are |
| 431 | also wrong here regardless of order, because the descriptors genuinely contain |
| 432 | backslashes; the unescaper has to be a single left-to-right scan. |
| 433 | |
| 434 | ## 5. Native code |
| 435 | |
| 436 | The arm64 split contains **no protocol or codec native library** — only |
| 437 | `libgmm-jni.so` (maps), `libhwrword.so` (handwriting), `libresampling_jni.so`, |
| 438 | and generic Google infra libs. Video/audio go through platform `MediaCodec`; |
| 439 | TLS through Conscrypt. Nothing to port. |
| 440 | |
| 441 | --- |
| 442 | |
| 443 | ## 6. Components |
| 444 | |
| 445 | 56 activities, 87 services, 42 receivers, 11 providers. Exported entry points that |
| 446 | matter: |
| 447 | |
| 448 | - `carservice.service.impl.GearheadCarStartupService` — `com.google.android.gms.car.CAR_STARTUP_NOTIFICATION` |
| 449 | - `carservice.gmscorecompat.CarChimeraService` — `com.google.android.gms.car.service.START` |
| 450 | - `carservice.gmscorecompat.CarSetupServiceImpl` — `com.google.android.gms.car.CAR_SETUP_SERVICE` |
| 451 | - `carservice.companion.CarProcessCompanionDeviceService` — CDM automotive profile |
| 452 | - `apps.auto.wireless.setup.service.impl.WirelessSetupSharedService` — wireless AA bring-up |
| 453 | - `components.telecom.service.CarProjectionInCallServiceImpl` — `InCallService` for projected calls |
| 454 | - `notifications.SharedNotificationListenerManager$ListenerService` — `NotificationListenerService` |
| 455 | - `service.CarSystemUiControllerService`, `appdecor.AppDecorService` — projected window decor |
| 456 | |
| 457 | Transports: USB (AOAP, `CarUsbReceiver` / `CarUsbReceiverTPlus`, action |
| 458 | `com.google.android.gms.car.usb.USB_ACCESSORY_FORCE_START`) and wireless |
| 459 | (`com.google.android.gms.car.wifi.BT_START` → RFCOMM handshake → TCP socket). |
| 460 | |
| 461 | --- |
| 462 | |
| 463 | ## 7. Scope |
| 464 | |
| 465 | Decided: **sender side** — MA Auto replaces gearhead on the phone and projects to a |
| 466 | real head unit. Holds `SYSTEM_AUTOMOTIVE_PROJECTION`. Testing against an emulated |
| 467 | head unit on a second device (no real car available yet). Ships the extracted |
| 468 | credential, accepting the 2026-12-09 expiry. |