communicator/ssh: ability to use a password-protected key
This commit is contained in:
parent
82e69b97f1
commit
be1f6b79f1
|
@ -26,6 +26,18 @@ func (k *SimpleKeychain) AddPEMKey(key string) (err error) {
|
||||||
return
|
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
|
// Key method for ssh.ClientKeyring interface
|
||||||
func (k *SimpleKeychain) Key(i int) (interface{}, error) {
|
func (k *SimpleKeychain) Key(i int) (interface{}, error) {
|
||||||
if i < 0 || i >= len(k.keys) {
|
if i < 0 || i >= len(k.keys) {
|
||||||
|
|
Loading…
Reference in New Issue