From 30a42e7bd80f3b0d30655d6f0532af7d4bb3424b Mon Sep 17 00:00:00 2001 From: Atsushi Watanabe Date: Fri, 21 Feb 2020 15:13:11 +0900 Subject: [PATCH] Respond to close_notify with close_notify RFC5246 Section 7.2.1 specifies that one received a close_notify alert MUST respond with a close_notify alert and close down the connection immediately. --- conn.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/conn.go b/conn.go index 2ef98fb46..70bca8e82 100644 --- a/conn.go +++ b/conn.go @@ -667,6 +667,8 @@ func (c *Conn) handleIncomingPacket(buf []byte) (*alert, error) { case *alert: c.log.Tracef("<- %s", content.String()) if content.alertDescription == alertCloseNotify { + // Respond with a close_notify [RFC5246 Section 7.2.1] + _ = c.notify(alertLevelWarning, alertCloseNotify) return nil, c.Close() } return nil, fmt.Errorf("alert: %v", content) @@ -778,7 +780,7 @@ func (c *Conn) startHandshakeOutbound() { func (c *Conn) close() error { if c.connectionClosed.Err() == nil && c.handshakeErr.load() == nil { - c.notify(alertLevelWarning, alertCloseNotify) //nolint + _ = c.notify(alertLevelWarning, alertCloseNotify) } c.workerTicker.Stop()