Merge pull request #273 from rgarcia/password-key

communicator/ssh: ability to use a password-protected key
This commit is contained in:
Mitchell Hashimoto 2013-08-11 16:13:53 -07:00
commit 3c5565c541
1 changed files with 12 additions and 0 deletions

View File

@ -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) {