MCPcopy
hub / github.com/wavetermdev/waveterm / createUnknownKeyVerifier

Function createUnknownKeyVerifier

pkg/remote/sshclient.go:517–545  ·  view source on GitHub ↗
(ctx context.Context, knownHostsFile string, hostname string, remote string, key ssh.PublicKey)

Source from the content-addressed store, hash-verified

515}
516
517func createUnknownKeyVerifier(ctx context.Context, knownHostsFile string, hostname string, remote string, key ssh.PublicKey) func() (*userinput.UserInputResponse, error) {
518 base64Key := base64.StdEncoding.EncodeToString(key.Marshal())
519 queryText := fmt.Sprintf(
520 "The authenticity of host '%s (%s)' can't be established "+
521 "as it **does not exist in any checked known_hosts files**. "+
522 "The host you are attempting to connect to provides this %s key: \n"+
523 "%s.\n\n"+
524 "**Would you like to continue connecting?** If so, the key will be permanently "+
525 "added to the file %s "+
526 "to protect from future man-in-the-middle attacks.", hostname, remote, key.Type(), base64Key, knownHostsFile)
527 request := &userinput.UserInputRequest{
528 ResponseType: "confirm",
529 QueryText: queryText,
530 Markdown: true,
531 Title: "Known Hosts Key Missing",
532 }
533 return func() (*userinput.UserInputResponse, error) {
534 ctx, cancelFn := context.WithTimeout(ctx, 60*time.Second)
535 defer cancelFn()
536 resp, err := userinput.GetUserInput(ctx, request)
537 if err != nil {
538 return nil, err
539 }
540 if !resp.Confirm {
541 return nil, fmt.Errorf("user selected no")
542 }
543 return resp, nil
544 }
545}
546
547func createMissingKnownHostsVerifier(knownHostsFile string, hostname string, remote string, key ssh.PublicKey) func() (*userinput.UserInputResponse, error) {
548 base64Key := base64.StdEncoding.EncodeToString(key.Marshal())

Callers 1

createHostKeyCallbackFunction · 0.85

Calls 2

GetUserInputFunction · 0.92
TypeMethod · 0.80

Tested by

no test coverage detected