diff --git a/server/cmd/cm-honeybee/main.go b/server/cmd/cm-honeybee/main.go index e4bc9b1..e19e62c 100644 --- a/server/cmd/cm-honeybee/main.go +++ b/server/cmd/cm-honeybee/main.go @@ -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" @@ -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 diff --git a/server/lib/ssh/ssh.go b/server/lib/ssh/ssh.go index e11caae..daabb42 100644 --- a/server/lib/ssh/ssh.go +++ b/server/lib/ssh/ssh.go @@ -2,12 +2,8 @@ package ssh import ( "bytes" - "crypto/rand" - "crypto/rsa" - "crypto/x509" "embed" "encoding/json" - "encoding/pem" "errors" "fmt" "github.com/cloud-barista/cm-honeybee/server/lib/config" @@ -53,77 +49,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,