Browse Source

webtransport: reject listening on a multiaddr with a certhash (#2426)

release-v0290
Marco Munizaga 1 year ago
committed by GitHub
parent
commit
0c8a73c0f1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      p2p/transport/webtransport/transport.go
  2. 9
      p2p/transport/webtransport/transport_test.go

5
p2p/transport/webtransport/transport.go

@ -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)

9
p2p/transport/webtransport/transport_test.go

@ -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)

Loading…
Cancel
Save