Skip to content

Latest commit

 

History

History
393 lines (269 loc) · 23.7 KB

README_EN.md

File metadata and controls

393 lines (269 loc) · 23.7 KB
TgWsProxy application icon

TgWsProxy Android

A local Telegram proxy for Android with MTProto and SOCKS5 frontends and routing through Cloudflare Proxy, direct WebSocket, Cloudflare Worker, userspace AWG/WARP, or TCP.

Release CI Platform License

Русский · English

🌐 Project website · Русская версия

Quick start · Documentation · Releases · Feedback


Telegram Worker (v1.11.2): choose between HTTPS Chunk Relay (existing default) and Flowseal Legacy WebSocket (/apiws) per Worker. Legacy WebSocket is experimental: some networks restrict long-lived Cloudflare WebSocket connections, so Telegram may not connect and messages or media may fail to load. A successful WebSocket upgrade does not verify MTProto on Android. Existing Worker configurations stay on Chunk Relay unless explicitly changed. See Cloudflare Worker setup.

About

TgWsProxy runs a local proxy on an Android device. Telegram connects through the MTProto Proxy frontend or the compatible SOCKS5 mode, and the native runtime selects an allowed route to Telegram infrastructure.

The primary use case remains MTProto Proxy → Cloudflare Proxy on 127.0.0.1:1443. Version 1.11.0 additionally introduces the optional userspace awg_warp route over AmneziaWG/WARP. The application does not create a system VPN tunnel or route all device traffic.

Project status

Latest published release: GitHub Releases
Source version: 1.11.10 (versionCode 66) — candidate notes. Source status: v1.11.10 is not published; v1.11.9 is the latest published stable release. Flowseal Legacy Worker remains experimental.

Android application ID: io.github.regstar2.tgwsproxy. The app installs alongside the original com.amurcanov.tgwsproxy package; settings and data are not migrated automatically. Both local proxies cannot listen on the same port simultaneously.

Area Status
MTProto Proxy over cf_proxy_ws Primary use case; manually verified on mobile data and Wi-Fi
awg_warp Userspace AWG/WARP without VpnService; automatic provisioning, profile management, and MTProto-aware validation are implemented
SOCKS5 / WebSocket frontend Implemented as a compatibility mode
direct_ws and tcp_fallback Implemented; availability depends on the network
Cloudflare Worker Optional Telegram route; Consumer WARP provisioning uses a separately managed bootstrap Worker pool
Worker Pool Implemented but still slower than direct connectivity and not recommended as the primary route
Feedback Dedicated screen; GitHub Issue Forms without an embedded PAT
Updates GitHub Releases check, optional startup prompt, verified APK download and Android installer handoff. The main path was tested on Xiaomi; extended #139 acceptance remains open

Features

  • local MTProto Proxy with t.me/proxy and tg://proxy link generation;
  • compatible SOCKS5 frontend on the same configurable port;
  • cf_proxy_ws, direct_ws, cf_worker_ws, awg_warp, and tcp_fallback routes;
  • in-app WARP/AWG profile management: automatic Consumer WARP provisioning, .conf import, name/config editing, selection, validation, and deletion;
  • separate custom/built-in bootstrap Workers for Consumer WARP profile creation; they are not added to the Telegram cf_worker_ws Worker Pool and the built-in pool can be fully disabled;
  • userspace AmneziaWG/WARP routing without root, Android VpnService, or a system TUN interface;
  • separate route policies for Wi-Fi, mobile data, and unknown networks;
  • Fake TLS secrets in dd<secret> and ee<secret><domain_hex> formats;
  • optional probe passthrough to a configured masking domain;
  • foreground service, status notification, local listener watchdog, and optional proxy autostart after Android boot;
  • route diagnostics, runtime status, report export, and configurable logging;
  • dedicated Feedback and Updates screens;
  • English and Russian UI.

Screenshots

TgWsProxy main screen with local proxy status TgWsProxy settings overview Local connection settings
Cloudflare Proxy and Worker settings Application behavior and appearance settings Logging and diagnostics settings

Quick start

  1. Install a compatible ARMv7, ARM64 or Universal APK from GitHub Releases when the required version is available, or build a debug APK.
  2. Open TgWsProxy.
  3. Keep MTProto Proxy as the frontend and port 1443 unless another local service already uses it.
  4. Tap Start proxy.
  5. Tap Apply in Telegram and confirm the configuration in Telegram.

When Telegram cannot connect, open the built-in diagnostics and test the selected route separately.

Requirements

For use

  • Android 8.0 or newer (minSdk 26);
  • an armeabi-v7a (ARMv7) or arm64-v8a (ARM64) device;
  • Telegram installed;
  • a network where at least one allowed route is available.

