From 82afd9492a7d8b7dee4e92e90a70e5fe30b6681e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Cluseau?= Date: Sun, 17 Dec 2023 15:33:56 +0100 Subject: [PATCH] ssh: load more host key formats than rsa --- ssh.go | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/ssh.go b/ssh.go index b053c89..cb9386b 100644 --- a/ssh.go +++ b/ssh.go @@ -23,18 +23,28 @@ func startSSH(cfg *config.Config) { PublicKeyCallback: sshCheckPubkey, } - pkBytes, err := os.ReadFile("/id_rsa") // TODO configurable - if err != nil { - fatalf("ssh: failed to load private key: %v", err) + hostKeyLoaded := false + + for _, format := range []string{"rsa", "dsa", "ecdsa", "ed25519"} { + pkBytes, err := os.ReadFile("/id_" + format) + if err != nil { + log.Printf("ssh : failed to load %s host key: %v", format, err) + continue + } + + pk, err := ssh.ParsePrivateKey(pkBytes) + if err != nil { + log.Printf("ssh: failed to parse %s host key: %v", format, err) + continue + } + + sshConfig.AddHostKey(pk) } - pk, err := ssh.ParsePrivateKey(pkBytes) - if err != nil { - fatalf("ssh: failed to parse private key: %v", err) + if !hostKeyLoaded { + fatalf("ssh: failed to load any host key") } - sshConfig.AddHostKey(pk) - sshBind := ":22" // TODO configurable listener, err := net.Listen("tcp", sshBind) if err != nil {