Skip to content

Commit

Permalink
websocket: fix nil pointer in tlsClientConf (#1770)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo authored Sep 21, 2022
1 parent 3981799 commit fa70f6e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
5 changes: 3 additions & 2 deletions p2p/transport/websocket/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ func New(u transport.Upgrader, rcmgr network.ResourceManager, opts ...Option) (*
rcmgr = network.NullResourceManager
}
t := &WebsocketTransport{
upgrader: u,
rcmgr: rcmgr,
upgrader: u,
rcmgr: rcmgr,
tlsClientConf: &tls.Config{},
}
for _, opt := range opts {
if err := opt(t); err != nil {
Expand Down
21 changes: 18 additions & 3 deletions p2p/transport/websocket/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ func testWSSServer(t *testing.T, listenAddr ma.Multiaddr) (ma.Multiaddr, peer.ID
t.Fatal(err)
}

// l, err := tpt.Listen(ma.StringCast("/ip4/127.0.0.1/tcp/0/wss"))
// l, err := tpt.Listen(ma.StringCast("/ip4/127.0.0.1/tcp/0/tls/ws"))
l, err := tpt.Listen(listenAddr)
fmt.Println("here", listenAddr)
require.NoError(t, err)
t.Cleanup(func() {
l.Close()
Expand Down Expand Up @@ -245,6 +242,24 @@ func TestDialWss(t *testing.T) {
require.NoError(t, err)
}

func TestDialWssNoClientCert(t *testing.T) {
serverMA, rid, _ := testWSSServer(t, ma.StringCast("/ip4/127.0.0.1/tcp/0/tls/sni/example.com/ws"))
require.Contains(t, serverMA.String(), "tls")

_, u := newSecureUpgrader(t)
tpt, err := New(u, network.NullResourceManager)
require.NoError(t, err)

masToDial, err := tpt.Resolve(context.Background(), serverMA)
require.NoError(t, err)

_, err = tpt.Dial(context.Background(), masToDial[0], rid)
require.Error(t, err)

// The server doesn't have a signed certificate
require.Contains(t, err.Error(), "x509")
}

func TestWebsocketTransport(t *testing.T) {
t.Skip("This test is failing, see https://github.com/libp2p/go-ws-transport/issues/99")
_, ua := newUpgrader(t)
Expand Down

0 comments on commit fa70f6e

Please sign in to comment.