mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
socket: Timeout TLS handshakes
This commit is contained in:
parent
6cd71e1b9e
commit
149550b453
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user