This document outlines the plan for implementing SoftEther VPN protocol in C language within the SoftEtherClient Android module.
Target Repository: https://github.com/SoftEtherVPN/SoftEtherVPN_Stable
Submodule: SoftEtherClient/ (points to https://github.com/hoang-rio/SoftEther-Android-Module.git)
Integration: Android VPN app with existing OpenVPN and SSTP support
- Analyze existing project structure and VPN implementation patterns
- Create comprehensive implementation plan for SoftEther VPN protocol
- Design Android instrumentation tests for JNI level testing
- Phase 1: Set up SoftEtherClient module structure and build system
- Phase 2: Implement C/C++ native code with JNI bridge
- Phase 3: Implement Kotlin/Java layer (VPN service, controller, client)
- Phase 4: Implement protocol-specific logic (handshake, auth, data tunnel)
- Phase 5: Integrate with main Android app
- Phase 6: Implement Android instrumentation tests for native code
- Phase 7: Testing and validation against vpngate.net servers
- Root cause analysis and protocol fixes
All core implementation phases are complete and stable:
- ✅ Protocol implementation with VPNGate HTTP POST steps
- ✅ JNI bridge and native libraries
- ✅ Kotlin/Java VPN service and controller
- ✅ Android instrumentation tests
- ✅ App integration with OpenVPN, SoftEther, and MS-SSTP
- ✅ Domain-to-IP resolution before TLS handshake (matching SoftEther client behavior)
- ✅ Redundant DNS lookup elimination in TCP socket layer
- ✅ Enhanced SSL error logging with errno and OpenSSL error details
1. TLS Domain Resolution (softether_protocol.c):
- Resolve domain to IP upfront in
softether_connect_with_hub() - Use resolved IP for both TCP connect and TLS handshake
- Eliminates duplicate DNS lookups and matches original SoftEther client behavior
2. TCP Socket Optimization (tcp_socket.c):
socket_connect_timeout()now usesinet_pton()to detect if host is already a dotted-decimal IP- Skips redundant
resolve_hostname()call when host is pure IP string - Result: single "Resolved X to X" log for both IP and domain inputs
3. SSL Error Diagnostics (aes_wrapper.c):
- Enhanced
SSL_ERROR_SYSCALLlogging with errno, strerror, and ERR_get_error() details - Helps identify handshake failures (connection reset, EOF, timeout, etc.)
4. UI/State Logging Cleanup (SoftEtherVpnService.kt, DetailActivity.kt):
- Omit empty
ip=suffix when assigned IP is not yet populated - Clean logs for CONNECTING/DISCONNECTING states (only show
ip=in CONNECTED state)
5. MS-SSTP Protocol Dialog Integration (VpnProtocolSelectionDialog.kt, DetailActivity.kt):
- Merged standalone MS-SSTP button into protocol selection dialog
- Protocol order: SoftEther TCP → SoftEther UDP → OpenVPN TCP → OpenVPN UDP → MS-SSTP
- Full button state lifecycle for SSTP (Cancel while connecting, Disconnect while connected)
- Wired SSTP connect/disconnect through protocol dialog callback
| Transport | Status |
|---|---|
| TCP (SoftEther over HTTPS/TLS) | ✅ Supported |
| UDP (SoftEther RUDP) | 🚧 Planned |
TCP is the only currently supported transport. UDP (RUDP) support is planned and requires implementing ~5000+ lines of reliable-UDP layer with NAT traversal, sequence numbers, ACKs, retransmission, and HMAC signatures.
Client Server
| |
|-------- TCP Connect ------------->|
|-------- TLS Handshake ----------->|
|<-------- TLS Handshake ----------|
|-------- HTTP GET / X-VPN: 1 ----->| (HTTP Detection)
|<-------- HTTP 403 Forbidden -----|
|-------- POST /vpnsvc/connect.cgi -->| (Watermark)
|<-------- HTTP 200 + Hello PACK --| ← Server sends Hello here!
|-------- POST /vpnsvc/vpn.cgi ----->| (AUTH via HTTP)
|<-------- HTTP 200 + AUTH_OK -----| ← Auth success!
|-------- POST /vpnsvc/vpn.cgi ----->| (SESSION via HTTP) ← NEW!
|<-------- HTTP 200 + SESSION -----| ← Session established!
...
-
SoftEtherClient/src/main/cpp/softether-core/src/proto/softether_protocol.c- Resolve domain to IP upfront via
resolve_hostname()insoftether_connect_with_hub() - Pass resolved IP (not domain) to both
socket_connect_timeout()andperform_tls_handshake()
- Resolve domain to IP upfront via
-
SoftEtherClient/src/main/cpp/softether-core/src/socket/tcp_socket.c- Add
inet_pton()check before DNS lookup insocket_connect_timeout() - Skip redundant
resolve_hostname()when host is already a dotted-decimal IP
- Add
-
SoftEtherClient/src/main/cpp/softether-core/src/crypto/aes_wrapper.c- Enhanced
SSL_ERROR_SYSCALLlogging: errno, strerror, ERR_get_error() details
- Enhanced
-
SoftEtherClient/src/main/java/vn/unlimit/softether/SoftEtherVpnService.kt- Omit
ip=suffix when assigned IP is empty in state logs
- Omit
-
SoftEtherClient/src/main/java/vn/unlimit/softether/controller/ConnectionController.kt- (No changes in 2026-03-09; maintains existing state management)
-
app/src/main/java/vn/unlimit/vpngate/dialog/VpnProtocolSelectionDialog.kt- Add MS-SSTP to protocol enum
- Reorder protocols: SoftEther TCP/UDP first, OpenVPN TCP/UDP second, MS-SSTP last
- Show/hide MS-SSTP card based on
connection.isSSTPSupport()
-
app/src/main/res/layout/dialog_vpn_protocol_selection.xml- Reorder protocol cards to match new preference order
-
app/src/main/java/vn/unlimit/vpngate/activities/DetailActivity.kt- Update
connectSSTPVPN(): set button state (Cancel + orange) while connecting - Update
initSSTP(): set button state on connection/disconnection in prefs listener - Update
handleSSTPBtn(): set button state (Connect) when disconnecting - Handle SSTP connected state in
onClick()→handleSSTPBtn() - Handle SSTP cancel in
isConnectingpath →startVpnSSTPService(DISCONNECT) - Remove standalone
btn_sstp_connectbutton fromactivity_detail.xml
- Update
-
app/src/main/res/layout/activity_detail.xml- Remove
ln_sstp_btnLinearLayout andbtn_sstp_connectButton
- Remove
-
app/src/main/res/values/strings.xml- Add
ms_sstpstring resource
- Add
-
SoftEtherClient/README.md- Add Protocol Support section documenting TCP (supported) and UDP (planned)
-
SoftEtherClient/IMPLEMENTATION_PLAN.md(this file)- Updated status, key improvements, protocol support table
./gradlew :SoftEtherClient:assembleDebug
./gradlew :SoftEtherClient:installDebugAndroidTest
./gradlew :SoftEtherClient:connectedDebugAndroidTestSoftEtherClient/build/outputs/apk/androidTest/debug/SoftEtherClient-debug-androidTest.apk
-
UDP (RUDP) Support
- Implement reliable UDP transport layer with sequence numbers, ACKs, retransmission
- Add NAT traversal support
- Integrate with existing native layer
-
Additional Stability & Testing
- Run full instrumentation suite periodically
- Validate behavior across diverse VPNGate server profiles
- Monitor for any edge cases in domain resolution or SSL handshakes
-
Optional Cleanup (Non-blocking)
- Address compiler warnings (unused helpers, deprecated connectivity broadcast)
Last Updated: 2026-03-09 Status: ✅ TCP protocol fully working, dialog merged, domain→IP resolution implemented, button states consistent with OpenVPN/SoftEther