From 1b12a22fc546b6791fe4e05ec249766734fff933 Mon Sep 17 00:00:00 2001 From: Yves Biener Date: Mon, 7 Oct 2024 16:47:02 +0200 Subject: [PATCH] mod: add configuration for key.dir and key.name --- internal/serve/serve.go | 8 ++++---- main.go | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/serve/serve.go b/internal/serve/serve.go index 6786e1b..119fe8f 100644 --- a/internal/serve/serve.go +++ b/internal/serve/serve.go @@ -34,10 +34,10 @@ func setupLogging() { // all if no user is given) the application `name` with the provided arguments // `args` as the ssh session. The ssh session will always allocate an pty // (necessary for tui applications). -func setupSshServer(host string, port string, users map[string]string, name string, args []string) (*ssh.Server, error) { +func setupSshServer(host string, port string, host_key_path string, users map[string]string, name string, args []string) (*ssh.Server, error) { return wish.NewServer( wish.WithAddress(net.JoinHostPort(host, port)), - wish.WithHostKeyPath(".ssh/ssh_host_ed25519_key"), + wish.WithHostKeyPath(host_key_path), wish.WithPublicKeyAuth(func(_ ssh.Context, key ssh.PublicKey) bool { if len(users) == 0 { // no users provided, meaning there is no user authentication, everyone is allowed to connect @@ -69,9 +69,9 @@ func setupSshServer(host string, port string, users map[string]string, name stri } // Serve an ssh application using the provided arguments. -func Serve(host string, port string, users map[string]string, name string, args []string) { +func Serve(host string, port string, host_key_path string, users map[string]string, name string, args []string) { setupLogging() - srv, err := setupSshServer(host, port, users, name, args) + srv, err := setupSshServer(host, port, host_key_path, users, name, args) if err != nil { log.Error("Could not start server", "error", err) } diff --git a/main.go b/main.go index 7b6dd80..c37f264 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,8 @@ func createDefaultConfig() { viper.SetDefault("host", "127.0.0.1") viper.SetDefault("port", "8022") viper.SetDefault("users", map[string]string{}) + viper.SetDefault("key.dir", ".ssh") + viper.SetDefault("key.name", "ssh_ed25519_key") viper.SetDefault("app.name", "echo") viper.SetDefault("app.args", []string{"Hello World"}) } @@ -58,6 +60,7 @@ func main() { serve.Serve( viper.GetString("host"), viper.GetString("port"), + fmt.Sprintf("%s/%s", viper.GetString("key.dir"), viper.GetString("key.name")), viper.GetStringMapString("users"), viper.GetString("app.name"), viper.GetStringSlice("app.args"),