Enable using saved host key

This commit is contained in:
Torjus Håkestad 2021-04-10 10:53:02 +02:00
parent 1d0d1aa20f
commit f356858f02

View File

@ -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