@@ -141,7 +141,13 @@ func createPublicKeyCallback(connCtx context.Context, sshKeywords *wshrpc.ConnKe
141
141
authSockSigners = append (authSockSigners , authSockSignersExt ... )
142
142
authSockSignersPtr := & authSockSigners
143
143
144
- return func () ([]ssh.Signer , error ) {
144
+ return func () (outSigner []ssh.Signer , outErr error ) {
145
+ defer func () {
146
+ panicErr := panichandler .PanicHandler ("sshclient:publickey-callback" , recover ())
147
+ if panicErr != nil {
148
+ outErr = panicErr
149
+ }
150
+ }()
145
151
// try auth sock
146
152
if len (* authSockSignersPtr ) != 0 {
147
153
authSockSigner := (* authSockSignersPtr )[0 ]
@@ -219,7 +225,13 @@ func createPublicKeyCallback(connCtx context.Context, sshKeywords *wshrpc.ConnKe
219
225
}
220
226
221
227
func createInteractivePasswordCallbackPrompt (connCtx context.Context , remoteDisplayName string , debugInfo * ConnectionDebugInfo ) func () (secret string , err error ) {
222
- return func () (secret string , err error ) {
228
+ return func () (secret string , outErr error ) {
229
+ defer func () {
230
+ panicErr := panichandler .PanicHandler ("sshclient:password-callback" , recover ())
231
+ if panicErr != nil {
232
+ outErr = panicErr
233
+ }
234
+ }()
223
235
blocklogger .Infof (connCtx , "[conndebug] Password Authentication requested from connection %s...\n " , remoteDisplayName )
224
236
ctx , cancelFn := context .WithTimeout (connCtx , 60 * time .Second )
225
237
defer cancelFn ()
@@ -244,7 +256,13 @@ func createInteractivePasswordCallbackPrompt(connCtx context.Context, remoteDisp
244
256
}
245
257
246
258
func createInteractiveKbdInteractiveChallenge (connCtx context.Context , remoteName string , debugInfo * ConnectionDebugInfo ) func (name , instruction string , questions []string , echos []bool ) (answers []string , err error ) {
247
- return func (name , instruction string , questions []string , echos []bool ) (answers []string , err error ) {
259
+ return func (name , instruction string , questions []string , echos []bool ) (answers []string , outErr error ) {
260
+ defer func () {
261
+ panicErr := panichandler .PanicHandler ("sshclient:kbdinteractive-callback" , recover ())
262
+ if panicErr != nil {
263
+ outErr = panicErr
264
+ }
265
+ }()
248
266
if len (questions ) != len (echos ) {
249
267
return nil , fmt .Errorf ("bad response from server: questions has len %d, echos has len %d" , len (questions ), len (echos ))
250
268
}
@@ -332,7 +350,7 @@ func writeToKnownHosts(knownHostsFile string, newLine string, getUserVerificatio
332
350
return f .Close ()
333
351
}
334
352
335
- func createUnknownKeyVerifier (knownHostsFile string , hostname string , remote string , key ssh.PublicKey ) func () (* userinput.UserInputResponse , error ) {
353
+ func createUnknownKeyVerifier (ctx context. Context , knownHostsFile string , hostname string , remote string , key ssh.PublicKey ) func () (* userinput.UserInputResponse , error ) {
336
354
base64Key := base64 .StdEncoding .EncodeToString (key .Marshal ())
337
355
queryText := fmt .Sprintf (
338
356
"The authenticity of host '%s (%s)' can't be established " +
@@ -349,7 +367,7 @@ func createUnknownKeyVerifier(knownHostsFile string, hostname string, remote str
349
367
Title : "Known Hosts Key Missing" ,
350
368
}
351
369
return func () (* userinput.UserInputResponse , error ) {
352
- ctx , cancelFn := context .WithTimeout (context . Background () , 60 * time .Second )
370
+ ctx , cancelFn := context .WithTimeout (ctx , 60 * time .Second )
353
371
defer cancelFn ()
354
372
resp , err := userinput .GetUserInput (ctx , request )
355
373
if err != nil {
@@ -402,7 +420,7 @@ func lineContainsMatch(line []byte, matches [][]byte) bool {
402
420
return false
403
421
}
404
422
405
- func createHostKeyCallback (sshKeywords * wshrpc.ConnKeywords ) (ssh.HostKeyCallback , HostKeyAlgorithms , error ) {
423
+ func createHostKeyCallback (ctx context. Context , sshKeywords * wshrpc.ConnKeywords ) (ssh.HostKeyCallback , HostKeyAlgorithms , error ) {
406
424
globalKnownHostsFiles := sshKeywords .SshGlobalKnownHostsFile
407
425
userKnownHostsFiles := sshKeywords .SshUserKnownHostsFile
408
426
@@ -473,7 +491,13 @@ func createHostKeyCallback(sshKeywords *wshrpc.ConnKeywords) (ssh.HostKeyCallbac
473
491
}
474
492
}
475
493
476
- waveHostKeyCallback := func (hostname string , remote net.Addr , key ssh.PublicKey ) error {
494
+ waveHostKeyCallback := func (hostname string , remote net.Addr , key ssh.PublicKey ) (outErr error ) {
495
+ defer func () {
496
+ panicErr := panichandler .PanicHandler ("sshclient:wave-hostkey-callback" , recover ())
497
+ if panicErr != nil {
498
+ outErr = panicErr
499
+ }
500
+ }()
477
501
err := basicCallback (hostname , remote , key )
478
502
if err == nil {
479
503
// success
@@ -493,7 +517,7 @@ func createHostKeyCallback(sshKeywords *wshrpc.ConnKeywords) (ssh.HostKeyCallbac
493
517
err := fmt .Errorf ("placeholder, should not be returned" ) // a null value here can cause problems with empty slice
494
518
for _ , filename := range knownHostsFiles {
495
519
newLine := xknownhosts .Line ([]string {xknownhosts .Normalize (hostname )}, key )
496
- getUserVerification := createUnknownKeyVerifier (filename , hostname , remote .String (), key )
520
+ getUserVerification := createUnknownKeyVerifier (ctx , filename , hostname , remote .String (), key )
497
521
err = writeToKnownHosts (filename , newLine , getUserVerification )
498
522
if err == nil {
499
523
break
@@ -623,7 +647,7 @@ func createClientConfig(connCtx context.Context, sshKeywords *wshrpc.ConnKeyword
623
647
authMethods = append (authMethods , authMethod )
624
648
}
625
649
626
- hostKeyCallback , hostKeyAlgorithms , err := createHostKeyCallback (sshKeywords )
650
+ hostKeyCallback , hostKeyAlgorithms , err := createHostKeyCallback (connCtx , sshKeywords )
627
651
if err != nil {
628
652
return nil , err
629
653
}
0 commit comments