3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-23 03:02:48 +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" "io"
"net" "net"
"strings" "strings"
"time"
) )
var ( var (
errNotTLS = errors.New("Not a TLS connection") errNotTLS = errors.New("Not a TLS connection")
errNoPeerCerts = errors.New("Client did not provide a certificate") errNoPeerCerts = errors.New("Client did not provide a certificate")
handshakeTimeout, _ = time.ParseDuration("5s")
) )
// Socket represents an IRC socket. // Socket represents an IRC socket.
@ -51,8 +53,14 @@ func (socket *Socket) CertFP() (string, error) {
return "", errNotTLS return "", errNotTLS
} }
// ensure handehake is performed // ensure handehake is performed, and timeout after a few seconds
tlsConn.Handshake() tlsConn.SetDeadline(time.Now().Add(handshakeTimeout))
err := tlsConn.Handshake()
tlsConn.SetDeadline(time.Time{})
if err != nil {
return "", err
}
peerCerts := tlsConn.ConnectionState().PeerCertificates peerCerts := tlsConn.ConnectionState().PeerCertificates
if len(peerCerts) < 1 { if len(peerCerts) < 1 {