Skip to content

Commit

Permalink
Make sure clean the stored session
Browse files Browse the repository at this point in the history
We need to delete the stored session when any fatal errors occurs.
This operation should be taken in the Conn.notify function.
  • Loading branch information
taoso committed Dec 23, 2021
1 parent 961026b commit d44813b
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,6 @@ func (c *Conn) handleIncomingPacket(buf []byte, enqueue bool) (bool, *alert.Aler
var err error
buf, err = c.state.cipherSuite.Decrypt(buf)
if err != nil {
if len(c.state.SessionID) > 0 {
// According to the RFC, we need to delete the stored session.
// https://datatracker.ietf.org/doc/html/rfc5246#section-7.2
if delErr := c.fsm.cfg.sessionStore.Del(c.state.SessionID); delErr != nil {
return false, &alert.Alert{Level: alert.Fatal, Description: alert.InternalError}, delErr
}
return false, &alert.Alert{Level: alert.Fatal, Description: alert.DecryptError}, err
}
c.log.Debugf("%s: decrypt failed: %s", srvCliStr(c.state.isClient), err)
return false, nil, nil
}
Expand Down Expand Up @@ -764,6 +756,13 @@ func (c *Conn) recvHandshake() <-chan chan struct{} {
}

func (c *Conn) notify(ctx context.Context, level alert.Level, desc alert.Description) error {
if level == alert.Fatal && len(c.state.SessionID) > 0 {
// According to the RFC, we need to delete the stored session.
// https://datatracker.ietf.org/doc/html/rfc5246#section-7.2
if err := c.fsm.cfg.sessionStore.Del(c.state.SessionID); err != nil {
return err
}
}
return c.writePackets(ctx, []*packet{
{
record: &recordlayer.RecordLayer{
Expand Down

0 comments on commit d44813b

Please sign in to comment.