pires / go-proxyproto

A Go library implementation of the PROXY protocol, versions 1 and 2.
Apache License 2.0
482 stars 108 forks source link

support tls? #59

Closed smil267 closed 3 years ago

smil267 commented 3 years ago

hi, when the server listen mode is tls, it isn't work. can you support tls listen?

smil267 commented 3 years ago

tls prompt err: tls: first record does not look like a TLS handshake

pires commented 3 years ago

I'm sorry but I can't understand what the request is here. TLS is supported. Can you share code?

pires commented 3 years ago

Here's a test that shows how to setup TLS properly. Let us know if it doesn't work. Closing for now.

baixiaoshi commented 2 years ago

image

server code

`func main() {

cert, err := tls.LoadX509KeyPair("cert/xxxx.crt", "cert/xxx.key")
if err != nil {
    log.Println(err)
    return
}
config := &tls.Config{
    Certificates: []tls.Certificate{cert}}

ln, err := tls.Listen("tcp", ":9090", config)

proxyListener := &proxyproto.Listener{
    Listener: ln,
}

conn, err := proxyListener.Accept()
if err != nil {
    log.Fatalf("err: %v", err)
}
defer conn.Close()

addr := conn.RemoteAddr().(*net.TCPAddr)
fmt.Println("ip====", addr.IP.String())
if addr.IP.String() != "10.1.1.1" {
    log.Fatalf("bad: %v", addr)
}
if addr.Port != 1000 {
    log.Fatalf("bad: %v", addr)
}

} `

client code

`func main() {

conn, err := net.Dial("tcp", "127.0.0.1:9090")
if err != nil {
    log.Fatalf("err: %v", err)
}
defer conn.Close()

// Write out the header!
header := "PROXY TCP4 10.1.1.1 20.2.2.2 1000 2000\r\n"
conn.Write([]byte(header))

}`

shanezhiu commented 1 year ago

I got the same error.