Commit 93a8c153 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

communicator/ssh: add keyboard interactive auth [GH-121]

parent a5a7915a
package ssh
import "log"
// An implementation of ssh.ClientPassword so that you can use a static
// string password for the password to ClientAuthPassword.
type Password string
......@@ -7,3 +9,24 @@ type Password string
func (p Password) Password(user string) (string, error) {
return string(p), nil
}
// An implementation of ssh.ClientKeyboardInteractive that simply sends
// back the password for all questions. The questions are logged.
type PasswordKeyboardInteractive string
func (p PasswordKeyboardInteractive) Challenge(user, instruction string, questions []string, echos []bool) ([]string, error) {
log.Printf("Keyboard interactive challenge: ")
log.Printf("-- User: %s", user)
log.Printf("-- Instructions: %s", instruction)
for i, question := range questions {
log.Printf("-- Question %d: %s", i+1, question)
}
// Just send the password back for all questions
answers := make([]string, len(questions))
for i, _ := range answers {
answers[i] = string(p)
}
return answers, nil
}
......@@ -2,6 +2,7 @@ package ssh
import (
"code.google.com/p/go.crypto/ssh"
"reflect"
"testing"
)
......@@ -24,3 +25,24 @@ func TestPasswordPassword(t *testing.T) {
t.Fatalf("invalid password: %s", result)
}
}
func TestPasswordKeyboardInteractive_Impl(t *testing.T) {
var raw interface{}
raw = PasswordKeyboardInteractive("foo")
if _, ok := raw.(ssh.ClientKeyboardInteractive); !ok {
t.Fatal("PasswordKeyboardInteractive must implement ClientKeyboardInteractive")
}
}
func TestPasswordKeybardInteractive_Challenge(t *testing.T) {
p := PasswordKeyboardInteractive("foo")
result, err := p.Challenge("foo", "bar", []string{"one", "two"}, nil)
if err != nil {
t.Fatalf("err not nil: %s", err)
}
if !reflect.DeepEqual(result, []string{"foo", "foo"}) {
t.Fatalf("invalid password: %#v", result)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment