@@ -170,7 +170,12 @@ func (srv *Server) config(ctx Context) *gossh.ServerConfig {
170
170
config .KeyboardInteractiveCallback = func (conn gossh.ConnMetadata , challenger gossh.KeyboardInteractiveChallenge ) (* gossh.Permissions , error ) {
171
171
resetPermissions (ctx )
172
172
applyConnMetadata (ctx , conn )
173
- if ok := srv .KeyboardInteractiveHandler (ctx , challenger ); ! ok {
173
+ ok := srv .KeyboardInteractiveHandler (ctx , challenger )
174
+ err := ensureNoPKInPermissions (ctx )
175
+ if err != nil {
176
+ return ctx .Permissions ().Permissions , err
177
+ }
178
+ if ! ok {
174
179
return ctx .Permissions ().Permissions , fmt .Errorf ("permission denied" )
175
180
}
176
181
return ctx .Permissions ().Permissions , nil
@@ -302,6 +307,30 @@ func (srv *Server) HandleConn(newConn net.Conn) {
302
307
return
303
308
}
304
309
310
+ if sshConn .Permissions != nil {
311
+ // Now that the connection was authed, if the permissionsPublicKeyExt was
312
+ // attached, we need to re-parse it as a public key.
313
+ if keyData , ok := sshConn .Permissions .Extensions [permissionsPublicKeyExt ]; ok {
314
+ decodedData , err := base64 .StdEncoding .DecodeString (keyData )
315
+ if err != nil {
316
+ if srv .ConnectionFailedCallback != nil {
317
+ srv .ConnectionFailedCallback (conn , err )
318
+ }
319
+ return
320
+ }
321
+
322
+ key , err := gossh .ParsePublicKey (decodedData )
323
+ if err != nil {
324
+ if srv .ConnectionFailedCallback != nil {
325
+ srv .ConnectionFailedCallback (conn , err )
326
+ }
327
+ return
328
+ }
329
+
330
+ ctx .SetValue (ContextKeyPublicKey , key )
331
+ }
332
+ }
333
+
305
334
// Additionally, now that the connection was authed, we can take the
306
335
// permissions off of the gossh.Conn and re-attach them to the Permissions
307
336
// object stored in the Context.
0 commit comments