For building

Windows: PowerShell, JDK 17, Android SDK/NDK, Go, Python 3, and the repository Gradle Wrapper.

Android/Termux: an ARM64 device, JDK 17, Go 1.25.0+, Python 3 + Pillow, Android SDK Platform 35 with ARM64/Bionic build-tools, and an NDK containing linux-aarch64 host tools. See the Termux build guide in docs/development/android-abis.md.

Desktop Linux and macOS builds are not claimed; Termux has a separate ARM64 build path.

Installation

Check GitHub Releases for an APK of the required version. Install a locally built debug APK through ADB:

adb install -r app\build\outputs\apk\debug\app-universal-debug.apk

Android may require uninstalling the existing application when switching between debug and release signatures. Note that uninstalling may remove local application settings.

In-app updates

Checking for a newer release is asynchronous and does not block the local proxy. When a compatible version exists, TgWsProxy may offer an optional startup prompt. Later postpones the prompt by 24 hours. Reminders can be disabled or re-enabled through Settings → Updates, which also provides manual refresh, release information and a GitHub release link.

Tapping Download and install in the startup prompt downloads the official APK matching Build.SUPPORTED_ABIS (compatible ABI-specific APK first, then Universal) without navigating to the Updates screen. Before installation, TgWsProxy verifies SHA-256, the APK signing certificate, package identity and an increased versionCode. If install-from-this-source permission is already granted, the Android system installer opens directly after verification and requires the user's confirmation. Otherwise the app opens Updates, then the Android Install unknown apps permission page scoped to TgWsProxy. Granting access continues with the same verified APK, without downloading again.

A progress/cancel notification is shown when notifications are permitted. Installation does not launch an activity while the app is in the background: return to TgWsProxy to continue. If Android kills the app process, an interrupted download does not automatically resume. On error, the official release page remains available; unverified APKs are never installed. Installing an update may interrupt running proxy connections and is never silent.

In-place updates require a matching applicationId and compatible signing identity. Legacy com.amurcanov.tgwsproxy installations are separate packages; their settings are not migrated automatically. See the acceptance checklist and limitations.

Usage

MTProto Proxy

  1. Select the MTProto Proxy frontend.
  2. Check the local address and port.
  3. Configure a masking domain when needed.
  4. Start the service and apply the configuration in Telegram.

Without a masking domain, the link uses a dd<32 hex chars> secret. With a configured domain, it uses ee<secret><domain_hex>.

To copy the configuration for another Telegram client on the same device, tap the copy icon next to the proxy address on the home screen. In MTProto mode, it copies an https://t.me/proxy link with the current host, port and secret, including the Fake TLS domain when configured. This is the same link produced by Settings → Connection → Copy link. Open it in a client that supports proxy links; Apply in Telegram still opens Telegram directly.

Do not publish the copied MTProto link: it contains the proxy secret. The local address 127.0.0.1 is accessible only from the device running TgWsProxy.

WARP / AmneziaWG

Under Settings → Cloudflare → WARP / AmneziaWG, you can create a Consumer WARP profile automatically or import an existing .conf. Automatically created profiles pass structural validation, bounded autotuning, and full-duplex network validation before they are persisted. At most one profile is selected at a time.

The awg_warp route is used only for connections that Telegram sends to the local proxy frontend. It does not create a system VPN or intercept traffic from other applications.

SOCKS5 compatibility mode

In SOCKS5 mode, the home-screen copy icon produces a link such as https://t.me/socks?server=127.0.0.1&port=1443, using the current application port. If the Telegram client does not handle this link, configure the connection manually:

Host: 127.0.0.1
Port: 1443
Username: empty
Password: empty

When the port is changed in the application, use the same value in Telegram. The SOCKS5 link does not contain an MTProto secret.

Operating modes

Local frontends

Frontend Purpose Limitation
MTProto Proxy Primary mode applied through an MTProto proxy link Uses the application's local port only
SOCKS5 / WebSocket Compatibility with Telegram's SOCKS5 configuration Copyable link, or manual host and port entry when the client does not support links

Routes

Route kind Purpose Limitation
cf_proxy_ws WebSocket through Cloudflare Proxy domains: kws{dc}.<domain>/apiws Availability depends on external domains and the network
direct_ws Direct WebSocket to kws{dc}.web.telegram.org May be blocked or unstable on some networks
cf_worker_ws Traffic through a Cloudflare Worker Requires separate Worker configuration
awg_warp Telegram TCP through a userspace AmneziaWG/WARP tunnel Requires a selected valid WARP/AWG profile; provisioning depends on the external Consumer WARP API
tcp_fallback Direct TCP to a Telegram data-center IP on port 443 This is not a WebSocket route

