From be1f6b79f162e3b65e47f5f102d2bd91075f930b Mon Sep 17 00:00:00 2001 From: Rafael Garcia Date: Sun, 11 Aug 2013 09:46:28 -0700 Subject: [PATCH] communicator/ssh: ability to use a password-protected key --- communicator/ssh/keychain.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/communicator/ssh/keychain.go b/communicator/ssh/keychain.go index 8e409cf19..4c794322d 100644 --- a/communicator/ssh/keychain.go +++ b/communicator/ssh/keychain.go @@ -26,6 +26,18 @@ func (k *SimpleKeychain) AddPEMKey(key string) (err error) { return } +func (k *SimpleKeychain) AddPEMKeyPassword(key string, password string) (err error) { + block, _ := pem.Decode([]byte(key)) + bytes, _ := x509.DecryptPEMBlock(block, []byte(password)) + rsakey, err := x509.ParsePKCS1PrivateKey(bytes) + if err != nil { + return + } + + k.keys = append(k.keys, rsakey) + return +} + // Key method for ssh.ClientKeyring interface func (k *SimpleKeychain) Key(i int) (interface{}, error) { if i < 0 || i >= len(k.keys) {