custom-auth

command
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2026 License: CC0-1.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

SOCKS Proxy Custom Authentication Example

A complete client-server example demonstrating SOCKS5 proxy with custom authentication using a simple token-based authentication method.

Overview

This example demonstrates:

  • Custom AuthMethod implementation (client-side)
  • Custom AuthHandler implementation (server-side)
  • Private authentication method code (0x80)

Usage

go run . [options]
Options
  • -addr: SOCKS server listen address (default: 127.0.0.1:1080)
  • -target: Target URL to fetch (default: http://example.com)
  • -token: Shared authentication token (required)

Examples

# Use a token
go run . -token my-secret-token

# Connect to a custom target
go run . -token my-secret-token -target http://httpbin.org/ip

Custom Authentication Protocol

This example implements a simple token-based authentication method:

  1. Client sends method selection including custom auth (0x80)
  2. Server selects custom authentication
  3. Client sends token:
    • 1 byte: token length
    • N bytes: token (SHA-256 hash of shared secret)
  4. Server validates token and sends response:
    • 1 byte: 0x00 (success) or 0x01 (failure)
Token Frame Format (Client → Server)
+--------+---------+
| LEN    | TOKEN   |
+--------+---------+
| 1 byte | N bytes |
+--------+---------+

Where:

  • LEN: Token length (1 byte)
  • TOKEN: SHA-256 hash of the shared secret
Response Format (Server → Client)
+--------+
| STATUS |
+--------+
| 1 byte |
+--------+

Where:

  • STATUS: 0x00 (success) or 0x01 (failure)

Authentication Method Codes

SOCKS5 defines the following standard method codes:

  • 0x00: No authentication required
  • 0x01: GSS-API authentication
  • 0x02: Username/password authentication
  • 0x03-0x7F: IANA assigned methods
  • 0x80-0xFE: Private methods (used by this example)
  • 0xFF: No acceptable methods

This example uses 0x80 for the custom token-based authentication method.

Documentation

Overview

nolint

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL