3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +01:00

socket: Timeout TLS handshakes

This commit is contained in:
Daniel Oaks 2016-10-22 20:53:36 +10:00
parent 6cd71e1b9e
commit 149550b453

View File

@ -13,11 +13,13 @@ import (
"io"
"net"
"strings"
"time"
)
var (
errNotTLS = errors.New("Not a TLS connection")
errNoPeerCerts = errors.New("Client did not provide a certificate")
errNotTLS = errors.New("Not a TLS connection")
errNoPeerCerts = errors.New("Client did not provide a certificate")
handshakeTimeout, _ = time.ParseDuration("5s")
)
// Socket represents an IRC socket.
@ -51,8 +53,14 @@ func (socket *Socket) CertFP() (string, error) {
return "", errNotTLS
}
// ensure handehake is performed
tlsConn.Handshake()
// ensure handehake is performed, and timeout after a few seconds
tlsConn.SetDeadline(time.Now().Add(handshakeTimeout))
err := tlsConn.Handshake()
tlsConn.SetDeadline(time.Time{})
if err != nil {
return "", err
}
peerCerts := tlsConn.ConnectionState().PeerCertificates
if len(peerCerts) < 1 {