WebSocket is a transport. The interface and diagnostics identify the actual path with a separate route kind.

Configuration

Defaults for new or reset profiles starting with 1.11.7 (previously saved user policies are not replaced):

Setting Value
Local address 127.0.0.1
Local port 1443
Frontend MTProto Proxy
Mobile data cf_proxy_ws only, without fallback
Wi-Fi cf_proxy_ws only, no fallback
Unknown network cf_proxy_ws only, without fallback
Runtime log collection disabled
Persistent file logs disabled

awg_warp is not added to the default route policy automatically; the user explicitly configures and selects a WARP/AWG profile.

Migration retains saved Wi-Fi/mobile route permissions and, when possible, the previously preferred route. The ordered list persists both visible positions and the enabled chain. A previous no-fallback policy must not gain additional enabled routes. Save important settings before changing the configuration.

Warning

Enable masking-domain passthrough only for a trusted domain. The application will create real outbound connections to the configured host.

Architecture

Telegram
   │
   ▼
local MTProto Proxy or SOCKS5 frontend
   │
   ▼
Android ProxyService (foreground service)
   │
   ▼
Go runtime: libtgwsproxy.so
   │
   ├── cf_proxy_ws
   ├── direct_ws
   ├── cf_worker_ws
   ├── awg_warp
   └── tcp_fallback

The Android layer uses Kotlin and Jetpack Compose. The native runtime is located in native/tgwsproxy/, is built as libtgwsproxy.so, and connects to the Android application through a JNA/CGO bridge. awg_warp uses a userspace netstack plus amneziawg-go; no system TUN/VPN is created.

Detailed design: docs/architecture/architecture.md.

Security

