Skip to content

Commit

Permalink
fix CanDial for addresses that don't contain any certificate hashes (#25
Browse files Browse the repository at this point in the history
)
  • Loading branch information
marten-seemann authored Sep 7, 2022
1 parent 7714b04 commit 98ff0c6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 2 additions & 3 deletions p2p/transport/webtransport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,8 @@ func (t *transport) CanDial(addr ma.Multiaddr) bool {
}
return true
})
if numHashes == 0 {
return false
}
// Remove the /certhash components from the multiaddr.
// If the multiaddr doesn't contain any certhashes, the node might have a CA-signed certificate.
for i := 0; i < numHashes; i++ {
addr, _ = ma.SplitLast(addr)
}
Expand Down
9 changes: 5 additions & 4 deletions p2p/transport/webtransport/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ func TestCanDial(t *testing.T) {
ma.StringCast("/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash/" + randomMultihash(t)),
ma.StringCast("/ip6/b16b:8255:efc6:9cd5:1a54:ee86:2d7a:c2e6/udp/1234/quic/webtransport/certhash/" + randomMultihash(t)),
ma.StringCast(fmt.Sprintf("/ip4/127.0.0.1/udp/1234/quic/webtransport/certhash/%s/certhash/%s/certhash/%s", randomMultihash(t), randomMultihash(t), randomMultihash(t))),
ma.StringCast("/ip4/127.0.0.1/udp/1234/quic/webtransport"), // no certificate hash
}

invalid := []ma.Multiaddr{
ma.StringCast("/ip4/127.0.0.1/udp/1234"), // missing webtransport
ma.StringCast("/ip4/127.0.0.1/udp/1234/webtransport"), // missing quic
ma.StringCast("/ip4/127.0.0.1/tcp/1234/webtransport"), // WebTransport over TCP? Is this a joke?
ma.StringCast("/ip4/127.0.0.1/udp/1234/quic/webtransport"), // missing certificate hash
ma.StringCast("/ip4/127.0.0.1/udp/1234"), // missing webtransport
ma.StringCast("/ip4/127.0.0.1/udp/1234/webtransport"), // missing quic
ma.StringCast("/ip4/127.0.0.1/tcp/1234/webtransport"), // WebTransport over TCP? Is this a joke?
}

_, key := newIdentity(t)
Expand Down Expand Up @@ -506,6 +506,7 @@ func TestStaticTLSConf(t *testing.T) {
require.NoError(t, err)
defer cl.(io.Closer).Close()

require.True(t, cl.CanDial(ln.Multiaddr()))
conn, err := cl.Dial(context.Background(), ln.Multiaddr(), serverID)
require.NoError(t, err)
defer conn.Close()
Expand Down

0 comments on commit 98ff0c6

Please sign in to comment.