mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-04-13 15:47:17 +03:00
#315: set a 10 sec deadline for clients to complete the handshake
This commit is contained in:
parent
0a122be81e
commit
de89c87946
@ -2,6 +2,7 @@ package sshd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/shazow/rateio"
|
"github.com/shazow/rateio"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
@ -32,12 +33,18 @@ func (l *SSHListener) handleConn(conn net.Conn) (*Terminal, error) {
|
|||||||
conn = ReadLimitConn(conn, l.RateLimit())
|
conn = ReadLimitConn(conn, l.RateLimit())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handshake shouldn't take more than 10 seconds
|
||||||
|
conn.SetReadDeadline(time.Now().Add(10 * time.Second))
|
||||||
|
|
||||||
// Upgrade TCP connection to SSH connection
|
// Upgrade TCP connection to SSH connection
|
||||||
sshConn, channels, requests, err := ssh.NewServerConn(conn, l.config)
|
sshConn, channels, requests, err := ssh.NewServerConn(conn, l.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clear the deadline
|
||||||
|
conn.SetDeadline(time.Time{})
|
||||||
|
|
||||||
// FIXME: Disconnect if too many faulty requests? (Avoid DoS.)
|
// FIXME: Disconnect if too many faulty requests? (Avoid DoS.)
|
||||||
go ssh.DiscardRequests(requests)
|
go ssh.DiscardRequests(requests)
|
||||||
return NewSession(sshConn, channels)
|
return NewSession(sshConn, channels)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user