File tree 2 files changed +13
-0
lines changed 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ type Server struct {
24
24
HostSigners []Signer // private keys for the host key, must have at least one
25
25
Version string // server version to be sent before the initial handshake
26
26
27
+ KeyboardInteractiveHandler KeyboardInteractiveHandler // keyboard-interactive authentication handler
27
28
PasswordHandler PasswordHandler // password authentication handler
28
29
PublicKeyHandler PublicKeyHandler // public key authentication handler
29
30
PtyCallback PtyCallback // callback for allowing PTY sessions, allows all if nil
@@ -105,6 +106,14 @@ func (srv *Server) config(ctx Context) *gossh.ServerConfig {
105
106
return ctx .Permissions ().Permissions , nil
106
107
}
107
108
}
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
+ }
108
117
return config
109
118
}
110
119
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package ssh
2
2
3
3
import (
4
4
"crypto/subtle"
5
+ gossh "golang.org/x/crypto/ssh"
5
6
"net"
6
7
)
7
8
@@ -39,6 +40,9 @@ type PublicKeyHandler func(ctx Context, key PublicKey) bool
39
40
// PasswordHandler is a callback for performing password authentication.
40
41
type PasswordHandler func (ctx Context , password string ) bool
41
42
43
+ // KeyboardInteractiveHandler is a callback for performing keyboard-interactive authentication.
44
+ type KeyboardInteractiveHandler func (ctx Context , challenger gossh.KeyboardInteractiveChallenge ) bool
45
+
42
46
// PtyCallback is a hook for allowing PTY sessions.
43
47
type PtyCallback func (ctx Context , pty Pty ) bool
44
48
You can’t perform that action at this time.
0 commit comments