File tree 2 files changed +12
-3
lines changed
2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ type Server struct {
39
39
Version string // server version to be sent before the initial handshake
40
40
Banner string // server banner
41
41
42
+ BannerHandler BannerHandler // server banner handler, overrides Banner
42
43
KeyboardInteractiveHandler KeyboardInteractiveHandler // keyboard-interactive authentication handler
43
44
PasswordHandler PasswordHandler // password authentication handler
44
45
PublicKeyHandler PublicKeyHandler // public key authentication handler
@@ -134,10 +135,16 @@ func (srv *Server) config(ctx Context) *gossh.ServerConfig {
134
135
config .ServerVersion = "SSH-2.0-" + srv .Version
135
136
}
136
137
if srv .Banner != "" {
137
- config .BannerCallback = func (conn gossh.ConnMetadata ) string {
138
+ config .BannerCallback = func (_ gossh.ConnMetadata ) string {
138
139
return srv .Banner
139
140
}
140
141
}
142
+ if srv .BannerHandler != nil {
143
+ config .BannerCallback = func (conn gossh.ConnMetadata ) string {
144
+ applyConnMetadata (ctx , conn )
145
+ return srv .BannerHandler (ctx )
146
+ }
147
+ }
141
148
if srv .PasswordHandler != nil {
142
149
config .PasswordCallback = func (conn gossh.ConnMetadata , password []byte ) (* gossh.Permissions , error ) {
143
150
applyConnMetadata (ctx , conn )
Original file line number Diff line number Diff line change @@ -35,6 +35,9 @@ type Option func(*Server) error
35
35
// Handler is a callback for handling established SSH sessions.
36
36
type Handler func (Session )
37
37
38
+ // BannerHandler is a callback for displaying the server banner.
39
+ type BannerHandler func (ctx Context ) string
40
+
38
41
// PublicKeyHandler is a callback for performing public key authentication.
39
42
type PublicKeyHandler func (ctx Context , key PublicKey ) bool
40
43
@@ -115,8 +118,7 @@ func Handle(handler Handler) {
115
118
116
119
// KeysEqual is constant time compare of the keys to avoid timing attacks.
117
120
func KeysEqual (ak , bk PublicKey ) bool {
118
-
119
- //avoid panic if one of the keys is nil, return false instead
121
+ // avoid panic if one of the keys is nil, return false instead
120
122
if ak == nil || bk == nil {
121
123
return false
122
124
}
You can’t perform that action at this time.
0 commit comments