Skip to content

The engine's HTTPS: the unit's own libssl, home Wi-Fi only - #422

Open
AwsomeFox wants to merge 9 commits into
wifi/home-routingfrom
engine/https
Open

AwsomeFox wants to merge 9 commits into
wifi/home-routingfrom
engine/https

Conversation

@AwsomeFox

@AwsomeFox AwsomeFox commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Stack: 3 of 5, on #420. Foundation for the catalogue (#423): nothing calls it yet.

Why

The engine needs HTTPS to GitHub for the catalogue and updates. Android 4.4's Java TLS shares no cipher suite with GitHub, and under app_process its MessageDigest SHA-256 can be missing (Conscrypt's class didn't load in a mod's service on the car).

What

  • core/fetch/fetch.c → /data/hmgapi/lib/libhmgapi_fetch.so. Built like the loader: no libc, dlopen/dlsym only, against the syslib stubs. Installed into /data by install.sh (nothing new on /system, nothing for the uninstaller to restore). It makes one TLS 1.2 request through the unit's own libssl.so (OpenSSL 1.0.1, ECDHE + AES-GCM) and writes the raw answer to a file with a cap. The socket gets SO_MARK 0x2951, so its route is table 95: Home Wi-Fi, or unreachable (Home Wi-Fi: mods' connections and their services' lookups get through #420), never mobile data.
  • The certificate isn't checked. The unit's 2013 root store doesn't know GitHub's roots and its clock starts at 2015. Downloads are trusted only through the SHA-256 in the catalogue (or a release's SHA256SUMS) and then the package signature (Catalogue, dependencies and updates in the engine #423). A hostile network can make a check fail; it can't get code installed.
  • NativeFetch (plus NativeFetch.Web: files standing in for GitHub off the car).
  • Http: https only, GitHub's hosts only (github.com, api.github.com, raw./objects./release-assets.githubusercontent.com, codeload), redirects only between them, Content-Length and chunked, a size cap, .part then rename.
  • DnsLookup: an A query straight to dhcp.wlan0.dns1, since the engine runs outside netd's per-app setup.
  • Sha256: plain Java.

Tested

  • fetch-test.sh (15 checks): redirects, a refused host, the cap, 404, no connection, SHA-256 against the JDK's, the DNS reader.
  • ./build.sh fetchlib: it imports only dlopen/dlsym.
  • The same C ran on an Ioniq 5 US 260507 (rc.10) inside a test mod: it fetched catalogue entries and three packages from GitHub with matching SHA-256s. The DNS and mark parts came out of that run.
  • The host build fetched the real catalogue from a computer.

Review follow-ups (Nov 30)

  • The installer fix (copy the HTTPS library before the /system changes) is here now, with the library (moved from App: Get mods and Updates in the Mods tab #424).
  • NativeFetch.fetch() and dns() are synchronized on one lock: the unit's OpenSSL 1.0.1 has no locking callbacks, so no two calls run at once. fetch.c's comment says calls are serialized.

🤖 Generated with Claude Code

For the catalogue and updates (next). Android 4.4's Java TLS shares no cipher suite with GitHub,
and its MessageDigest SHA-256 can be missing under app_process, so:

- core/fetch/fetch.c -> /data/hmgapi/lib/libhmgapi_fetch.so (built like the loader: no libc,
  dlopen/dlsym only; installed into /data, nothing new on /system). One TLS 1.2 request through
  the unit's libssl.so; the socket carries home Wi-Fi's mark (SO_MARK 0x2951), so it leaves on
  home Wi-Fi or not at all. The certificate isn't checked (the unit's 2013 roots and its clock
  can't be relied on): what's downloaded is trusted only through a SHA-256 and a signature.
- NativeFetch (with NativeFetch.Web, files standing in for GitHub off the car), Http (https,
  GitHub's hosts only, redirects between them, a size cap), DnsLookup (home Wi-Fi's DNS server,
  asked directly), Sha256 (plain Java).
- fetch-test.sh. The same C, built for a computer, fetched catalogue entries and packages from
  GitHub; first run on an Ioniq 5 US 260507 as a mod.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AwsomeFox and others added 4 commits November 26, 2026 10:36
…s libc headers)

The few JNI pieces it uses are declared at their places in the standard table, checked at
compile time; the library is byte-for-byte the same. CI's Linux headers failed for the ARM target.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fetch.c: every socket gets 20 s send and receive timeouts (connect, the
handshake, each read and write), home Wi-Fi's mark and SO_BINDTODEVICE
wlan0, or the call fails (E_ROUTE): no unmarked socket on the main
table, even before the fwmark rule is in. setsockopt is required. The
DNS query goes out through the library too (NativeFetch.dns, UDP, the
same socket setup), and the connection only goes to an address
(AI_NUMERICHOST: never the system resolver). An answer ends whole only
on the server's TLS close; a drop, read error or timeout is E_CUT with
what came kept. No static buffer (malloc'd per call); the answer file is
opened O_EXCL | O_NOFOLLOW.

DnsLookup takes the server from wifi.sh's lease (there only while home
Wi-Fi's route is up) instead of dhcp.wlan0.dns1, and asks through an
Asker (the library's socket) instead of an unmarked DatagramSocket.

Http: one answer file per call (NativeFetch.fresh); a cut answer counts
only if its Content-Length is met or its last chunk read; headers cut
off are an error; chunk sizes are hex digits only, at most 7 (a
negative size passed the cap), each chunk must end in CRLF; a body that
fails for any reason leaves no .part. Content-Length must be a number
and within the cap.

Tests: NativeFetch.Web honours maxBytes and O_EXCL, and serves chunked,
no-length, raw and cut answers; FetchTest adds cap, chunked, cut,
redirect, lease and eight-threads cases. fetch-test.sh builds the
library for the computer (-DHOST) and runs it against a local TLS
server: a TLS close, a drop, a quiet server (timeouts), the cap, O_EXCL
and O_NOFOLLOW, and the DNS exchange. libhmgapi_fetch.so is in
install-test.sh's and zygote-orders.py's MANIFESTs, and install-test
checks it lands in /data/hmgapi/lib, 644, nothing on /system.

Tested off-car only (fetch-test.sh with Homebrew OpenSSL 3 on macOS,
install-test.sh, orders-test.sh; ./build.sh fetchlib links with only
dlopen and dlsym undefined). Not yet run on a car.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AwsomeFox
AwsomeFox marked this pull request as ready for review November 28, 2026 15:50
@AwsomeFox
AwsomeFox requested review from a team and VysseCodes as code owners November 28, 2026 15:50
@isaacwisdom
isaacwisdom added this pull request to stack #443 November 28, 2026 17:44
isaacwisdom
isaacwisdom previously approved these changes Nov 28, 2026

@isaacwisdom isaacwisdom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found.

@VysseCodes VysseCodes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things before merging:

  1. Installer fix: the commit that copies the HTTPS library before the /system changes landed in #424, but it belongs here, with the library. Please move it into this PR.
  2. Thread safety: OpenSSL 1.0.1 isn't thread-safe without locking callbacks, and fetch.c's comment says calls may come from several threads. Nothing calls it from two threads today, but please add a lock (e.g. synchronize fetch()/dns() in NativeFetch) so later parallel use is safe, and fix the comment to say calls are serialized.

Merge order: after #420, before #423.

AwsomeFox and others added 3 commits November 30, 2026 16:39
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It went into /data after the wrapper and boot hook were written, so a
failure there stopped the install with the maps, the app and the records
after it skipped. It's now kept right after the backups, before
remount rw, and a failure says nothing on /system was changed. Test: a
file where its folder goes: refused, /system unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 34b9624)
…llbacks)

NativeFetch.fetch and dns are synchronized on one lock, so later parallel use can't run two
OpenSSL calls at once; fetch.c's comment now says calls are serialized (review). The installer
fix that keeps this library before /system changes moved here from #424 (cherry-picked).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AwsomeFox added a commit that referenced this pull request Nov 30, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AwsomeFox

Copy link
Copy Markdown
Contributor Author

Both done:

  1. The installer fix is here now (d817b23, cherry-picked from App: Get mods and Updates in the Mods tab #424; App: Get mods and Updates in the Mods tab #424 no longer changes install/).
  2. NativeFetch.fetch() and dns() are synchronized on one lock, and fetch.c's comment says calls are serialized (5053a7f). The HTTPS tests pass.

The only conflict was tools/test-all.sh: this branch's fetch-test.sh and
release/2.0's core/client/test.sh both go in ALL and FAST.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants