summaryrefslogtreecommitdiff
path: root/client/main.go
diff options
context:
space:
mode:
authoratanarjuat <atanarjuat@example.com>2022-05-29 22:18:12 +0200
committeratanarjuat <atanarjuat@example.com>2022-05-29 22:18:12 +0200
commit60eda76d073ad9c0eaef63c6eb31d47e5ca86ff7 (patch)
treee757b95a836e6c1e788fa030a165cc8bf8c687f6 /client/main.go
parent6f2d28e19a41e9aa777071f63eebec89ca80ade4 (diff)
attempt at android bindings
Diffstat (limited to 'client/main.go')
-rw-r--r--client/main.go102
1 files changed, 0 insertions, 102 deletions
diff --git a/client/main.go b/client/main.go
deleted file mode 100644
index b536a81..0000000
--- a/client/main.go
+++ /dev/null
@@ -1,102 +0,0 @@
-package main
-
-import (
- "flag"
- "fmt"
- "io"
- "log"
- "net"
- "os"
-
- "0xacab.org/leap/obfsvpn"
-
- "github.com/kalikaneko/socks5"
- "github.com/xtaci/kcp-go"
-)
-
-func main() {
- // Setup logging.
- logger := log.New(os.Stderr, "", log.LstdFlags)
- debug := log.New(io.Discard, "DEBUG ", log.LstdFlags)
-
- // setup command line flags.
- var (
- verbose bool
- obfs4Cert string
- obfs4Remote string
- socksPort string
- socksHost string
- )
-
- socksPort = "8080"
- socksHost = "127.0.0.1"
-
- flags := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
- flags.BoolVar(&verbose, "v", verbose, "Enable verbose logging")
- flags.StringVar(&obfs4Cert, "c", obfs4Cert, "The remote obfs4 certificate")
- flags.StringVar(&obfs4Remote, "r", obfs4Remote, "The remote obfs4 endpoint (ip:port)")
- flags.StringVar(&socksPort, "p", socksPort, "The port for the local socks5 proxy (default: 8080)")
- flags.StringVar(&socksHost, "i", socksHost, "The host for the local socks5 proxy (default: localhost)")
- err := flags.Parse(os.Args[1:])
- if err != nil {
- logger.Fatalf("error parsing flags: %v", err)
- }
- // Configure logging.
- if verbose {
- debug.SetOutput(os.Stderr)
- }
-
- kcpTransport := false
- // TODO make this configurable via a Config struct
- // TODO make sure we're disabling all the crypto options for KCP
- if os.Getenv("KCP") == "1" {
- kcpTransport = true
- }
-
- socksAddr := net.JoinHostPort(socksHost, socksPort)
- client := NewClient(kcpTransport, socksAddr, obfs4Cert)
- client.Start()
-}
-
-type Client struct {
- kcp bool
- socksAddr string
- obfs4Cert string
-}
-
-func NewClient(kcp bool, socksAddr, obfs4Cert string) *Client {
- return &Client{
- kcp: kcp,
- socksAddr: socksAddr,
- obfs4Cert: obfs4Cert,
- }
-}
-
-func (c *Client) Start() bool {
- server := &socks5.Server{
- Addr: c.socksAddr,
- BindIP: "127.0.0.1",
- }
-
- dialer, err := obfsvpn.NewDialerFromCert(c.obfs4Cert)
- if err != nil {
- log.Printf("Error getting dialer: %v\n", err)
- return false
- }
-
- if c.kcp {
- dialer.DialFunc = func(network, address string) (net.Conn, error) {
- log.Printf("Dialing kcp://%s\n", address)
- return kcp.Dial(address)
- }
- }
-
- server.Dial = dialer.Dial
-
- fmt.Printf("[+] Starting socks5 proxy at %s\n", c.socksAddr)
- if err := server.ListenAndServe(); err != nil {
- log.Printf("error while listening: %v\n", err)
- return false
- }
- return true
-}