ZaStoGram/TMessagesProj/jni/zsg_naive
Repository files (latest commit first)
Filename Latest commit message Latest commit date
loop-uh 32ea6ab145
Some checks failed
Build three ZaStoGram APKs / build (arm64-v8a, ZaStoGram-standalone-arm64-v8a, Arm64, arm64) (push) Failing after 42s
Build three ZaStoGram APKs / build (armeabi-v7a, ZaStoGram-standalone-armeabi-v7a, Armv7, armv7) (push) Failing after 43s
ZaStoGram source guards / guards (push) Failing after 27s
Build three ZaStoGram APKs / build (x86, ZaStoGram-standalone-x86, X86, x86) (push) Failing after 40s
WARP: endpoint scanner on Android (core f84e911): starts after 3 s of silence, remembers the last working edges, 'Scan Cloudflare endpoints' row with progress; no account re-registration while a scan runs
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-28 17:22:53 -05:00
..
core@f84e91110d WARP: endpoint scanner on Android (core f84e911): starts after 3 s of silence, remembers the last working edges, 'Scan Cloudflare endpoints' row with progress; no account re-registration while a scan runs 2026-11-28 17:22:53 -05:00
test WSS: Cloudflare fronts send the zone as TLS server name, plain ws:// step, self-updating front list 2026-11-27 12:41:26 -05:00
tests WSS: Cloudflare fronts send the zone as TLS server name, plain ws:// step, self-updating front list 2026-11-27 12:41:26 -05:00
third_party zsg_naive: naive-core (private) and BoringSSL ea9f3a34 as git submodules 2026-11-24 15:49:50 -05:00
NaiveSocket.cpp WSS: replace the hand-made OpenSSL TLS/upgrade/frame code with the Chrome 158 WebSocket client (libzsgnaive); shared trust roots; guards updated; nested build always runs 2026-11-24 15:49:35 -05:00
NaiveSocket.h zsg_naive: wire the Naive proxy type (Java settings/UI, MtProxyOptions flag, ConnectionSocket hook, CMake nested build, hook guard test) 2026-11-24 15:49:34 -05:00
README.md WSS: Cloudflare fronts send the zone as TLS server name, plain ws:// step, self-updating front list 2026-11-27 12:41:26 -05:00
TrustRoots.cpp WSS: replace the hand-made OpenSSL TLS/upgrade/frame code with the Chrome 158 WebSocket client (libzsgnaive); shared trust roots; guards updated; nested build always runs 2026-11-24 15:49:35 -05:00
TrustRoots.h WSS: replace the hand-made OpenSSL TLS/upgrade/frame code with the Chrome 158 WebSocket client (libzsgnaive); shared trust roots; guards updated; nested build always runs 2026-11-24 15:49:35 -05:00
WarpEntry.cpp WARP: endpoint scanner on Android (core f84e911): starts after 3 s of silence, remembers the last working edges, 'Scan Cloudflare endpoints' row with progress; no account re-registration while a scan runs 2026-11-28 17:22:53 -05:00
WarpEntry.h WARP entry hop (opt-in): native WireGuard+lwIP engine from naive-core (848f94c), loopback forward ports for tgnet/WSS/Naive/pool first hops, settings row, account registration 2026-11-27 15:02:26 -05:00
WebProxy.cpp Naive: route WebViews (mini apps, in-app browser) through the selected Naive proxy via a loopback CONNECT proxy + ProxyController (fail closed) 2026-11-24 16:56:14 -05:00
WebProxy.h Naive: route WebViews (mini apps, in-app browser) through the selected Naive proxy via a loopback CONNECT proxy + ProxyController (fail closed) 2026-11-24 16:56:14 -05:00
WebProxyJni.cpp WARP entry hop (opt-in): native WireGuard+lwIP engine from naive-core (848f94c), loopback forward ports for tgnet/WSS/Naive/pool first hops, settings row, account registration 2026-11-27 15:02:26 -05:00
WebProxyJni.h Naive: route WebViews (mini apps, in-app browser) through the selected Naive proxy via a loopback CONNECT proxy + ProxyController (fail closed) 2026-11-24 16:56:14 -05:00
zsg_naive.cmake WARP entry hop (opt-in): native WireGuard+lwIP engine from naive-core (848f94c), loopback forward ports for tgnet/WSS/Naive/pool first hops, settings row, account registration 2026-11-27 15:02:26 -05:00

zsg_naive — Naive transport for ZaStoGram Android

Fork-only module. Everything lives in this folder so that merging upstream Telegram never conflicts with it.

