diff --git a/pkg/crc/constants/constants.go b/pkg/crc/constants/constants.go index 6ffb8c6af9..bc4c78056a 100644 --- a/pkg/crc/constants/constants.go +++ b/pkg/crc/constants/constants.go @@ -174,11 +174,11 @@ func EnsureBaseDirectoriesExist() error { } func GetPublicKeyPath() string { - return filepath.Join(MachineInstanceDir, DefaultName, "id_ecdsa.pub") + return filepath.Join(MachineInstanceDir, DefaultName, "id_ed25519.pub") } func GetPrivateKeyPath() string { - return filepath.Join(MachineInstanceDir, DefaultName, "id_ecdsa") + return filepath.Join(MachineInstanceDir, DefaultName, "id_ed25519") } func GetHostDockerSocketPath() string { diff --git a/pkg/crc/ssh/keys.go b/pkg/crc/ssh/keys.go index 24e3a8a9f3..bd172787fe 100644 --- a/pkg/crc/ssh/keys.go +++ b/pkg/crc/ssh/keys.go @@ -3,8 +3,7 @@ package ssh import ( "bufio" "bytes" - "crypto/ecdsa" - "crypto/elliptic" + "crypto/ed25519" "crypto/rand" "crypto/x509" "errors" @@ -14,13 +13,11 @@ import ( "strings" "github.com/crc-org/crc/v2/pkg/crc/constants" - gossh "golang.org/x/crypto/ssh" ) var ( ErrKeyGeneration = errors.New("Unable to generate key") ErrPrivateKey = errors.New("Unable to marshal private key") - ErrPublicKey = errors.New("Unable to convert public key") ErrUnableToWriteFile = errors.New("Unable to write file") ) @@ -33,7 +30,7 @@ type KeyPair struct { // This will return a private & public key encoded as DER. func NewKeyPair() (keyPair *KeyPair, err error) { - priv, err := ecdsa.GenerateKey(elliptic.P521(), rand.Reader) + pubSSH, priv, err := ed25519.GenerateKey(rand.Reader) if err != nil { return nil, ErrKeyGeneration } @@ -42,15 +39,9 @@ func NewKeyPair() (keyPair *KeyPair, err error) { if err != nil { return nil, ErrPrivateKey } - - pubSSH, err := gossh.NewPublicKey(&priv.PublicKey) - if err != nil { - return nil, ErrPublicKey - } - return &KeyPair{ PrivateKey: privDer, - PublicKey: gossh.MarshalAuthorizedKey(pubSSH), + PublicKey: pubSSH, }, nil }