|
|
|
@ -18,6 +18,7 @@ import (
|
|
|
|
|
"github.com/fangdingjun/go-log/v5"
|
|
|
|
|
socks "github.com/fangdingjun/socks-go"
|
|
|
|
|
"golang.org/x/crypto/ssh"
|
|
|
|
|
"golang.org/x/crypto/ssh/agent"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Client is ssh client connection
|
|
|
|
@ -29,6 +30,7 @@ type Client struct {
|
|
|
|
|
err error
|
|
|
|
|
ctx context.Context
|
|
|
|
|
cancel context.CancelFunc
|
|
|
|
|
authAgent agent.ExtendedAgent
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewClient create a new ssh Client
|
|
|
|
@ -54,6 +56,11 @@ func NewClient(c net.Conn, config *ssh.ClientConfig, addr string, conf *Conf) (*
|
|
|
|
|
return client, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetAuthAgent set auth agent
|
|
|
|
|
func (cc *Client) SetAuthAgent(_agent agent.ExtendedAgent) {
|
|
|
|
|
cc.authAgent = _agent
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Client return *ssh.Client
|
|
|
|
|
func (cc *Client) Client() *ssh.Client {
|
|
|
|
|
return cc.client
|
|
|
|
@ -168,6 +175,17 @@ func (cc *Client) Shell() error {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if cc.authAgent != nil {
|
|
|
|
|
log.Debugln("request auth agent forwarding")
|
|
|
|
|
if err = agent.RequestAgentForwarding(session); err == nil {
|
|
|
|
|
if err1 := agent.ForwardToAgent(cc.client, cc.authAgent); err1 != nil {
|
|
|
|
|
log.Debugln(err)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.Debugln(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// register console change signal
|
|
|
|
|
consoleChange(_console, session)
|
|
|
|
|
|
|
|
|
|