|
|
@ -40,32 +40,39 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
// Handle handles an SSH connection from c.
|
|
|
|
// Handle handles an SSH connection from c.
|
|
|
|
func Handle(logf logger.Logf, lb *ipnlocal.LocalBackend, c net.Conn) error {
|
|
|
|
func Handle(logf logger.Logf, lb *ipnlocal.LocalBackend, c net.Conn) error {
|
|
|
|
sshd := &server{lb, logf}
|
|
|
|
srv := &server{lb, logf}
|
|
|
|
srv := &ssh.Server{
|
|
|
|
ss, err := srv.newSSHServer()
|
|
|
|
Handler: sshd.handleSSH,
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ss.HandleConn(c)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (srv *server) newSSHServer() (*ssh.Server, error) {
|
|
|
|
|
|
|
|
ss := &ssh.Server{
|
|
|
|
|
|
|
|
Handler: srv.handleSSH,
|
|
|
|
RequestHandlers: map[string]ssh.RequestHandler{},
|
|
|
|
RequestHandlers: map[string]ssh.RequestHandler{},
|
|
|
|
SubsystemHandlers: map[string]ssh.SubsystemHandler{},
|
|
|
|
SubsystemHandlers: map[string]ssh.SubsystemHandler{},
|
|
|
|
ChannelHandlers: map[string]ssh.ChannelHandler{},
|
|
|
|
ChannelHandlers: map[string]ssh.ChannelHandler{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for k, v := range ssh.DefaultRequestHandlers {
|
|
|
|
for k, v := range ssh.DefaultRequestHandlers {
|
|
|
|
srv.RequestHandlers[k] = v
|
|
|
|
ss.RequestHandlers[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for k, v := range ssh.DefaultChannelHandlers {
|
|
|
|
for k, v := range ssh.DefaultChannelHandlers {
|
|
|
|
srv.ChannelHandlers[k] = v
|
|
|
|
ss.ChannelHandlers[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for k, v := range ssh.DefaultSubsystemHandlers {
|
|
|
|
for k, v := range ssh.DefaultSubsystemHandlers {
|
|
|
|
srv.SubsystemHandlers[k] = v
|
|
|
|
ss.SubsystemHandlers[k] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
keys, err := lb.GetSSH_HostKeys()
|
|
|
|
keys, err := srv.lb.GetSSH_HostKeys()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, signer := range keys {
|
|
|
|
for _, signer := range keys {
|
|
|
|
srv.AddHostKey(signer)
|
|
|
|
ss.AddHostKey(signer)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ss, nil
|
|
|
|
srv.HandleConn(c)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type server struct {
|
|
|
|
type server struct {
|
|
|
|