websocket icon indicating copy to clipboard operation
websocket copied to clipboard

DialContext doesn't give back TLS information

Open mdosch opened this issue 4 months ago • 4 comments

Dear devs,

thank you for providing this library, however, I have an issue:

I have an TLS encrypted connection, but the response of DialContext() doesn't provide this informations as resp.TLS is always nil. :(

Here I dial: https://salsa.debian.org/mdosch/xmpp-dns/-/blob/gorilla/main.go#L956 There it is always nil: https://salsa.debian.org/mdosch/xmpp-dns/-/blob/gorilla/main.go#L1007

Best regards, Martin

mdosch avatar Aug 16 '25 13:08 mdosch

Use this function as a workaround for the missing functionality:

func getTLS(c any) *tls.ConnectionState {
	for c != nil {
		if tc, ok := c.(*tls.Conn); ok {
			state := tc.ConnectionState()
			return &state
		}
		wc, ok := c.(interface{ NetConn() net.Conn })
		if !ok {
			break
		}
		c = wc.NetConn()
	}
	return nil
}

Call it like this:

 c, r, err := d.DialContext(...)
 state := getTLS(c)

ghost avatar Sep 04 '25 19:09 ghost

@tollwayclout thanks a lot, this works! :) How do you want to be attributed?

mdosch avatar Sep 04 '25 19:09 mdosch

Thanks again. :)

mdosch avatar Sep 04 '25 20:09 mdosch

See #967.

ghost avatar Sep 06 '25 19:09 ghost