Mobile Development 14 min read

YouZan Mobile Testing Environment Switching Solution: VpnService + ZanProxy Implementation

YouZan’s Mobile Assistant combines Android VpnService (or iOS NetworkExtension) with the open‑source ZanProxy, using tun2socks‑based SOCKS5 tunneling, UUID‑based user isolation, and an ACL‑driven fake‑DNS scheme to replace complex Charles/hosts setups with a single‑click, certificate‑only, PC‑free environment‑switching solution supporting TCP, UDP, and WebSocket traffic.

Youzan Coder
Youzan Coder
Youzan Coder
YouZan Mobile Testing Environment Switching Solution: VpnService + ZanProxy Implementation

This article introduces YouZan's solution for one-click switching of testing environments in mobile app development. The original workflow required complex setup including Charles proxy, Hosts configuration, gateway settings, Wi-Fi proxy configuration, and certificate installation, creating high learning curves for product and operations teams.

The solution combines Android VpnService (or iOS NetworkExtension) with ZanProxy, an open-source Node.js HTTP proxy server. Key technical implementations include:

1. Network Layer Processing: Using badvpn's tun2socks to convert L3 IP packets into SOCKS5 protocol. The IP packet structure contains IP Header and payload (TCP/UDP data), allowing protocol parsing at L3 and L4 layers.

2. SOCKS5 Proxy: Unlike HTTP proxies, SOCKS5 operates at the application layer and can forward any protocol by treating data as raw bytes, supporting both TCP and UDP traffic including custom protocols like IM sockets.

3. Multi-User Management: Using device UUID as username in SOCKS authentication to identify different users and apply different proxy rules.

4. ACL Implementation: Custom DNS server returns fake IPs (198.18.0.0/16) for domains needing proxy, while other traffic connects directly. This reduces server load significantly.

5. DNS Considerations: Both UDP and TCP DNS servers must be implemented since DNS responses over 512 bytes automatically switch to TCP.

The final solution provides a standalone internal app "YouZan Mobile Assistant" with features: one-click environment switching, PC-independent operation, no Wi-Fi proxy configuration needed, single certificate installation, support for packet capture and mocking, no intrusion to business app code, and support for IM socket/WebSocket forwarding.

Mobile DevelopmentDNSTesting EnvironmentNetwork ProgrammingACLAndroid VpnServiceSOCKS5 proxyVPN proxyZanProxy
Youzan Coder
Written by

Youzan Coder

Official Youzan tech channel, delivering technical insights and occasional daily updates from the Youzan tech team.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.