mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-08 19:38:51 +01:00
feat: add user input for kbd-interactive auth
This adds a modal so the user can respond to prompts provided using the keyboard interactive authentication method.
This commit is contained in:
parent
38c6e8f5f8
commit
0a8c8221fd
@ -52,8 +52,8 @@ func createPublicKeyAuth(identityFile string, passphrase string) (ssh.AuthMethod
|
|||||||
return ssh.PublicKeys(signer), nil
|
return ssh.PublicKeys(signer), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createKeyboardInteractiveAuth(password string) ssh.AuthMethod {
|
func createNaiveKbdInteractiveChallenge(password string) func(name, instruction string, questions []string, echos []bool) (answers []string, err error) {
|
||||||
challenge := func(name, instruction string, questions []string, echos []bool) (answers []string, err error) {
|
return func(name, instruction string, questions []string, echos []bool) (answers []string, err error) {
|
||||||
for _, q := range questions {
|
for _, q := range questions {
|
||||||
if strings.Contains(strings.ToLower(q), "password") {
|
if strings.Contains(strings.ToLower(q), "password") {
|
||||||
answers = append(answers, password)
|
answers = append(answers, password)
|
||||||
@ -63,6 +63,42 @@ func createKeyboardInteractiveAuth(password string) ssh.AuthMethod {
|
|||||||
}
|
}
|
||||||
return answers, nil
|
return answers, nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func createInteractiveKbdInteractiveChallenge() func(name, instruction string, questions []string, echos []bool) (answers []string, err error) {
|
||||||
|
return func(name, instruction string, questions []string, echos []bool) (answers []string, err error) {
|
||||||
|
if len(questions) != len(echos) {
|
||||||
|
return nil, fmt.Errorf("bad response from server: questions has len %d, echos has len %d", len(questions), len(echos))
|
||||||
|
}
|
||||||
|
for i, question := range questions {
|
||||||
|
echo := echos[i]
|
||||||
|
answer, err := promptChallengeQuestion(question, echo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
answers = append(answers, answer)
|
||||||
|
}
|
||||||
|
return answers, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func promptChallengeQuestion(question string, echo bool) (answer string, err error) {
|
||||||
|
ctx, cancelFn := context.WithTimeout(context.Background(), 60*time.Second)
|
||||||
|
defer cancelFn()
|
||||||
|
request := &sstore.UserInputRequestType{
|
||||||
|
ResponseType: "text",
|
||||||
|
QueryText: question,
|
||||||
|
Title: "Keyboard Interactive Authentication",
|
||||||
|
}
|
||||||
|
response, err := sstore.MainBus.GetUserInput(request, ctx)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return response.Text, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func createKeyboardInteractiveAuth(password string) ssh.AuthMethod {
|
||||||
|
challenge := createInteractiveKbdInteractiveChallenge()
|
||||||
return ssh.KeyboardInteractive(challenge)
|
return ssh.KeyboardInteractive(challenge)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user