add option to drop host key msg (#140)

* add option to drop host key msg

* fix lint
This commit is contained in:
Boshi Lian 2023-02-13 07:18:48 -08:00 • committed by GitHub
parent 3198e767d7
commit 53d4789035
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 2 deletions

View file

@ -19,7 +19,8 @@ type daemon struct {
lis net.Listener
loginGraceTime time.Duration
recorddir string
recorddir string
filterHostkeysReqeust bool
}
func newDaemon(ctx *cli.Context) (*daemon, error) {
@ -147,6 +148,8 @@ func (d *daemon) run() error {
log.Infof("ssh connection pipe created %v (username [%v]) -> %v (username [%v])", p.DownstreamConnMeta().RemoteAddr(), p.DownstreamConnMeta().User(), p.UpstreamConnMeta().RemoteAddr(), p.UpstreamConnMeta().User())
var uphook func([]byte) ([]byte, error)
var downhook func([]byte) ([]byte, error)
if d.recorddir != "" {
recorddir := path.Join(d.recorddir, p.DownstreamConnMeta().User())
err = os.MkdirAll(recorddir, 0700)
@ -164,7 +167,22 @@ func (d *daemon) run() error {
uphook = recorder.loggingTty
}
err = p.WaitWithHook(uphook, nil)
if d.filterHostkeysReqeust {
uphook = func(b []byte) ([]byte, error) {
if b[0] == 80 {
var x struct {
RequestName string `sshtype:"80"`
}
_ = ssh.Unmarshal(b, &x)
if x.RequestName == "hostkeys-prove-00@openssh.com" || x.RequestName == "hostkeys-00@openssh.com" {
return nil, nil
}
}
return b, nil
}
}
err = p.WaitWithHook(uphook, downhook)
log.Infof("connection from %v closed reason: %v", c.RemoteAddr(), err)
}(conn)

View file

@ -127,6 +127,12 @@ func main() {
Usage: "display a banner from file before authentication",
EnvVars: []string{"SSHPIPERD_BANNERFILE"},
},
&cli.BoolFlag{
Name: "drop-hostkeys-message",
Value: false,
Usage: "filter out hostkeys-00@openssh.com which cause client side warnings",
EnvVars: []string{"SSHPIPERD_DROP_HOSTKEYS_MESSAGE"},
},
},
Action: func(ctx *cli.Context) error {
level, err := log.ParseLevel(ctx.String("log-level"))
@ -201,6 +207,7 @@ func main() {
}
d.recorddir = ctx.String("typescript-log-dir")
d.filterHostkeysReqeust = ctx.Bool("drop-hostkeys-message")
go func() {
quit <- d.run()