Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebTransport: Return an error when we listen on a multiaddr with a certhash #2426

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion p2p/transport/webtransport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,13 @@ func (t *transport) CanDial(addr ma.Multiaddr) bool {
}

func (t *transport) Listen(laddr ma.Multiaddr) (tpt.Listener, error) {
isWebTransport, _ := IsWebtransportMultiaddr(laddr)
isWebTransport, certhashCount := IsWebtransportMultiaddr(laddr)
if !isWebTransport {
return nil, fmt.Errorf("cannot listen on non-WebTransport addr: %s", laddr)
}
if certhashCount > 0 {
return nil, fmt.Errorf("cannot listen on a specific certhash non-WebTransport addr: %s", laddr)
}
if t.staticTLSConf == nil {
t.listenOnce.Do(func() {
t.certManager, t.listenOnceErr = newCertManager(t.privKey, t.clock)
Expand Down
9 changes: 4 additions & 5 deletions p2p/transport/webtransport/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,13 @@ func TestCanDial(t *testing.T) {
func TestListenAddrValidity(t *testing.T) {
valid := []ma.Multiaddr{
ma.StringCast("/ip6/::/udp/0/quic-v1/webtransport/"),
ma.StringCast("/ip4/127.0.0.1/udp/11234/quic-v1/webtransport/"),
}

invalid := []ma.Multiaddr{
ma.StringCast("/ip4/127.0.0.1/udp/11234"), // missing webtransport
ma.StringCast("/ip4/127.0.0.1/udp/11234/webtransport"), // missing quic
ma.StringCast("/ip4/127.0.0.1/tcp/11234/webtransport"), // WebTransport over TCP? Is this a joke?
ma.StringCast("/ip4/127.0.0.1/udp/11234/quic-v1/webtransport/certhash/" + randomMultihash(t)), // We can't listen on a specific certhash
ma.StringCast("/ip4/127.0.0.1/udp/0"), // missing webtransport
ma.StringCast("/ip4/127.0.0.1/udp/0/webtransport"), // missing quic
ma.StringCast("/ip4/127.0.0.1/tcp/0/webtransport"), // WebTransport over TCP? Is this a joke?
ma.StringCast("/ip4/127.0.0.1/udp/0/quic-v1/webtransport/certhash/" + randomMultihash(t)), // We can't listen on a specific certhash
}

_, key := newIdentity(t)
Expand Down