Skip to content

Commit 7bb32ee

Browse files
committed
ssh: Use ed25519 algorithm instead ECDSA
Key generated using ecdsa algorithm is causing issue for podman remote connection on podman desktop side because the library they consume doesn't have support for this algorithm. This PR is switching the ecdsa to ed25519 with openssh type which is supported by the library consumed in podman desktop. [0] podman-desktop/podman-desktop#8351 [1] mscdex/ssh2#1375
1 parent 831c5f9 commit 7bb32ee

File tree

6 files changed

+13
-14
lines changed

6 files changed

+13
-14
lines changed

pkg/crc/constants/constants.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ func EnsureBaseDirectoriesExist() error {
174174
}
175175

176176
func GetPublicKeyPath() string {
177-
return filepath.Join(MachineInstanceDir, DefaultName, "id_ecdsa.pub")
177+
return filepath.Join(MachineInstanceDir, DefaultName, "id_ed25519.pub")
178178
}
179179

180180
func GetPrivateKeyPath() string {
181-
return filepath.Join(MachineInstanceDir, DefaultName, "id_ecdsa")
181+
return filepath.Join(MachineInstanceDir, DefaultName, "id_ed25519")
182182
}
183183

184184
func GetHostDockerSocketPath() string {

pkg/crc/ssh/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func clientConfig(user string, keys []string) (*ssh.ClientConfig, error) {
5050

5151
privateKey, err := ssh.ParsePrivateKey(key)
5252
if err != nil {
53+
log.Debugf("Failed to parse private key: %v\n", err)
5354
return nil, err
5455
}
5556

pkg/crc/ssh/keys.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package ssh
33
import (
44
"bufio"
55
"bytes"
6-
"crypto/ecdsa"
7-
"crypto/elliptic"
6+
"crypto"
7+
"crypto/ed25519"
88
"crypto/rand"
9-
"crypto/x509"
9+
"encoding/pem"
1010
"errors"
1111
"fmt"
1212
"os"
@@ -33,23 +33,23 @@ type KeyPair struct {
3333
// This will return a private & public key encoded as DER.
3434
func NewKeyPair() (keyPair *KeyPair, err error) {
3535

36-
priv, err := ecdsa.GenerateKey(elliptic.P521(), rand.Reader)
36+
pub, priv, err := ed25519.GenerateKey(rand.Reader)
3737
if err != nil {
3838
return nil, ErrKeyGeneration
3939
}
4040

41-
privDer, err := x509.MarshalPKCS8PrivateKey(priv)
41+
privMar, err := gossh.MarshalPrivateKey(crypto.PrivateKey(priv), "")
4242
if err != nil {
4343
return nil, ErrPrivateKey
4444
}
4545

46-
pubSSH, err := gossh.NewPublicKey(&priv.PublicKey)
46+
pubSSH, err := gossh.NewPublicKey(pub)
4747
if err != nil {
4848
return nil, ErrPublicKey
4949
}
5050

5151
return &KeyPair{
52-
PrivateKey: privDer,
52+
PrivateKey: pem.EncodeToMemory(privMar),
5353
PublicKey: gossh.MarshalAuthorizedKey(pubSSH),
5454
}, nil
5555
}

pkg/crc/ssh/keys_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func TestNewKeyPair(t *testing.T) {
1111
t.Fatal(err)
1212
}
1313

14-
if privPem := pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Headers: nil, Bytes: pair.PrivateKey}); len(privPem) == 0 {
14+
if privPem := pem.EncodeToMemory(&pem.Block{Type: "OPENSSH PRIVATE KEY", Headers: nil, Bytes: pair.PrivateKey}); len(privPem) == 0 {
1515
t.Fatal("No PEM returned")
1616
}
1717
}

pkg/crc/ssh/keys_unix.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package ssh
55

66
import (
7-
"encoding/pem"
87
"os"
98
)
109

@@ -17,7 +16,7 @@ func (kp *KeyPair) WriteToFile(privateKeyPath string, publicKeyPath string) erro
1716
}{
1817
{
1918
File: privateKeyPath,
20-
Value: pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Headers: nil, Bytes: kp.PrivateKey}),
19+
Value: kp.PrivateKey,
2120
},
2221
{
2322
File: publicKeyPath,

pkg/crc/ssh/keys_windows.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package ssh
22

33
import (
4-
"encoding/pem"
54
"os"
65

76
"github.com/hectane/go-acl"
@@ -35,7 +34,7 @@ func (kp *KeyPair) WriteToFile(privateKeyPath string, publicKeyPath string) erro
3534
}{
3635
{
3736
File: privateKeyPath,
38-
Value: pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Headers: nil, Bytes: kp.PrivateKey}),
37+
Value: kp.PrivateKey,
3938
},
4039
{
4140
File: publicKeyPath,

0 commit comments

Comments
 (0)