Saturday, May 4, 2024
HomeGolangIs there some option to get the host server identify from a...

Is there some option to get the host server identify from a TLS web.Conn? – Getting Assist


I’ve a Go TLS server with a wildcard area *.myserver.com so distant shoppers can name it with foo.myserver.com or bar.myserver.com, is there a way I can discover out which hostname a consumer used from the web.Conn that I get again Listerner.Settle for()?

All I’ve discovered thus far is that if i take advantage of GetConfigForClient on the tls.Config of the server then that operate does get the server identify:

	tlsConfig := &tls.Config{
		GetConfigForClient: getConfigForClient,
	}
func getConfigForClient(hello *tls.ClientHelloInfo) (*tls.Config, error) {
        // does print the complete identify: foo.myserver.com
  	log.Println("Server.getConfigForClient hostName:", hello.ServerName) 
 . . .
}

however I can’t discover a option to get that or move that to a listener handler.

Thanks for any assist.

you would retailer this data in an information construction after which do lookup within the handler. ClientHelloInfo incorporates additionally the web.Conn so possibly you would use a map with web.Conn as key

Thats the kind of factor I’m hoping however I can’t but see how. Nothing I can discover has entry to each the host identify and the web.Conn.

effectively in ClientHelloInfo you could have each no?

contained in the getConfigForClient() you may learn each and retailer in a world map

The issue with that’s that web.Conn is an interface and the occasion from the ClientHelloInfo in getConfigForClient will not be the identical factor that’s returned from web.Listener.Settle for()

We now have one thing wokring now by utilizing a map with key web.Conn.RemoteAddr().String() which is the distant consumer’s ip tackle and port. This appears to work okay, however is it going to be distinctive all of it eventualities?

This matter was robotically closed 90 days after the final reply. New replies are now not allowed.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments