Skip to content

Commit

Permalink
noise: don't fail handshake when early data is received without handl…
Browse files Browse the repository at this point in the history
…er (#1746)
  • Loading branch information
marten-seemann authored Sep 13, 2022
1 parent f654b4b commit ddfb6f9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 0 additions & 2 deletions p2p/security/noise/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ func (s *secureSession) runHandshake(ctx context.Context) (err error) {
if err := s.earlyDataHandler.Received(ctx, s.insecureConn, initialPayload); err != nil {
return err
}
} else if len(initialPayload) > 0 {
return fmt.Errorf("received unexpected early data (%d bytes)", len(initialPayload))
}

// stage 1 //
Expand Down
10 changes: 5 additions & 5 deletions p2p/security/noise/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ func TestEarlyDataRejected(t *testing.T) {
}
}

func TestEarlyDataRejectedWithNoHandler(t *testing.T) {
func TestEarlyDataAcceptedWithNoHandler(t *testing.T) {
clientEDH := &earlyDataHandler{
send: func(ctx context.Context, conn net.Conn, id peer.ID) []byte { return []byte("foobar") },
}
Expand All @@ -526,14 +526,14 @@ func TestEarlyDataRejectedWithNoHandler(t *testing.T) {
errChan <- err
}()

_, err = initTransport.SecureOutbound(context.Background(), respConn, respTransport.localID)
require.Error(t, err)
conn, err := initTransport.SecureOutbound(context.Background(), respConn, respTransport.localID)
require.NoError(t, err)
defer conn.Close()

select {
case <-time.After(500 * time.Millisecond):
t.Fatal("timeout")
case err := <-errChan:
require.Error(t, err)
require.Contains(t, err.Error(), "received unexpected early data")
require.NoError(t, err)
}
}

0 comments on commit ddfb6f9

Please sign in to comment.