Skip to content

Commit

Permalink
Respond to close_notify with close_notify
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
at-wat committed Feb 22, 2020
1 parent d68b05b commit 30a42e7
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 30a42e7

Please sign in to comment.