0

I'm trying to dial using credentials and maintain a connection with a socks5 proxy server in Go.

This works nicely if I have IP authorisation set up with the proxy provider, however there is no way pass any auth credentials using net.Dial function in Go:

package main

import (
    "io"
    "net"
)

func main() {

    dst, err := net.Dial("tcp", "11.22.33.44:1111")
    if err != nil {
        panic("Dial Error:" + err.Error())
    }

    dst.Close()
}

Go has a useful proxy library and allows authenticated forward requests via proxy using this:

package main

import (
    "io"
    "net"
)

func main() {

    var proxyAuth *proxy.Auth
    if conf.Username != "" {
        proxyAuth = new(proxy.Auth)
        proxyAuth.User = conf.Username
        proxyAuth.Password = conf.Password
    }

    proxyconn, _ := proxy.SOCKS5("tcp", "11.11.11.11:1111", proxyAuth, nil) //returns a Dialer with proxy that can be invoked to connect to another address

    dst := proxyconn.Dial("tcp", "22.33.44.55:6666") //connects to an address via proxy

    dst.Close()
}

However it returns a Dialer that then asks to connect a target/ultimate address through this authenticated proxy rather the proxy server itself:

My objective here is to return a net.conn connection with a credentials-authenticated proxy server - something like this:

package main

import (
    "io"
    "net"
)

func main() {

    //net.Dial does not have a way to pass Auth creds
    dst := net.Dial("tcp", "22.33.44.55:6666", proxyAuth)

    dst.Close()
}
PitaHat
  • 21
  • 3
  • Why do you want a connection to the proxy? – Gari Singh Nov 30 '21 at 10:34
  • Building a native Go proxy Squid-like app. The server side would listen in on localhost and reroute the requests made by the client through an authenticated proxy. Works fine if I have IP authorisation set up with proxy provider as per the first example. – PitaHat Nov 30 '21 at 11:28

1 Answers1

0

The net.Dial() method doesn't concerned with proxy authentication. However, If you want proxy authentication you can set it in header of the request before the call. Please refer this link

dst := net.Dial("tcp", "22.33.44.55:6666")
Ashutosh Singh
  • 721
  • 3
  • 6
  • This seems to be applicable for HTTP forwarding only rather than SOCK5. It's a neat workaround but doesn't not entirely fit my needs unfortunately. – PitaHat Dec 01 '21 at 14:34