Native TLS now validates the upstream CA chain and hostname (PR #167). In v1.11.10, CF Proxy defaults to WS/80 without TLS encryption or server authentication when no preference is saved. Turn off “CF Proxy without TLS” to use verified WSS/443. Explicitly saved choices are preserved. Android CA acceptance remains pending (#158).

  • MTProto secrets, query parameters, and sensitive addresses are masked in the interface, diagnostic reports, and logs where the implementation supports it.
  • The WARP/AWG private key is generated/stored locally in app-private storage and is not sent to the Consumer WARP API; only the public key and required registration metadata are sent externally.
  • Cloudflare Worker URLs, proxy secrets, keystores, and signing variables must not be published in issues, logs, or commits.
  • Release signing uses local environment variables; the keystore is excluded from Git.
  • Feedback does not automatically attach runtime logs, proxy credentials, Telegram data, IP addresses, or secrets.
  • In-app updates download only compatible official ARMv7, ARM64 or Universal release APKs and verify SHA-256, APK signer, package identity and version code before invoking Android's installer. The main upgrade to 1.11.7 (63) was confirmed on Xiaomi; remaining cases and constraints are recorded in the #139 acceptance checklist.
  • A masking domain changes the Fake TLS handshake shape but does not turn the application into a VPN.

Review every diagnostic report manually before publishing it.

Privacy

TgWsProxy processes connections that Telegram sends to the local proxy frontend. The application does not create a system VPN tunnel or intercept traffic from other applications.

Depending on the route policy, traffic goes directly to Telegram, through Cloudflare Proxy, through a Cloudflare Worker, or through the selected userspace AWG/WARP profile. Runtime collection and persistent file logging are disabled by default and must be enabled manually for diagnostics.

Troubleshooting

Built-in diagnostics show:

  • configured, selected, and actually active routes;
  • DNS, TCP, TLS, HTTP, and WebSocket probe results;
  • Cloudflare Proxy and Worker state;
  • WARP/AWG profile state, handshake, and support-safe tunnel/application counters;
  • Fake TLS statistics;
  • recent errors and fallback reasons;
  • an exportable diagnostic report.

The runtime uses the TgWsProxy logcat tag. Diagnostic probes should not change the active route policy.

Routes (available since v1.11.7)

Under Settings → Routes, Wi-Fi and mobile data have independent policies. All five routes appear in one reorderable list, including disabled routes. Enabling or disabling a route does not move its row. Arrows and drag gestures reorder both active and inactive entries; enabled routes are attempted in visible top-to-bottom order by the MTProto frontend. With one enabled route, there is no implicit fallback.

Policy changes save immediately and apply to new MTProto sessions without intentionally interrupting existing ones. New or reset profiles enable Cloudflare Proxy only; AWG/WARP and Worker require their respective configurations.

The status and notification report the last confirmed outbound MTProto backend, not merely the highest-priority requested route. For example, successful TCP → AWG fallback is shown as AWG. Traffic speed is calculated from live relayed byte counters. The notification's Last outbound connection setup value measures connection establishment time, not network ping/RTT. Periodic speeds are sampled and notification publications are throttled.

The older route-settings screenshot has been omitted while the v1.11.7 screen is being finalized. Device/release-APK acceptance is still required: Issue #135 acceptance.

Build

Current toolchain:

Component Version or value
Android Gradle Plugin 8.2.2
Gradle Wrapper 8.2.1
Kotlin 1.9.22
compileSdk / targetSdk 35 / 35
minSdk 26
ABI armeabi-v7a, arm64-v8a; Universal

Build a debug APK:

.\gradlew.bat assembleDebug

Gradle builds both native ABIs and generates icons through preBuild. Outputs include app-armeabi-v7a-debug.apk, app-arm64-v8a-debug.apk and Universal:

app\build\outputs\apk\debug\app-universal-debug.apk

Build directly on Android/Termux (ARM64):

bash scripts/build-termux.sh

The script builds ARMv7, ARM64 and Universal Debug APKs, audits their ELF payloads, and copies the APKs plus SHA-256 sidecars to artifacts/termux/. It does not use the release keystore and does not change the Windows workflow.

Build and copy the APK to the local artifacts/ directory:

.\scripts\build-apk.ps1 -Configuration Debug

For in-place device testing over an official installation, use the original release certificate in the local gitignored release-signing.env:

.\scripts\build-signed-worker-smoke.ps1 -Install

This is a release-signed Debug build (versionCode 66), not a public Release APK. Never uninstall to bypass a signature mismatch.

Build the final signed release only when the local keystore is configured:

.\scripts\release.ps1 -Version v1.11.10

The script verifies that the tag matches versionName, verifies the APK signature, and produces three APKs (ARMv7, ARM64, Universal) with separate SHA-256 files in dist/. All variants retain the same versionCode.

See ABI build and safe testing instructions and Issue #162 results.

Build the Go runtime separately:

.\scripts\build-native-android.ps1

Testing

Single project CI entry point:

.\scripts\ci.ps1

It covers Go module verification, native Go tests, Android unit tests, debug APK assembly, and packaged-resource auditing. The release-candidate source also runs the final release audit from CI.

Before publishing v1.11.10, verify signed APKs for all three variants, Android TLS CA roots and real WSS/Worker transport, in-place update from v1.11.9, notification reconnect and Telegram media. WS/80 is enabled by default for unset preferences and is plaintext and unauthenticated. GO/NO-GO.

Current checklist: docs/testing/README.md.

Documentation

Task Document
Architecture and data flow docs/architecture/architecture.md
Cloudflare Proxy domain pool docs/architecture/CF_DOMAIN_POOL.md
Cloudflare Worker setup docs/cloudflare-worker.md
Repository structure docs/development/repository-structure.md
Manual testing docs/testing/README.md
Release preparation docs/releases/release.md
1.11.10 candidate notes docs/releases/v1.11.10_EN.md · Russian
1.10.13 final audit docs/releases/v1.10.13-final-audit.md
Change history CHANGELOG.md

Credits

AI tools were used for selected parts of the code, tests, and documentation. The resulting changes are checked by tests and the release audit; manual device acceptance remains a required final step.

Android Quick Settings (v1.11.5)

Open Android's Quick Settings editor (Edit / pencil icon), find TgWsProxy and drag it into the panel. Tapping the tile starts or stops the local proxy service; it does not configure Telegram or provide a system-wide VPN.

As of v1.11.5, every tile start rebuilds the runtime from current saved settings and the active network. Changing Wi-Fi ↔ mobile data or the route no longer requires another in-app start when the new settings are valid. Initial setup still requires one successful in-app proxy start; invalid current settings are rejected without falling back to an old runtime. The tile shows “Connecting” during preparation and only becomes ACTIVE once the frontend is truly RUNNING. Duplicate taps while starting/reconnecting are ignored. Tile layout and update timing depend on Android/OEM SystemUI.

Limitations

  • ARMv7 and ARM64 are supported; production APKs do not include x86/x86_64;
  • the application is a Telegram proxy, not a system-wide VPN;
  • route availability depends on the network and external infrastructure;
  • Consumer WARP provisioning depends on an external API; a fresh install may require the Worker bootstrap when direct registration is unavailable;
  • awg_warp compatibility depends on the Android device, network, and WARP availability; the current release candidate requires a device smoke test before the stable tag;
  • Worker Pool remains slower than direct connectivity and is not intended for the primary use case;
  • port 1443 must be changed when another local service already uses it;
  • the native build script targets Windows; Linux and macOS support is not confirmed;
  • masking-domain passthrough creates connections to the configured domain;
  • an APK is not guaranteed to be available for every version in GitHub Releases.

License

The project is distributed under the GNU General Public License v3.0.