|
|
@ -18,6 +18,7 @@ import (
|
|
|
|
"github.com/fangdingjun/go-log/v5"
|
|
|
|
"github.com/fangdingjun/go-log/v5"
|
|
|
|
socks "github.com/fangdingjun/socks-go"
|
|
|
|
socks "github.com/fangdingjun/socks-go"
|
|
|
|
"golang.org/x/crypto/ssh"
|
|
|
|
"golang.org/x/crypto/ssh"
|
|
|
|
|
|
|
|
"golang.org/x/crypto/ssh/agent"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// Client is ssh client connection
|
|
|
|
// Client is ssh client connection
|
|
|
@ -29,6 +30,7 @@ type Client struct {
|
|
|
|
err error
|
|
|
|
err error
|
|
|
|
ctx context.Context
|
|
|
|
ctx context.Context
|
|
|
|
cancel context.CancelFunc
|
|
|
|
cancel context.CancelFunc
|
|
|
|
|
|
|
|
authAgent agent.ExtendedAgent
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// NewClient create a new ssh Client
|
|
|
|
// 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
|
|
|
|
return client, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SetAuthAgent set auth agent
|
|
|
|
|
|
|
|
func (cc *Client) SetAuthAgent(_agent agent.ExtendedAgent) {
|
|
|
|
|
|
|
|
cc.authAgent = _agent
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Client return *ssh.Client
|
|
|
|
// Client return *ssh.Client
|
|
|
|
func (cc *Client) Client() *ssh.Client {
|
|
|
|
func (cc *Client) Client() *ssh.Client {
|
|
|
|
return cc.client
|
|
|
|
return cc.client
|
|
|
@ -168,6 +175,17 @@ func (cc *Client) Shell() error {
|
|
|
|
return err
|
|
|
|
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
|
|
|
|
// register console change signal
|
|
|
|
consoleChange(_console, session)
|
|
|
|
consoleChange(_console, session)
|
|
|
|
|
|
|
|
|
|
|
|