Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/devspace/services/proxycommands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package proxycommands
import (
"encoding/base64"
"fmt"
"strings"

sshpkg "github.com/gliderlabs/ssh"
"github.com/loft-sh/devspace/pkg/devspace/config/loader"
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
Expand All @@ -13,7 +15,6 @@ import (
"github.com/loft-sh/devspace/pkg/devspace/services/targetselector"
"github.com/loft-sh/devspace/pkg/util/tomb"
"github.com/pkg/errors"
"strings"
)

var DefaultRemotePort = 10567
Expand Down
9 changes: 5 additions & 4 deletions pkg/devspace/services/ssh/config.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package ssh

import (
"github.com/loft-sh/devspace/pkg/util/log"
"github.com/loft-sh/devspace/pkg/util/scanner"
"github.com/mitchellh/go-homedir"
"github.com/pkg/errors"
"io"
"os"
"path/filepath"
"strconv"
"strings"
"sync"

"github.com/loft-sh/devspace/pkg/util/log"
"github.com/loft-sh/devspace/pkg/util/scanner"
"github.com/mitchellh/go-homedir"
"github.com/pkg/errors"
)

var configLock sync.Mutex
Expand Down
58 changes: 34 additions & 24 deletions pkg/devspace/services/ssh/keys.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
package ssh

import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/base64"
"encoding/pem"
"github.com/loft-sh/devspace/pkg/devspace/config/constants"
"github.com/mitchellh/go-homedir"
"github.com/pkg/errors"
"golang.org/x/crypto/ssh"
"os"
"path/filepath"
"strings"
"sync"

"github.com/loft-sh/devspace/pkg/devspace/config/constants"
"github.com/mitchellh/go-homedir"
"github.com/pkg/errors"
"golang.org/x/crypto/ssh"
)

var (
DevSpaceSSHFolder = "ssh"
DevSpaceSSHHostKeyFile = "id_devspace_host_rsa"
DevSpaceSSHPrivateKeyFile = "id_devspace_rsa"
DevSpaceSSHPublicKeyFile = "id_devspace_rsa.pub"
DevSpaceSSHHostKeyFile = "id_devspace_host_ecdsa"
DevSpaceSSHPrivateKeyFile = "id_devspace_ecdsa"
DevSpaceSSHPublicKeyFile = "id_devspace_ecdsa.pub"
)

func init() {
Expand All @@ -33,32 +35,40 @@ func init() {

var keyLock sync.Mutex

func MakeHostKey() (string, error) {
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
func generatePrivateKey() (*ecdsa.PrivateKey, string, error) {
privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
return "", err
return nil, "", err
}

// generate and write private key as PEM
var privKeyBuf strings.Builder
privateKeyPEM := &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(privateKey)}
if err := pem.Encode(&privKeyBuf, privateKeyPEM); err != nil {
return "", err
var privateKeyBuf strings.Builder
b, err := x509.MarshalPKCS8PrivateKey(privateKey)
if err != nil {
return nil, "", err
}
privateKeyPEM := &pem.Block{
Type: "PRIVATE KEY",
Bytes: b,
}
if err := pem.Encode(&privateKeyBuf, privateKeyPEM); err != nil {
return nil, "", err
}

return privKeyBuf.String(), nil
return privateKey, privateKeyBuf.String(), nil
}

func MakeSSHKeyPair() (string, string, error) {
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
func MakeHostKey() (string, error) {
_, privKeyStr, err := generatePrivateKey()
if err != nil {
return "", "", err
return "", err
}
return privKeyStr, nil
}

// generate and write private key as PEM
var privKeyBuf strings.Builder
privateKeyPEM := &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(privateKey)}
if err := pem.Encode(&privKeyBuf, privateKeyPEM); err != nil {
func MakeSSHKeyPair() (string, string, error) {
privateKey, privKeyStr, err := generatePrivateKey()
if err != nil {
return "", "", err
}

Expand All @@ -70,7 +80,7 @@ func MakeSSHKeyPair() (string, string, error) {

var pubKeyBuf strings.Builder
pubKeyBuf.Write(ssh.MarshalAuthorizedKey(pub))
return pubKeyBuf.String(), privKeyBuf.String(), nil
return pubKeyBuf.String(), privKeyStr, nil
}

func getHostKey() (string, error) {
Expand Down