From 6dcd5356b5c45a4647f81f45e2273e65c20a2297 Mon Sep 17 00:00:00 2001 From: Aidan Steele Date: Sun, 6 Jan 2019 15:25:33 +1100 Subject: [PATCH 1/2] Added Server.KeyboardInteractiveHandler --- server.go | 9 +++++++++ ssh.go | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/server.go b/server.go index 31e3353..a41902e 100644 --- a/server.go +++ b/server.go @@ -24,6 +24,7 @@ type Server struct { HostSigners []Signer // private keys for the host key, must have at least one Version string // server version to be sent before the initial handshake + KeyboardInteractiveHandler KeyboardInteractiveHandler // keyboard-interactive authentication handler PasswordHandler PasswordHandler // password authentication handler PublicKeyHandler PublicKeyHandler // public key authentication handler PtyCallback PtyCallback // callback for allowing PTY sessions, allows all if nil @@ -105,6 +106,14 @@ func (srv *Server) config(ctx Context) *gossh.ServerConfig { return ctx.Permissions().Permissions, nil } } + if srv.KeyboardInteractiveHandler != nil { + config.KeyboardInteractiveCallback = func(conn gossh.ConnMetadata, challenger gossh.KeyboardInteractiveChallenge) (*gossh.Permissions, error) { + if ok := srv.KeyboardInteractiveHandler(ctx, challenger); !ok { + return ctx.Permissions().Permissions, fmt.Errorf("permission denied") + } + return ctx.Permissions().Permissions, nil + } + } return config } diff --git a/ssh.go b/ssh.go index 88cf934..cf11499 100644 --- a/ssh.go +++ b/ssh.go @@ -2,6 +2,7 @@ package ssh import ( "crypto/subtle" + "golang.org/x/crypto/ssh" "net" ) @@ -39,6 +40,9 @@ type PublicKeyHandler func(ctx Context, key PublicKey) bool // PasswordHandler is a callback for performing password authentication. type PasswordHandler func(ctx Context, password string) bool +// KeyboardInteractiveHandler is a callback for performing keyboard-interactive authentication. +type KeyboardInteractiveHandler func(ctx Context, challenger ssh.KeyboardInteractiveChallenge) bool + // PtyCallback is a hook for allowing PTY sessions. type PtyCallback func(ctx Context, pty Pty) bool From c2883aad47e00aac86a96a6892a4293d36de14ae Mon Sep 17 00:00:00 2001 From: Aidan Steele Date: Mon, 7 Jan 2019 08:09:35 +1100 Subject: [PATCH 2/2] Import x/net/crypto/ssh with alias gossh --- ssh.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ssh.go b/ssh.go index cf11499..1d339c4 100644 --- a/ssh.go +++ b/ssh.go @@ -2,7 +2,7 @@ package ssh import ( "crypto/subtle" - "golang.org/x/crypto/ssh" + gossh "golang.org/x/crypto/ssh" "net" ) @@ -41,7 +41,7 @@ type PublicKeyHandler func(ctx Context, key PublicKey) bool type PasswordHandler func(ctx Context, password string) bool // KeyboardInteractiveHandler is a callback for performing keyboard-interactive authentication. -type KeyboardInteractiveHandler func(ctx Context, challenger ssh.KeyboardInteractiveChallenge) bool +type KeyboardInteractiveHandler func(ctx Context, challenger gossh.KeyboardInteractiveChallenge) bool // PtyCallback is a hook for allowing PTY sessions. type PtyCallback func(ctx Context, pty Pty) bool