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

Function createMissingKnownHostsVerifier

pkg/remote/sshclient.go:547–576  ·  view source on GitHub ↗
(knownHostsFile string, hostname string, remote string, key ssh.PublicKey)

Source from the content-addressed store, hash-verified

545}
546
547func createMissingKnownHostsVerifier(knownHostsFile string, hostname string, remote string, key ssh.PublicKey) func() (*userinput.UserInputResponse, error) {
548 base64Key := base64.StdEncoding.EncodeToString(key.Marshal())
549 queryText := fmt.Sprintf(
550 "The authenticity of host '%s (%s)' can't be established "+
551 "as **no known_hosts files could be found**. "+
552 "The host you are attempting to connect to provides this %s key: \n"+
553 "%s.\n\n"+
554 "**Would you like to continue connecting?** If so: \n"+
555 "- %s will be created \n"+
556 "- the key will be added to %s\n\n"+
557 "This will protect from future man-in-the-middle attacks.", hostname, remote, key.Type(), base64Key, knownHostsFile, knownHostsFile)
558 request := &userinput.UserInputRequest{
559 ResponseType: "confirm",
560 QueryText: queryText,
561 Markdown: true,
562 Title: "Known Hosts File Missing",
563 }
564 return func() (*userinput.UserInputResponse, error) {
565 ctx, cancelFn := context.WithTimeout(context.Background(), 60*time.Second)
566 defer cancelFn()
567 resp, err := userinput.GetUserInput(ctx, request)
568 if err != nil {
569 return nil, err
570 }
571 if !resp.Confirm {
572 return nil, fmt.Errorf("user selected no")
573 }
574 return resp, nil
575 }
576}
577
578func lineContainsMatch(line []byte, matches [][]byte) bool {
579 for _, match := range matches {

Callers 1

createHostKeyCallbackFunction · 0.85

Calls 2

GetUserInputFunction · 0.92
TypeMethod · 0.80

Tested by

no test coverage detected