File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package ssh
22
33import (
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.
4041type 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.
4347type PtyCallback func (ctx Context , pty Pty ) bool
4448
You can’t perform that action at this time.
0 commit comments