Browse Source

socket: Timeout TLS handshakes

tags/v0.3.0
Daniel Oaks 7 years ago
parent
commit
149550b453
1 changed files with 12 additions and 4 deletions
  1. 12
    4
      irc/socket.go

+ 12
- 4
irc/socket.go View File

@@ -13,11 +13,13 @@ import (
13 13
 	"io"
14 14
 	"net"
15 15
 	"strings"
16
+	"time"
16 17
 )
17 18
 
18 19
 var (
19
-	errNotTLS      = errors.New("Not a TLS connection")
20
-	errNoPeerCerts = errors.New("Client did not provide a certificate")
20
+	errNotTLS           = errors.New("Not a TLS connection")
21
+	errNoPeerCerts      = errors.New("Client did not provide a certificate")
22
+	handshakeTimeout, _ = time.ParseDuration("5s")
21 23
 )
22 24
 
23 25
 // Socket represents an IRC socket.
@@ -51,8 +53,14 @@ func (socket *Socket) CertFP() (string, error) {
51 53
 		return "", errNotTLS
52 54
 	}
53 55
 
54
-	// ensure handehake is performed
55
-	tlsConn.Handshake()
56
+	// ensure handehake is performed, and timeout after a few seconds
57
+	tlsConn.SetDeadline(time.Now().Add(handshakeTimeout))
58
+	err := tlsConn.Handshake()
59
+	tlsConn.SetDeadline(time.Time{})
60
+
61
+	if err != nil {
62
+		return "", err
63
+	}
56 64
 
57 65
 	peerCerts := tlsConn.ConnectionState().PeerCertificates
58 66
 	if len(peerCerts) < 1 {

Loading…
Cancel
Save