Skip to content

Commit

Permalink
feat(options): add banner callback
Browse files Browse the repository at this point in the history
  • Loading branch information
shipengqi committed May 8, 2024
1 parent 9d6fd1b commit ce5fa9f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions gosh.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Client struct {
opts *Options
auth ssh.AuthMethod
callback ssh.HostKeyCallback
bannercb ssh.BannerCallback
}

// NewDefault creates a Client with DefaultHostKeyCallback, the host public key must be in known hosts.
Expand Down Expand Up @@ -112,6 +113,12 @@ func (c *Client) WithHostKeyCallback(callback ssh.HostKeyCallback) *Client {
return c
}

// WithBannerCallback sets ssh.BannerCallback of Client.
func (c *Client) WithBannerCallback(callback ssh.BannerCallback) *Client {
c.bannercb = callback
return c
}

// Dial starts a client connection to the given SSH server.
func (c *Client) Dial() error {
cli, err := c.dial()
Expand Down Expand Up @@ -280,6 +287,7 @@ func (c *Client) dial() (*ssh.Client, error) {
Auth: []ssh.AuthMethod{c.auth},
Timeout: c.opts.Timeout,
HostKeyCallback: c.callback,
BannerCallback: c.bannercb,
},
)
}
Expand Down
4 changes: 2 additions & 2 deletions knownhosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (

func AutoFixedHostKeyCallback(host string, remote net.Addr, key ssh.PublicKey) error {
found, err := VerifyKnownHost("", host, remote, key)
if found && err != nil {
if err != nil {
return err
}
if found && err == nil {
if found {
return nil
}
// Add the new host to known hosts file.
Expand Down

0 comments on commit ce5fa9f

Please sign in to comment.