Skip to content

Commit bed87f3

Browse files
authored
Merge pull request #92 from glassechidna/master
Added Server.KeyboardInteractiveHandler
2 parents cbabf54 + c2883aa commit bed87f3

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

server.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Server struct {
2424
HostSigners []Signer // private keys for the host key, must have at least one
2525
Version string // server version to be sent before the initial handshake
2626

27+
KeyboardInteractiveHandler KeyboardInteractiveHandler // keyboard-interactive authentication handler
2728
PasswordHandler PasswordHandler // password authentication handler
2829
PublicKeyHandler PublicKeyHandler // public key authentication handler
2930
PtyCallback PtyCallback // callback for allowing PTY sessions, allows all if nil
@@ -105,6 +106,14 @@ func (srv *Server) config(ctx Context) *gossh.ServerConfig {
105106
return ctx.Permissions().Permissions, nil
106107
}
107108
}
109+
if srv.KeyboardInteractiveHandler != nil {
110+
config.KeyboardInteractiveCallback = func(conn gossh.ConnMetadata, challenger gossh.KeyboardInteractiveChallenge) (*gossh.Permissions, error) {
111+
if ok := srv.KeyboardInteractiveHandler(ctx, challenger); !ok {
112+
return ctx.Permissions().Permissions, fmt.Errorf("permission denied")
113+
}
114+
return ctx.Permissions().Permissions, nil
115+
}
116+
}
108117
return config
109118
}
110119

ssh.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ssh
22

33
import (
44
"crypto/subtle"
5+
gossh "golang.org/x/crypto/ssh"
56
"net"
67
)
78

@@ -39,6 +40,9 @@ type PublicKeyHandler func(ctx Context, key PublicKey) bool
3940
// PasswordHandler is a callback for performing password authentication.
4041
type PasswordHandler func(ctx Context, password string) bool
4142

43+
// KeyboardInteractiveHandler is a callback for performing keyboard-interactive authentication.
44+
type KeyboardInteractiveHandler func(ctx Context, challenger gossh.KeyboardInteractiveChallenge) bool
45+
4246
// PtyCallback is a hook for allowing PTY sessions.
4347
type PtyCallback func(ctx Context, pty Pty) bool
4448

0 commit comments

Comments
 (0)