Accept and reply to keepalive@openssh.com messages.

This commit is contained in:
Russell Jones 2017-05-29 18:26:35 -07:00
parent abe4284217
commit cfd8a5f17d
2 changed files with 32 additions and 2 deletions

View file

@ -664,9 +664,14 @@ func (s *Server) keyAuth(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permiss
return permissions, nil
}
// HandleRequest is a callback for out of band requests
// HandleRequest is a callback for handling global out-of-band requests.
func (s *Server) HandleRequest(r *ssh.Request) {
log.Debugf("recieved out-of-band request: %+v", r)
switch r.Type {
case teleport.KeepAliveReqType:
s.handleKeepAlive(r)
default:
log.Debugf("[SSH] Discarding %q global request: %+v", r.Type, r)
}
}
// HandleNewChan is called when new channel is opened
@ -1122,6 +1127,22 @@ func (s *Server) handleExec(ch ssh.Channel, req *ssh.Request, ctx *ctx) error {
return nil
}
// handleKeepAlive accepts and replies to keepalive@openssh.com requests.
func (s *Server) handleKeepAlive(req *ssh.Request) {
log.Debugf("[KEEP ALIVE] Received %q: WantReply: %v", req.Type, req.WantReply)
// only reply if the sender actually wants a response
if req.WantReply {
err := req.Reply(true, nil)
if err != nil {
log.Warnf("[KEEP ALIVE] Unable to reply to %q request: %v", req.Type, err)
return
}
}
log.Debugf("[KEEP ALIVE] Replied to %q", req.Type)
}
func replyError(ch ssh.Channel, req *ssh.Request, err error) {
message := []byte(utils.UserMessageFromError(err))
ch.Stderr().Write(message)

View file

@ -1125,6 +1125,15 @@ func (s *SrvSuite) TestLimiter(c *C) {
clt.Close()
}
// TestServerAliveInterval simulates ServerAliveInterval and OpenSSH
// interoperability by sending a keepalive@openssh.com global request to the
// server and expecting a response in return.
func (s *SrvSuite) TestServerAliveInterval(c *C) {
ok, _, err := s.clt.SendRequest(teleport.KeepAliveReqType, true, nil)
c.Assert(err, IsNil)
c.Assert(ok, Equals, true)
}
// upack holds all ssh signing artefacts needed for signing and checking user keys
type upack struct {
// key is a raw private user key