Skip to content

Commit

Permalink
Merge pull request #84 from openziti/fix-tls-dial-proxy
Browse files Browse the repository at this point in the history
tls.Dial should use proxy configuration if provided Fixes #83
  • Loading branch information
plorenz authored Jun 28, 2024
2 parents 375bca7 + da1992d commit 1a3cacc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 27 deletions.
8 changes: 6 additions & 2 deletions tls/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ type address struct {
port uint16
}

func (a address) Dial(name string, i *identity.TokenId, timeout time.Duration, cfg transport.Configuration) (transport.Conn, error) {
return Dial(a.bindableAddress(), name, i, timeout, cfg.Protocols()...)
func (a address) Dial(name string, i *identity.TokenId, timeout time.Duration, tcfg transport.Configuration) (transport.Conn, error) {
proxyConfig, err := tcfg.GetProxyConfiguration()
if err != nil {
return nil, errors.Wrapf(err, "unable to get proxy configuration")
}
return Dial(a, name, i, timeout, proxyConfig, tcfg.Protocols()...)
}

func (a address) DialWithLocalBinding(name string, localBinding string, i *identity.TokenId, timeout time.Duration, tcfg transport.Configuration) (transport.Conn, error) {
Expand Down
23 changes: 2 additions & 21 deletions tls/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,11 @@ import (
"github.com/openziti/transport/v2"
"github.com/openziti/transport/v2/proxies"
"github.com/pkg/errors"
"net"
"time"
)

func Dial(destination, name string, i *identity.TokenId, timeout time.Duration, protocols ...string) (transport.Conn, error) {
log := pfxlog.Logger()

tlsCfg := i.ClientTLSConfig().Clone()
tlsCfg.NextProtos = protocols
socket, err := tls.DialWithDialer(&net.Dialer{Timeout: timeout}, "tcp", destination, tlsCfg)
if err != nil {
return nil, err
}

log.Debugf("server provided [%d] certificates", len(socket.ConnectionState().PeerCertificates))

return &Connection{
detail: &transport.ConnectionDetail{
Address: Type + ":" + destination,
InBound: false,
Name: name,
},
Conn: socket,
}, nil
func Dial(a address, name string, i *identity.TokenId, timeout time.Duration, proxyConf *transport.ProxyConfiguration, protocols ...string) (transport.Conn, error) {
return DialWithLocalBinding(a, name, "", i, timeout, proxyConf, protocols...)
}

func DialWithLocalBinding(a address, name, localBinding string, i *identity.TokenId, timeout time.Duration, proxyConf *transport.ProxyConfiguration, protocols ...string) (transport.Conn, error) {
Expand Down
10 changes: 6 additions & 4 deletions tls/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,15 @@ func checkClient(addr string, proto string, expected string, t *testing.T) error
Data: nil,
}

transport.AddAddressParser(AddressParser{})
tlsAddr, err := transport.ParseAddress("tls:" + addr)
require.NoError(t, err)

var c transport.Conn
var err error
if proto == "" {
c, err = Dial(addr, "test-dialer", clt, time.Second)

c, err = Dial(*(tlsAddr.(*address)), "test-dialer", clt, time.Second, nil)
} else {
c, err = Dial(addr, "test-dialer", clt, time.Second, proto)
c, err = Dial(*(tlsAddr.(*address)), "test-dialer", clt, time.Second, nil, proto)
}
if err != nil {
return err
Expand Down

0 comments on commit 1a3cacc

Please sign in to comment.