diff --git a/src/controllers/files/establish_controller.go b/src/controllers/files/establish_controller.go index b574617..e598abf 100644 --- a/src/controllers/files/establish_controller.go +++ b/src/controllers/files/establish_controller.go @@ -4,7 +4,6 @@ import ( "github.com/genshen/ssh-web-console/src/models" "github.com/genshen/ssh-web-console/src/utils" "github.com/oklog/ulid/v2" - "golang.org/x/crypto/ssh" "log" "math/rand" "net/http" @@ -34,7 +33,7 @@ func (e SftpEstablish) ServeAfterAuthenticated(w http.ResponseWriter, r *http.Re // add sftp client to list if success. user := session.Value.(models.UserInfo) - sftpEntity, err := utils.NewSftpEntity(utils.SftpNode(utils.NewSSHNode(user.Host, user.Port)), user.Username, ssh.Password(user.Password)) + sftpEntity, err := utils.NewSftpEntity(utils.SftpNode(utils.NewSSHNode(user.Host, user.Port)), user.Username, (user.Password)) if err != nil { http.Error(w, "Error while establishing sftp connection", 400) log.Println("Error: while establishing sftp connection", err) diff --git a/src/controllers/main_controller.go b/src/controllers/main_controller.go index ca03c07..f05d7a6 100644 --- a/src/controllers/main_controller.go +++ b/src/controllers/main_controller.go @@ -3,7 +3,6 @@ package controllers import ( "github.com/genshen/ssh-web-console/src/models" "github.com/genshen/ssh-web-console/src/utils" - "golang.org/x/crypto/ssh" "net/http" "strconv" ) @@ -33,7 +32,7 @@ func SignIn(w http.ResponseWriter, r *http.Request) { //try to login session account session := utils.SSHShellSession{} session.Node = utils.NewSSHNode(userinfo.Host, userinfo.Port) - err := session.Connect(userinfo.Username, ssh.Password(userinfo.Password)) + err := session.Connect(userinfo.Username, (userinfo.Password)) if err != nil { errUnmarshal = models.JsonResponse{HasError: true, Message: models.SIGN_IN_FORM_TYPE_ERROR_PASSWORD} } else { diff --git a/src/controllers/websocket.go b/src/controllers/websocket.go index dd14db7..f92fcc0 100644 --- a/src/controllers/websocket.go +++ b/src/controllers/websocket.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/genshen/ssh-web-console/src/models" "github.com/genshen/ssh-web-console/src/utils" - "golang.org/x/crypto/ssh" "io" "log" "net/http" @@ -44,7 +43,7 @@ func (c *SSHWebSocketHandle) ServeAfterAuthenticated(w http.ResponseWriter, r *h userInfo := session.Value.(models.UserInfo) cols := utils.GetQueryInt32(r, "cols", 120) rows := utils.GetQueryInt32(r, "rows", 32) - sshAuth := ssh.Password(userInfo.Password) + sshAuth := (userInfo.Password) if err := c.SSHShellOverWS(r.Context(), conn, claims.Host, claims.Port, userInfo.Username, sshAuth, cols, rows); err != nil { log.Println("Error,", err) utils.Abort(w, err.Error(), 500) @@ -56,7 +55,7 @@ func (c *SSHWebSocketHandle) ServeAfterAuthenticated(w http.ResponseWriter, r *h // then we deliver ssh data via ssh connection between browser and ssh server. // That is, read webSocket data from browser (e.g. 'ls' command) and send data to ssh server via ssh connection; // the other hand, read returned ssh data from ssh server and write back to browser via webSocket API. -func (c *SSHWebSocketHandle) SSHShellOverWS(ctx context.Context, ws *websocket.Conn, host string, port int, username string, auth ssh.AuthMethod, cols, rows uint32) error { +func (c *SSHWebSocketHandle) SSHShellOverWS(ctx context.Context, ws *websocket.Conn, host string, port int, username string, auth string, cols, rows uint32) error { //setup ssh connection sshEntity := utils.SSHShellSession{ Node: utils.NewSSHNode(host, port), diff --git a/src/utils/sftp_utils.go b/src/utils/sftp_utils.go index fdc0f68..4844b67 100644 --- a/src/utils/sftp_utils.go +++ b/src/utils/sftp_utils.go @@ -3,7 +3,6 @@ package utils import ( "fmt" "github.com/pkg/sftp" - "golang.org/x/crypto/ssh" "sync" ) @@ -36,12 +35,12 @@ var ( subscribers = make(map[string]SftpEntity) ) -func NewSftpEntity(user SftpNode, username string, auth ssh.AuthMethod) (SftpEntity, error) { +func NewSftpEntity(user SftpNode, username string, pwd string) (SftpEntity, error) { sshEntity := SSHShellSession{ Node: NewSSHNode(user.Host, user.Port), } // init ssh connection. - err := sshEntity.Connect(username, auth) + err := sshEntity.Connect(username, pwd) if err != nil { return SftpEntity{}, err } diff --git a/src/utils/ssh_utils.go b/src/utils/ssh_utils.go index 3ffc686..54ef4e7 100644 --- a/src/utils/ssh_utils.go +++ b/src/utils/ssh_utils.go @@ -19,7 +19,7 @@ type SSHConnInterface interface { // close ssh connection Close() error // connect using username and password - Connect(username string, auth ssh.AuthMethod) error + Connect(username string, pwd string) error // config connection after connected and may also create a ssh session. Config(cols, rows uint32) (*ssh.Session, error) } @@ -43,7 +43,7 @@ func (node *Node) GetClient() (*ssh.Client, error) { //see: http://www.nljb.net/default/Go-SSH-%E4%BD%BF%E7%94%A8/ // establish a ssh connection. if success return nil, than can operate ssh connection via pointer Node.client in struct Node. -func (node *Node) Connect(username string, auth ssh.AuthMethod) error { +func (node *Node) Connect(username string, pwd string) error { //var hostKey ssh.PublicKey // An SSH client is represented with a ClientConn. @@ -54,7 +54,14 @@ func (node *Node) Connect(username string, auth ssh.AuthMethod) error { config := &ssh.ClientConfig{ User: username, Auth: []ssh.AuthMethod{ - auth, + ssh.Password(pwd), + ssh.KeyboardInteractive(func(name, instruction string, questions []string, echos []bool) ([]string, error){ + answers := make([]string, len(questions)) + for i := range answers { + answers[i] = pwd + } + return answers, nil + }), }, //HostKeyCallback: ssh.FixedHostKey(hostKey), HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {