diff --git a/helper/ssh/key_pair.go b/helper/ssh/key_pair.go index 55071cf63..f6852080d 100644 --- a/helper/ssh/key_pair.go +++ b/helper/ssh/key_pair.go @@ -2,6 +2,7 @@ package ssh import ( "bytes" + "crypto" "crypto/dsa" "crypto/ecdsa" "crypto/elliptic" @@ -12,7 +13,6 @@ import ( "fmt" "strings" - "golang.org/x/crypto/ed25519" gossh "golang.org/x/crypto/ssh" ) @@ -66,17 +66,11 @@ func KeyPairFromPrivateKey(config FromPrivateKeyConfig) (KeyPair, error) { } switch pk := privateKey.(type) { - case *rsa.PrivateKey: - publicKey, err := gossh.NewPublicKey(&pk.PublicKey) - if err != nil { - return KeyPair{}, err - } - return KeyPair{ - PrivateKeyPemBlock: config.RawPrivateKeyPemBlock, - PublicKeyAuthorizedKeysLine: authorizedKeysLine(publicKey, config.Name), - }, nil - case *ecdsa.PrivateKey: - publicKey, err := gossh.NewPublicKey(&pk.PublicKey) + case crypto.Signer: + // crypto.Signer is implemented by ecdsa.PrivateKey, + // ed25519.PrivateKey, and rsa.PrivateKey - separate cases + // for each PrivateKey type would be redundant. + publicKey, err := gossh.NewPublicKey(pk.Public()) if err != nil { return KeyPair{}, err } @@ -93,15 +87,6 @@ func KeyPairFromPrivateKey(config FromPrivateKeyConfig) (KeyPair, error) { PrivateKeyPemBlock: config.RawPrivateKeyPemBlock, PublicKeyAuthorizedKeysLine: authorizedKeysLine(publicKey, config.Name), }, nil - case *ed25519.PrivateKey: - publicKey, err := gossh.NewPublicKey(pk.Public()) - if err != nil { - return KeyPair{}, err - } - return KeyPair{ - PrivateKeyPemBlock: config.RawPrivateKeyPemBlock, - PublicKeyAuthorizedKeysLine: authorizedKeysLine(publicKey, config.Name), - }, nil } return KeyPair{}, fmt.Errorf("Cannot parse existing SSH key pair - unknown key pair type")