From f356858f029d39f1816824e478f22366b5a8b02c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Sat, 10 Apr 2021 10:53:02 +0200 Subject: [PATCH] Enable using saved host key --- honeypot/server.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/honeypot/server.go b/honeypot/server.go index fdc48ea..ea32878 100644 --- a/honeypot/server.go +++ b/honeypot/server.go @@ -4,8 +4,11 @@ import ( "context" "io" "net" + "os" "time" + gossh "golang.org/x/crypto/ssh" + "github.uio.no/torjus/apiary/config" "github.com/gliderlabs/ssh" @@ -34,6 +37,25 @@ func NewHoneypotServer(cfg config.HoneypotConfig, store store.LoginAttemptStore) PasswordHandler: hs.passwordHandler, ConnCallback: hs.connCallback, Handler: handler, + Version: "OpenSSH_7.4p1 Debian-10+deb9u6", + } + + if cfg.HostKeyPath != "" { + f, err := os.Open(cfg.HostKeyPath) + if err != nil { + return nil, err + } + pemBytes, err := io.ReadAll(f) + if err != nil { + return nil, err + } + signer, err := gossh.ParsePrivateKey(pemBytes) + if err != nil { + return nil, err + } + + hs.sshServer.AddHostKey(signer) + } return &hs, nil