mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-12 15:17:16 +03:00
sshd: Apply read deadline to handler
This commit is contained in:
parent
de89c87946
commit
61b525ae54
2
go.mod
2
go.mod
@ -8,3 +8,5 @@ require (
|
||||
golang.org/x/crypto v0.0.0-20190320223903-b7391e95e576
|
||||
golang.org/x/sys v0.0.0-20190321052220-f7bb7a8bee54
|
||||
)
|
||||
|
||||
go 1.13
|
||||
|
10
sshd/net.go
10
sshd/net.go
@ -33,8 +33,11 @@ func (l *SSHListener) handleConn(conn net.Conn) (*Terminal, error) {
|
||||
conn = ReadLimitConn(conn, l.RateLimit())
|
||||
}
|
||||
|
||||
// Handshake shouldn't take more than 10 seconds
|
||||
conn.SetReadDeadline(time.Now().Add(10 * time.Second))
|
||||
// If the connection doesn't write anything back for too long before we get
|
||||
// a valid session, it should be dropped.
|
||||
var handleTimeout = 20 * time.Second
|
||||
conn.SetReadDeadline(time.Now().Add(handleTimeout))
|
||||
defer conn.SetReadDeadline(time.Time{})
|
||||
|
||||
// Upgrade TCP connection to SSH connection
|
||||
sshConn, channels, requests, err := ssh.NewServerConn(conn, l.config)
|
||||
@ -42,9 +45,6 @@ func (l *SSHListener) handleConn(conn net.Conn) (*Terminal, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// clear the deadline
|
||||
conn.SetDeadline(time.Time{})
|
||||
|
||||
// FIXME: Disconnect if too many faulty requests? (Avoid DoS.)
|
||||
go ssh.DiscardRequests(requests)
|
||||
return NewSession(sshConn, channels)
|
||||
|
Loading…
x
Reference in New Issue
Block a user