(ctx context.Context, knownHostsFile string, hostname string, remote string, key ssh.PublicKey)
| 515 | } |
| 516 | |
| 517 | func 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 | |
| 547 | func createMissingKnownHostsVerifier(knownHostsFile string, hostname string, remote string, key ssh.PublicKey) func() (*userinput.UserInputResponse, error) { |
| 548 | base64Key := base64.StdEncoding.EncodeToString(key.Marshal()) |
no test coverage detected