What it covers

  1. Naive proxy (NaiveSocket): a NaiveProxy-compatible server entry in the proxy list (ProxySettings.Type.NAIVE).
  2. WSS (tgnet/wss/WssSocket.cpp): the WebSocket relay transport. Its old hand-made TLS / HTTP-upgrade / frame code was deleted and replaced by the same library (zsg_ws_*), so both transports show the same Chrome 158 handshake. Route selection and health tracking in that file are unchanged.

What it is

A NaiveProxy-compatible client that carries the DC connection through an HTTPS proxy and looks like Chrome 158 on the wire. The protocol work (TLS handshake, HTTP/2, preamble, CONNECT, padding) is the separate sans-I/O library naive-core (libzsgnaive.so, own BoringSSL at Chromium 158's revision). NaiveSocket adapts it to tgnet's transport::Socket interface (the same seam WSS uses).

Hook lines outside this folder (a merge must keep every one — zsg_naive/tests/check_hooks.py verifies them)

  1. jni/CMakeLists.txt: include(zsg_naive/zsg_naive.cmake) and zsg_naive_socket in tgnet's link libraries.
  2. jni/tgnet/ConnectionSocket.cpp: #include "../zsg_naive/NaiveSocket.h"; the useNaive block after OfficialRoute(...); the useNaive ? tgnet::naive::CreateFor(...) : tgnet::wss::CreateSocket(...) creation; the "naive" guard on the pooled-socket lookup. 2b. jni/tgnet/Connection.cpp: in Connection::connect, a Naive route forces ipv6 = 0 (the server's egress family is unknown; an IPv4-only server cannot reach Telegram's IPv6 addresses). 2c. java/.../tgnet/ConnectionsManager.java: one line after native_init in init, org.telegram.zastogram.wss.WssFrontsUpdater.start(configPath) (keeps the WSS Cloudflare front list wss_fronts.txt current; the class lives in zastogram/wss/, the reader in tgnet/wss/WssSocket.cpp).
  3. jni/mtproxy/MtProxyOptions.h (+ jni/TgNetWrapper.cpp, tgnet/MtProxyOptions.java): the naive flag.
  4. Java: ProxySettings.Type.NAIVE and its handling in ConnectionsManager.setProxySettings; ProxyWssFallback.isAllowed() excludes NAIVE (a Naive entry fails closed, never falls back to a direct WSS route).

WebViews (mini apps, in-app browser)

WebProxy.cpp is a loopback HTTP proxy (127.0.0.1, random port) that accepts only CONNECT and tunnels it through the selected Naive server over ONE shared Naive connection; org.telegram.zastogram.naive.NaiveWebProxy starts it and points every WebView of the process at it with androidx.webkit ProxyController (no direct rule: fail closed). It runs while a Naive entry is selected, or while the setting "Mini apps through Naive" (SharedConfig.naiveWebAppsEnabled, a row in the proxy list screen) is on and the proxy list holds a Naive entry (the first valid one is used). Limits: plain http is refused; any local app can reach the loopback port (ProxyController cannot send credentials); a WebView without PROXY_OVERRIDE support stays direct (logged). Hooks: ConnectionsManager.java (NaiveWebProxy.apply(...) in setProxySettings and in the startup restore) and TgNetWrapper.cpp (RegisterWebProxyJni).

Tests

  • test/build_webproxy_host_test.sh + webproxy_host_test.cpp — the REAL WebProxy.cpp against a real Caddy + forwardproxy: one tunnel, 8 concurrent tunnels over one Naive connection, plain http refused, dead target.
  • tests/check_hooks.py — the hook lines above are all present.
  • test/naive_socket_host_test.cpp — NaiveSocket through an epoll loop against a real Caddy + forwardproxy@naive.
  • test/build_wss_host_test.sh + wss_socket_host_test.cpp — the REAL WssSocket.cpp (stub logger, lab trust root) against a TLS WebSocket echo server, including the "first frame is at least 64 bytes" rule and fail-closed certificate checking. The lab servers and captures live in ~/zastogram/naive-ref-lab.

Sources needed to build (git submodules)

  • core/ — naive-core, the sans-I/O protocol library (private repo zastogram/naive-core). It is a private submodule on purpose: clone access needs a Forgejo account with access to that repo, so a plain public clone (and the push-triggered Actions build) cannot fetch it. Local release builds work because the build host has the access.
  • third_party/boringssl/ — BoringSSL ea9f3a34c3977144c45d272be81842fd891a0bdb (Chromium 158.0.8127.88), public. Separate from the app's own older jni/third_party/boringssl, which stays untouched. After a fresh clone: git submodule update --init TMessagesProj/jni/zsg_naive/core TMessagesProj/jni/zsg_naive/third_party/boringssl.