Skip to content

[WIP] Add SOCKS5 proxy server implementation in Android app#1

Merged
veynko merged 4 commits into
mainfrom
copilot/add-socks5-proxy-server
May 2, 2026
Merged

[WIP] Add SOCKS5 proxy server implementation in Android app#1
veynko merged 4 commits into
mainfrom
copilot/add-socks5-proxy-server

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 1, 2026

  • Set up Android project structure (Gradle, manifest, build files)
  • Create SOCKS5 server implementation (Socks5Server.kt, Socks5Handler.kt)
  • Create ForegroundService (ProxyForegroundService.kt)
  • Create ViewModel (ProxyViewModel.kt)
  • Create Compose UI (ProxyScreen.kt, MainActivity.kt, Theme)
  • Create AndroidManifest.xml with proper permissions
  • Create notification icon and resources
  • Add GitHub Actions CI workflow
  • Validate build compiles successfully via CI
Original prompt

You are a senior Android developer. Build a complete Android application in Kotlin that works as a SOCKS5 proxy server running locally on the device.

Core Requirements:

  1. The app must start a SOCKS5 proxy server bound to 0.0.0.0 (all interfaces) on a configurable port.
  2. The server must support:
    • SOCKS5 protocol (RFC 1928)
    • TCP CONNECT command
    • Optional username/password authentication (RFC 1929)
  3. The proxy must tunnel traffic between client and destination (full duplex stream forwarding).
  4. The server must handle multiple concurrent connections using coroutines.

Networking:

  • Use Kotlin + coroutines (no blocking IO)
  • Use ServerSocket or NIO
  • Efficient buffer forwarding between client and remote host
  • Proper error handling and socket closing

Android Constraints:

  • Run the proxy inside a Foreground Service
  • Show persistent notification when running
  • Handle lifecycle correctly (start/stop server)
  • Request INTERNET permission
  • Support Android 8+ (API 26+)

UI Requirements:

Create a simple UI with:

  • Toggle button: Start / Stop server
  • Input field: Port
  • Switch: Enable authentication
  • Input fields: Username and Password (visible only if auth enabled)
  • Status indicator (Running / Stopped)

Use:

  • Jetpack Compose for UI
  • ViewModel for state management

Architecture:

  • Clean architecture (UI / Service / Network layer)
  • Separate SOCKS5 protocol logic into its own class/module
  • Use dependency injection (Hilt preferred but optional)

SOCKS5 Implementation Details:

Implement:

  1. Greeting:

    • Version = 0x05
    • Method negotiation (no auth or username/password)
  2. Authentication (if enabled):

    • Version 0x01
    • Validate credentials
  3. Request:

    • CONNECT command only
    • Support IPv4, domain names
  4. Response:

    • Proper success and error replies

Extra:

  • Log connections (client IP, target host)
  • Gracefully handle invalid packets
  • Prevent crashes on malformed input

Deliverables:

  • Full Android project structure
  • MainActivity
  • ForegroundService implementation
  • SOCKS5 server implementation
  • UI code (Compose)
  • Manifest setup

Important:

  • Do NOT use third-party SOCKS libraries. Implement protocol manually.
  • Write clean, well-commented code.
  • Ensure the app is functional and can be built immediately.

Copilot AI and others added 3 commits May 1, 2026 19:41
- settings.gradle.kts: project config with plugin management and dependency resolution
- build.gradle.kts: top-level build file with AGP 8.5.2, Kotlin 2.0.21
- gradle/libs.versions.toml: version catalog with all dependencies
- app/build.gradle.kts: module build config (compileSdk 35, minSdk 26)
- AndroidManifest.xml: permissions, activity, foreground service declaration
- Socks5Handler.kt: RFC 1928/1929 SOCKS5 protocol handler (connect + auth)
- Socks5Server.kt: ServerSocket accept loop with coroutine-per-connection
- ProxyForegroundService.kt: foreground service hosting the proxy server
- ProxyViewModel.kt: AndroidViewModel with UI state and service control
- ProxyScreen.kt: Compose UI with port, auth toggle, start/stop button
- Theme/Color.kt: Material3 theming with status colors
- MainActivity.kt: edge-to-edge Compose entry point
- Resources: strings, themes, colors, vector drawables, adaptive icons

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: veynko <49876227+veynko@users.noreply.github.com>
- MainActivity: pass innerPadding to ProxyScreen to prevent content
  drawing under system bars
- ProxyScreen: accept modifier parameter and apply it to root Column
- Socks5Handler.forwardData: cancel both directions symmetrically —
  each direction now cancels the other as soon as it finishes,
  rather than only cancelling remoteToClient after clientToRemote

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Co-authored-by: veynko <49876227+veynko@users.noreply.github.com>
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.

2 participants