Skip to content

Commit

Permalink
server: main, lib: ssh: Remove SSH keys generation
Browse files Browse the repository at this point in the history
  • Loading branch information
ish-hcc committed Dec 4, 2024
1 parent c5b110e commit 1c16cdd
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 77 deletions.
6 changes: 0 additions & 6 deletions server/cmd/cm-honeybee/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/cloud-barista/cm-honeybee/server/db"
"github.com/cloud-barista/cm-honeybee/server/lib/config"
"github.com/cloud-barista/cm-honeybee/server/lib/rsautil"
"github.com/cloud-barista/cm-honeybee/server/lib/ssh"
"github.com/cloud-barista/cm-honeybee/server/pkg/api/rest/controller"
"github.com/cloud-barista/cm-honeybee/server/pkg/api/rest/server"
"github.com/jollaman999/utils/fileutil"
Expand Down Expand Up @@ -51,11 +50,6 @@ func init() {
logger.Panicln(logger.ERROR, false, err.Error())
}

err = ssh.GenerateSSHIdentityFile()
if err != nil {
logger.Panicln(logger.ERROR, false, err.Error())
}

controller.OkMessage.Message = "API server is not ready"

var wg sync.WaitGroup
Expand Down
71 changes: 0 additions & 71 deletions server/lib/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,77 +53,6 @@ var sourceFiles embed.FS

var homeDir string

func GenerateSSHIdentityFile() error {
var err error

homeDir, err = os.UserHomeDir()
if err != nil {
return fmt.Errorf("failed to determine user home directory: %v", err)
}
sshDir := filepath.Join(homeDir, ".ssh")
privateKeyPath := filepath.Join(sshDir, "id_rsa")
publicKeyPath := filepath.Join(sshDir, "id_rsa.pub")

_, err = os.Stat(privateKeyPath)
if err == nil {
return nil
}

err = os.MkdirAll(sshDir, 0700)
if err != nil {
return err
}

privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
return fmt.Errorf("failed to generate ssh private key file: %v", err)
}

privateKeyPEM := &pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: x509.MarshalPKCS1PrivateKey(privateKey),
}

privateKeyFile, err := os.OpenFile(privateKeyPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return fmt.Errorf("failed to generate ssh private key file: %v", err)
}
defer func() {
_ = privateKeyFile.Close()
}()

err = pem.Encode(privateKeyFile, privateKeyPEM)
if err != nil {
return fmt.Errorf("failed to store ssh private key file: %v", err)
}

publicKey := &privateKey.PublicKey
publicKeyBytes, err := x509.MarshalPKIXPublicKey(publicKey)
if err != nil {
return fmt.Errorf("failed to generate ssh public key file: %v", err)
}

publicKeyPEM := &pem.Block{
Type: "RSA PUBLIC KEY",
Bytes: publicKeyBytes,
}

publicKeyFile, err := os.OpenFile(publicKeyPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return fmt.Errorf("failed to generate ssh public key file: %v", err)
}
defer func() {
_ = publicKeyFile.Close()
}()

err = pem.Encode(publicKeyFile, publicKeyPEM)
if err != nil {
return fmt.Errorf("failed to store ssh public key file: %v", err)
}

return nil
}

func DefaultSSHOptions() Options {
return Options{
SSHPort: 22,
Expand Down

0 comments on commit 1c16cdd

Please sign in to comment.