FIXES:
* cryptparse.TlsUri.ToConn and cryptparse.TlsUri.ToTlsConn would
  previously use incorrect "host" parameter during dial for UDS/IPC
  sockets.
This commit is contained in:
brent saner 2024-08-12 15:59:38 -04:00
parent 77a85a4f84
commit 5dc944cf21
Signed by: bts
GPG Key ID: 8C004C2F93481F6B

View File

@ -38,6 +38,7 @@ func (t *TlsUri) WithConn(underlying net.Conn) (conn *tls.Conn, err error) {
func (t *TlsUri) ToConn() (conn net.Conn, err error) {

var ok bool
var connHost string
var params map[string][]string
var netType string = DefaultNetType

@ -48,8 +49,16 @@ func (t *TlsUri) ToConn() (conn net.Conn, err error) {
netType = params[TlsUriParamNet][0]
}
}
netType = strings.ToLower(netType)

if conn, err = net.Dial(netType, t.Host); err != nil {
switch netType {
case "unix", "unixgram", "unixpacket":
connHost = t.Path
default:
connHost = t.Host
}

if conn, err = net.Dial(netType, connHost); err != nil {
return
}

@ -79,6 +88,7 @@ func (t *TlsUri) ToTlsConn() (conn *tls.Conn, err error) {

var ok bool
var cfg *tls.Config
var connHost string
var params map[string][]string
var netType string = DefaultNetType

@ -93,8 +103,16 @@ func (t *TlsUri) ToTlsConn() (conn *tls.Conn, err error) {
netType = params[TlsUriParamNet][0]
}
}
netType = strings.ToLower(netType)

if conn, err = tls.Dial(netType, t.Host, cfg); err != nil {
switch netType {
case "unix", "unixgram", "unixpacket":
connHost = t.Path
default:
connHost = t.Host
}

if conn, err = tls.Dial(netType, connHost, cfg); err != nil {
return
}