Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support of dialer for TCP #547

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions v8/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/jcmturner/gokrb5/v8/krberror"
"github.com/jcmturner/gokrb5/v8/messages"
"github.com/jcmturner/gokrb5/v8/types"
"golang.org/x/net/proxy"
)

// Client side configuration and state.
Expand All @@ -28,6 +29,7 @@ type Client struct {
settings *Settings
sessions *sessions
cache *Cache
tcpDialer proxy.Dialer
}

// NewWithPassword creates a new client from a password credential.
Expand Down Expand Up @@ -327,3 +329,7 @@ func (cl *Client) Print(w io.Writer) {
k, _ := cl.Credentials.Keytab().JSON()
fmt.Fprintf(w, "Keytab:\n%s\n", k)
}

func (cl *Client) SetDialerForTCP(dialer proxy.Dialer) {
cl.tcpDialer = dialer
}
17 changes: 13 additions & 4 deletions v8/client/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/jcmturner/gokrb5/v8/iana/errorcode"
"github.com/jcmturner/gokrb5/v8/messages"
"golang.org/x/net/proxy"
)

// SendToKDC performs network actions to send data to the KDC.
Expand Down Expand Up @@ -132,18 +133,26 @@ func (cl *Client) sendKDCTCP(realm string, b []byte) ([]byte, error) {
if err != nil {
return r, err
}
r, err = dialSendTCP(kdcs, b)
r, err = dialSendTCP(kdcs, b, cl.tcpDialer)
if err != nil {
return r, err
}
return checkForKRBError(r)
}

// dialKDCTCP establishes a TCP connection to a KDC.
func dialSendTCP(kdcs map[int]string, b []byte) ([]byte, error) {
func dialSendTCP(kdcs map[int]string, b []byte, dialer proxy.Dialer) ([]byte, error) {
var errs []string
for i := 1; i <= len(kdcs); i++ {
conn, err := net.DialTimeout("tcp", kdcs[i], 5*time.Second)
var conn net.Conn
var err error

if dialer != nil {
conn, err = dialer.Dial("tcp", kdcs[i])
} else {
conn, err = net.DialTimeout("tcp", kdcs[i], 5*time.Second)
}

if err != nil {
errs = append(errs, fmt.Sprintf("error establishing connection to %s: %v", kdcs[i], err))
continue
Expand All @@ -155,7 +164,7 @@ func dialSendTCP(kdcs map[int]string, b []byte) ([]byte, error) {
// conn is guaranteed to be a TCPConn
rb, err := sendTCP(conn.(*net.TCPConn), b)
if err != nil {
errs = append(errs, fmt.Sprintf("error sneding to %s: %v", kdcs[i], err))
errs = append(errs, fmt.Sprintf("error sending to %s: %v", kdcs[i], err))
continue
}
return rb, nil
Expand Down
2 changes: 1 addition & 1 deletion v8/client/passwd.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (cl *Client) sendToKPasswd(msg kadmin.Request) (r kadmin.Reply, err error)
return
}
} else {
rb, err = dialSendTCP(kps, b)
rb, err = dialSendTCP(kps, b, cl.tcpDialer)
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion v8/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ require (
github.com/jcmturner/rpc/v2 v2.0.3
github.com/stretchr/testify v1.8.1
golang.org/x/crypto v0.6.0
golang.org/x/net v0.7.0 // indirect
golang.org/x/net v0.7.0
)